Namespace Lucene.Net.QueryParsers.Flexible.Standard
Implementation of the Lucene classic query parser using the flexible query parser frameworks
Lucene Flexible Query Parser Implementation
The old Lucene query parser used to have only one class that performed all the parsing operations. In the new query parser structure, the parsing was divided in 3 steps: parsing (syntax), processing (semantic) and building.
The classes contained in the namespace Lucene.Net.QueryParsers.Flexible.Standard are used to reproduce the same behavior as the old query parser.
Check StandardQueryParser to quick start using the Lucene query parser.
Classes
QueryParserUtil
This class defines utility methods to (help) parse query strings into Lucene.Net.Search.Query objects.
StandardQueryParser
This class is a helper that enables users to easily use the Lucene query parser.
To construct a Query object from a query string, use the Parse(string, string) method:StandardQueryParser queryParserHelper = new StandardQueryParser();
Query query = queryParserHelper.Parse("a AND b", "defaultField");
To change any configuration before parsing the query string do, for example:
queryParserHelper.Analyzer = new WhitespaceAnalyzer();
queryParserHelper.AllowLeadingWildcard = true;
// Or alternativley use the query config handler returned by StandardQueryParser which is a
// StandardQueryConfigHandler:
queryParserHelper.QueryConfigHandler.Set(ConfigurationKeys.ALLOW_LEADING_WILDCARD, true);
The syntax for query strings is as follows (copied from the old QueryParser
javadoc):
A Query is a series of clauses. A clause may be prefixed by:
-
a plus (
+
) or a minus (-
) sign, indicating that the clause is required or prohibited respectively; or - a term followed by a colon, indicating the field to be searched. This enables one to construct queries which search multiple fields.
A clause may be either:
- a term, indicating all the documents that contain this term; or
-
a nested query, enclosed in parentheses. Note that this may be used with
a
+
/-
prefix to require any of a set of terms.
Thus, in BNF, the query grammar is:
Query ::= ( Clause )*
Clause ::= ["+", "-"] [<TERM> ":"] ( <TERM> | "(" Query ")" )
Examples of appropriately formatted queries can be found in the query syntax documentation.
The text parser used by this helper is a StandardSyntaxParser.
The query node processor used by this helper is a StandardQueryNodeProcessorPipeline.
The builder used by this helper is a StandardQueryTreeBuilder.
Interfaces
ICommonQueryParserConfiguration
Configuration options common across queryparser implementations.