Class QueryParser
This class is generated by JavaCC. The most important method is Parse(String).
The syntax for query strings is as follows: 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.
In TermRangeQuerys, QueryParser tries to detect date values, e.g. date:[6/1/2005 TO 6/4/2005] produces a range query that searches for "date" fields between 2005-06-01 and 2005-06-04. Note that the format of the accepted input depends on the System.Globalization.CultureInfo. A Lucene.Net.Documents.DateTools.Resolution has to be set, if you want to use DateTools for date conversion.
The date resolution that shall be used for RangeQueries can be set using SetDateResolution(DateTools.Resolution) or SetDateResolution(String, DateTools.Resolution). The former sets the default date resolution for all fields, whereas the latter can be used to set field specific date resolutions. Field specific date resolutions take, if set, precedence over the default date resolution.
If you don't use DateTools in your index, you can create your own query parser that inherits QueryParser and overwrites GetRangeQuery(String, String, String, Boolean, Boolean) to use a different method for date conversion.
Note that QueryParser is not thread-safe.
NOTE: there is a new QueryParser in contrib, which matches the same syntax as this class, but is more modular, enabling substantial customization to how a query is created.
NOTE: You must specify the required Lucene.Net.Util.LuceneVersion compatibility when creating QueryParser:
- As of 3.1, AutoGeneratePhraseQueries is false by default.
Inheritance
Implements
Inherited Members
Namespace: Lucene.Net.QueryParsers.Classic
Assembly: Lucene.Net.QueryParser.dll
Syntax
public class QueryParser : QueryParserBase, ICommonQueryParserConfiguration
Constructors
| Improve this Doc View SourceQueryParser(ICharStream)
Constructor with user supplied ICharStream.
Declaration
protected QueryParser(ICharStream stream)
Parameters
Type | Name | Description |
---|---|---|
ICharStream | stream |
QueryParser(QueryParserTokenManager)
Constructor with generated Token Manager.
Declaration
protected QueryParser(QueryParserTokenManager tm)
Parameters
Type | Name | Description |
---|---|---|
QueryParserTokenManager | tm |
QueryParser(LuceneVersion, String, Analyzer)
Constructs a query parser.
Declaration
public QueryParser(LuceneVersion matchVersion, string f, Analyzer a)
Parameters
Type | Name | Description |
---|---|---|
Lucene.Net.Util.LuceneVersion | matchVersion | Lucene version to match. |
System.String | f | the default field for query terms. |
Lucene.Net.Analysis.Analyzer | a | used to find terms in the query text. |
Properties
| Improve this Doc View SourceJj_nt
Next token.
Declaration
public Token Jj_nt { get; set; }
Property Value
Type | Description |
---|---|
Token |
Token
Current token.
Declaration
public Token Token { get; set; }
Property Value
Type | Description |
---|---|
Token |
TokenSource
Generated Token Manager.
Declaration
public QueryParserTokenManager TokenSource { get; set; }
Property Value
Type | Description |
---|---|
QueryParserTokenManager |
Methods
| Improve this Doc View SourceClause(String)
Declaration
public Query Clause(string field)
Parameters
Type | Name | Description |
---|---|---|
System.String | field |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query |
Conjunction()
Declaration
public int Conjunction()
Returns
Type | Description |
---|---|
System.Int32 |
Disable_tracing()
Disable tracing.
Declaration
public void Disable_tracing()
Enable_tracing()
Enable tracing.
Declaration
public void Enable_tracing()
GenerateParseException()
Generate ParseException.
Declaration
public virtual ParseException GenerateParseException()
Returns
Type | Description |
---|---|
ParseException |
GetNextToken()
Get the next Token.
Declaration
public Token GetNextToken()
Returns
Type | Description |
---|---|
Token |
GetToken(Int32)
Get the specific Token.
Declaration
public Token GetToken(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index |
Returns
Type | Description |
---|---|
Token |
Modifiers()
Declaration
public int Modifiers()
Returns
Type | Description |
---|---|
System.Int32 |
Query(String)
Declaration
public Query Query(string field)
Parameters
Type | Name | Description |
---|---|---|
System.String | field |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query |
ReInit(ICharStream)
Reinitialize.
Declaration
public override void ReInit(ICharStream stream)
Parameters
Type | Name | Description |
---|---|---|
ICharStream | stream |
Overrides
| Improve this Doc View SourceReInit(QueryParserTokenManager)
Reinitialize.
Declaration
public virtual void ReInit(QueryParserTokenManager tm)
Parameters
Type | Name | Description |
---|---|---|
QueryParserTokenManager | tm |
Term(String)
Declaration
public Query Term(string field)
Parameters
Type | Name | Description |
---|---|---|
System.String | field |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query |
TopLevelQuery(String)
Declaration
public override sealed Query TopLevelQuery(string field)
Parameters
Type | Name | Description |
---|---|---|
System.String | field |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query |