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); }
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; }