public static Query Parse(string inputQuery, bool rawLuceneQuery) { if (string.IsNullOrWhiteSpace(inputQuery)) { return(new MatchAllDocsQuery()); } if (rawLuceneQuery) { return(CreateRawQuery(inputQuery)); } // Transform the query for Lucene parsing inputQuery = TransformQuery(inputQuery); // Parse the query our query parser PackageQueryParser parser = new PackageQueryParser(Lucene.Net.Util.Version.LUCENE_30, DefaultTermName, new PackageAnalyzer()); Query query = parser.Parse(inputQuery); // Process the query into clauses List <BooleanClause> clausesCollector = new List <BooleanClause>(); string nugetQuery = ExtractLuceneClauses(query, inputQuery, clausesCollector); // Rewrite Id clauses into "TokenizedId, ShingledId, Id" booleans IEnumerable <BooleanClause> luceneClauses = clausesCollector.Select(RewriteClauses(parser)); // Now, take the nuget query, if there is one, and process it Query nugetParsedQuery = ParseNuGetQuery(nugetQuery); // Build the lucene clauses query BooleanQuery luceneQuery = BuildBooleanQuery(luceneClauses); // Build the final query return(Combine(nugetParsedQuery, luceneQuery)); }
private static Query ParseNuGetQuery(string nugetQuery) { Query nugetParsedQuery = null; if (!String.IsNullOrEmpty(nugetQuery)) { // Process the query StringBuilder luceneQuery = new StringBuilder(); CreateFieldClause(luceneQuery, "Id", nugetQuery); CreateFieldClause(luceneQuery, "Version", nugetQuery); CreateFieldClause(luceneQuery, "TokenizedId", nugetQuery); CreateFieldClauseAND(luceneQuery, "TokenizedId", nugetQuery, 4); CreateFieldClause(luceneQuery, "ShingledId", nugetQuery); CreateFieldClause(luceneQuery, "Title", nugetQuery, 2); CreateFieldClauseAND(luceneQuery, "Title", nugetQuery, 4); CreateFieldClause(luceneQuery, "Tags", nugetQuery); CreateFieldClause(luceneQuery, "Description", nugetQuery); CreateFieldClause(luceneQuery, "Summary", nugetQuery); CreateFieldClause(luceneQuery, "Authors", nugetQuery); CreateFieldClause(luceneQuery, "Owners", nugetQuery); PackageQueryParser parser = new PackageQueryParser(Lucene.Net.Util.Version.LUCENE_30, "Title", new PackageAnalyzer()); nugetParsedQuery = parser.Parse(luceneQuery.ToString()); } return(nugetParsedQuery); }
public static Query Parse(string inputQuery, bool rawLuceneQuery) { if (string.IsNullOrWhiteSpace(inputQuery)) { return new MatchAllDocsQuery(); } if (rawLuceneQuery) { return CreateRawQuery(inputQuery); } // Transform the query for Lucene parsing inputQuery = TransformQuery(inputQuery); // Parse the query our query parser PackageQueryParser parser = new PackageQueryParser(Lucene.Net.Util.Version.LUCENE_30, DefaultTermName, new PackageAnalyzer()); Query query = parser.Parse(inputQuery); // Process the query into clauses List<BooleanClause> clausesCollector = new List<BooleanClause>(); string nugetQuery = ExtractLuceneClauses(query, inputQuery, clausesCollector); // Rewrite Id clauses into "TokenizedId, ShingledId, Id" booleans IEnumerable<BooleanClause> luceneClauses = clausesCollector.Select(RewriteClauses(parser)); // Now, take the nuget query, if there is one, and process it Query nugetParsedQuery = ParseNuGetQuery(nugetQuery); // Build the lucene clauses query BooleanQuery luceneQuery = BuildBooleanQuery(luceneClauses); // Build the final query return Combine(nugetParsedQuery, luceneQuery); }
private static void ApplyDeletes(List <int> packageKeys, Func <int, IndexDocumentData> fetch, Lucene.Net.Store.Directory directory, TextWriter log, PerfEventTracker perfTracker, IEnumerable <FrameworkName> projectFxs) { log.WriteLine("ApplyDeletes"); try { PackageQueryParser queryParser = new PackageQueryParser(Lucene.Net.Util.Version.LUCENE_30, "Id", new PackageAnalyzer()); // Collect all the packages var packages = packageKeys.Select(k => fetch(k)); using (IndexWriter indexWriter = CreateIndexWriter(directory, false)) { var dirtyDocuments = new List <FacetedDocument>(); IDictionary <string, string> commitUserData; using (var reader = indexWriter.GetReader()) { commitUserData = reader.CommitUserData; // Group by Id foreach (var group in packages.GroupBy(p => p.Package.PackageRegistration.Id)) { // Collect existing documents IEnumerable <FacetedDocument> existing = CollectExistingDocuments(perfTracker, indexWriter.GetReader(), group.Key); // Remove the documents we need to remove foreach (var package in group) { Query query = NumericRangeQuery.NewIntRange("Key", package.Package.Key, package.Package.Key, true, true); indexWriter.DeleteDocuments(query); existing = existing.Where(d => !SemanticVersion.Parse(package.Package.NormalizedVersion).Equals(d.Version)); } // Recalculate facets UpdateFacets(group.Key, existing.ToList(), projectFxs, perfTracker); // Add dirty documents dirtyDocuments.AddRange(existing.Where(d => d.Dirty)); } } // Process dirty documents WriteDirtyDocuments(dirtyDocuments, indexWriter, perfTracker); commitUserData["count"] = packageKeys.Count.ToString(); commitUserData["commit-description"] = "delete"; log.WriteLine("Commit {0} deletes", packageKeys.Count); indexWriter.Commit(commitUserData); } } catch (Exception) { } }
public static Query CreateRawQuery(string q) { if (String.IsNullOrEmpty(q)) { return(null); } QueryParser parser = new PackageQueryParser(Lucene.Net.Util.Version.LUCENE_30, "Title", new PackageAnalyzer()); Query query = parser.Parse(q); return(query); }
private static Query ParseNuGetQuery(string nugetQuery) { Query nugetParsedQuery = null; if (!String.IsNullOrEmpty(nugetQuery)) { // Process the query StringBuilder luceneQuery = new StringBuilder(); CreateFieldClause(luceneQuery, "Id", nugetQuery); CreateFieldClause(luceneQuery, "Version", nugetQuery); CreateFieldClause(luceneQuery, "TokenizedId", nugetQuery); CreateFieldClauseAND(luceneQuery, "TokenizedId", nugetQuery, 4); CreateFieldClause(luceneQuery, "ShingledId", nugetQuery); CreateFieldClause(luceneQuery, "Title", nugetQuery, 2); CreateFieldClauseAND(luceneQuery, "Title", nugetQuery, 4); CreateFieldClause(luceneQuery, "Tags", nugetQuery); CreateFieldClause(luceneQuery, "Description", nugetQuery); CreateFieldClause(luceneQuery, "Summary", nugetQuery); CreateFieldClause(luceneQuery, "Authors", nugetQuery); CreateFieldClause(luceneQuery, "Owners", nugetQuery); PackageQueryParser parser = new PackageQueryParser(Lucene.Net.Util.Version.LUCENE_30, "Title", new PackageAnalyzer()); nugetParsedQuery = parser.Parse(luceneQuery.ToString()); } return nugetParsedQuery; }
public static Query CreateRawQuery(string q) { if (String.IsNullOrEmpty(q)) { return null; } QueryParser parser = new PackageQueryParser(Lucene.Net.Util.Version.LUCENE_30, "Title", new PackageAnalyzer()); Query query = parser.Parse(q); return query; }