C# Class Lucene.Net.QueryParsers.Classic.QueryParser

This class is generated by JavaCC. The most important method is QueryParserBase.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 Locale. A Documents.DateTools.Resolution has to be set, if you want to use Documents.DateTools for date conversion.

The date resolution that shall be used for RangeQueries can be set using QueryParserBase.SetDateResolution(Documents.DateTools.Resolution) or QueryParserBase.SetDateResolution(string, Documents.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 Documents.DateTools in your index, you can create your own query parser that inherits QueryParser and overwrites QueryParserBase.GetRangeQuery(string, string, string, bool, bool) 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 LuceneVersion compatibility when creating QueryParser: As of 3.1, QueryParserBase.AutoGeneratePhraseQueries is false by default.
Inheritance: Lucene.Net.QueryParsers.Classic.QueryParserBase
Show file Open project: apache/lucenenet Class Usage Examples

Public Properties

Property Type Description
jj_nt Token
token Token
token_source QueryParserTokenManager

Public Methods

Method Description
Clause ( string field ) : Query
Conjunction ( ) : int
Disable_tracing ( ) : void

Disable tracing.

Enable_tracing ( ) : void

Enable tracing.

GenerateParseException ( ) : ParseException

Generate ParseException.

GetNextToken ( ) : Token

Get the next Token.

GetToken ( int index ) : Token

Get the specific Token.

Modifiers ( ) : int
Query ( string field ) : Query
QueryParser ( LuceneVersion matchVersion, string f, Analyzer a ) : Lucene.Net.Analysis

Constructs a query parser.

ReInit ( ICharStream stream ) : void

Reinitialize.

ReInit ( QueryParserTokenManager tm ) : void

Reinitialize.

Term ( string field ) : Query
TopLevelQuery ( string field ) : Query

Protected Methods

Method Description
QueryParser ( ICharStream stream ) : Lucene.Net.Analysis

Constructor with user supplied ICharStream.

QueryParser ( QueryParserTokenManager tm ) : Lucene.Net.Analysis

Constructor with generated Token Manager.

Private Methods

Method Description
Jj_2_1 ( int xla ) : bool
Jj_3R_2 ( ) : bool
Jj_3R_3 ( ) : bool
Jj_3_1 ( ) : bool
Jj_add_error_token ( int kind, int pos ) : void
Jj_consume_token ( int kind ) : Token
Jj_la1_init_0 ( ) : void
Jj_la1_init_1 ( ) : void
Jj_ntk ( ) : int
Jj_rescan_token ( ) : void
Jj_save ( int index, int xla ) : void
Jj_scan_token ( int kind ) : bool
QueryParser ( ) : Lucene.Net.Analysis

Method Details

Clause() public method

public Clause ( string field ) : Query
field string
return Lucene.Net.Search.Query

Conjunction() public method

public Conjunction ( ) : int
return int

Disable_tracing() public method

Disable tracing.
public Disable_tracing ( ) : void
return void

Enable_tracing() public method

Enable tracing.
public Enable_tracing ( ) : void
return void

GenerateParseException() public method

Generate ParseException.
public GenerateParseException ( ) : ParseException
return ParseException

GetNextToken() public method

Get the next Token.
public GetNextToken ( ) : Token
return Token

GetToken() public method

Get the specific Token.
public GetToken ( int index ) : Token
index int
return Token

Modifiers() public method

public Modifiers ( ) : int
return int

Query() public method

public Query ( string field ) : Query
field string
return Lucene.Net.Search.Query

QueryParser() protected method

Constructor with user supplied ICharStream.
protected QueryParser ( ICharStream stream ) : Lucene.Net.Analysis
stream ICharStream
return Lucene.Net.Analysis

QueryParser() public method

Constructs a query parser.
public QueryParser ( LuceneVersion matchVersion, string f, Analyzer a ) : Lucene.Net.Analysis
matchVersion LuceneVersion Lucene version to match.
f string the default field for query terms.
a Lucene.Net.Analysis.Analyzer used to find terms in the query text.
return Lucene.Net.Analysis

QueryParser() protected method

Constructor with generated Token Manager.
protected QueryParser ( QueryParserTokenManager tm ) : Lucene.Net.Analysis
tm QueryParserTokenManager
return Lucene.Net.Analysis

ReInit() public method

Reinitialize.
public ReInit ( ICharStream stream ) : void
stream ICharStream
return void

ReInit() public method

Reinitialize.
public ReInit ( QueryParserTokenManager tm ) : void
tm QueryParserTokenManager
return void

Term() public method

public Term ( string field ) : Query
field string
return Lucene.Net.Search.Query

TopLevelQuery() public final method

public final TopLevelQuery ( string field ) : Query
field string
return Lucene.Net.Search.Query

Property Details

jj_nt public property

Next token.
public Token jj_nt
return Token

token public property

Current token.
public Token token
return Token

token_source public property

Generated Token Manager.
public QueryParserTokenManager,Lucene.Net.QueryParsers.Classic token_source
return QueryParserTokenManager