C# Class Lucene.Net.QueryParsers.QueryParser

This class is generated by JavaCC. The most important method is {@link #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 {@link RangeQuery}s, 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 {@link #SetLocale(Locale) the locale}. By default a date is converted into a search term using the deprecated {@link DateField} for compatibility reasons. To use the new {@link DateTools} to convert dates, a {@link Lucene.Net.Documents.DateTools.Resolution} has to be set.

The date resolution that shall be used for RangeQueries can be set using {@link #SetDateResolution(DateTools.Resolution)} or {@link #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 use neither {@link DateField} nor {@link DateTools} in your index, you can create your own query parser that inherits QueryParser and overwrites {@link #GetRangeQuery(String, String, String, boolean)} to use a different method for date conversion.

Note that QueryParser is not thread-safe.

Inheritance: Lucene.Net.QueryParsers.QueryParserConstants
Datei anzeigen Open project: synhershko/lucene.net Class Usage Examples

Public Properties

Property Type Description
AND_OPERATOR Operator
OR_OPERATOR Operator
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.

Escape ( String s ) : String

Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding \.

GenerateParseException ( ) : Lucene.Net.QueryParsers.ParseException

Generate ParseException.

GetNextToken ( ) : Token

Get the next Token.

Modifiers ( ) : int
Parse ( String query ) : Query

Parses a query string, returning a {@link Lucene.Net.Search.Query}.

Query ( String field ) : Query
QueryParser ( Lucene.Net.Util.Version matchVersion, String f, Analyzer a ) : System
ReInit ( ICharStream stream ) : void

Reinitialise.

ReInit ( Lucene.Net.QueryParsers.QueryParserTokenManager tm ) : void

Reinitialise.

SetDateResolution ( Lucene.Net.Documents.DateTools dateResolution ) : void

Sets the default date resolution used by RangeQueries for fields for which no specific date resolutions has been set. Field specific resolutions can be set with {@link #SetDateResolution(String, DateTools.Resolution)}.

SetDateResolution ( String fieldName, Lucene.Net.Documents.DateTools dateResolution ) : void

Sets the date resolution used by RangeQueries for a specific field.

Term ( String field ) : Query
TopLevelQuery ( String field ) : Query
getDateResolution ( String fieldName ) : Lucene.Net.Documents.DateTools.Resolution

Returns the date resolution that is used by RangeQueries for the given field. Returns null, if no default or field specific date resolution has been set for the given field.

getToken ( int index ) : Token

Get the specific Token.

Protected Methods

Method Description
AddClause ( List clauses, int conj, int mods, Query q ) : void
GetBooleanQuery ( IList clauses ) : Query

Factory method for generating query, given a set of clauses. By default creates a boolean query composed of clauses passed in. Can be overridden by extending classes, to modify query being returned.

GetBooleanQuery ( IList clauses, bool disableCoord ) : Query

Factory method for generating query, given a set of clauses. By default creates a boolean query composed of clauses passed in. Can be overridden by extending classes, to modify query being returned.

GetFieldQuery ( String field, String queryText ) : Query
GetFieldQuery ( String field, String queryText, int slop ) : Query

Base implementation delegates to {@link #GetFieldQuery(String,String)}. This method may be overridden, for example, to return a SpanNearQuery instead of a PhraseQuery.

GetFuzzyQuery ( String field, String termStr, float minSimilarity ) : Query

Factory method for generating a query (similar to {@link #getWildcardQuery}). Called when parser parses an input term token that has the fuzzy suffix (~) appended.

GetPrefixQuery ( String field, String termStr ) : Query

Factory method for generating a query (similar to {@link #getWildcardQuery}). Called when parser parses an input term token that uses prefix notation; that is, contains a single '*' wildcard character as its last character. Since this is a special case of generic wildcard term, and such a query can be optimized easily, this usually results in a different query object.

Depending on settings, a prefix term may be lower-cased automatically. It will not go through the default Analyzer, however, since normal Analyzers are unlikely to work properly with wildcard templates.

Can be overridden by extending classes, to provide custom handling for wild card queries, which may be necessary due to missing analyzer calls.

GetRangeQuery ( String field, String part1, String part2, bool inclusive ) : Query
GetWildcardQuery ( String field, String termStr ) : Query

Factory method for generating a query. Called when parser parses an input term token that contains one or more wildcard characters (? and *), but is not a prefix term token (one that has just a single * character at the end)

Depending on settings, prefix term may be lower-cased automatically. It will not go through the default Analyzer, however, since normal Analyzers are unlikely to work properly with wildcard templates.

Can be overridden by extending classes, to provide custom handling for wildcard queries, which may be necessary due to missing analyzer calls.

NewBooleanClause ( Query q, Occur occur ) : BooleanClause

Builds a new BooleanClause instance

NewBooleanQuery ( bool disableCoord ) : Lucene.Net.Search.BooleanQuery

Builds a new BooleanQuery instance

NewFuzzyQuery ( Lucene.Net.Index.Term term, float minimumSimilarity, int prefixLength ) : Query

Builds a new FuzzyQuery instance

NewMatchAllDocsQuery ( ) : Query

Builds a new MatchAllDocsQuery instance

NewMultiPhraseQuery ( ) : MultiPhraseQuery

Builds a new MultiPhraseQuery instance

NewPhraseQuery ( ) : PhraseQuery

Builds a new PhraseQuery instance

NewPrefixQuery ( Lucene.Net.Index.Term prefix ) : Query

Builds a new PrefixQuery instance

NewRangeQuery ( String field, String part1, String part2, bool inclusive ) : Query

Builds a new TermRangeQuery instance

NewTermQuery ( Lucene.Net.Index.Term term ) : Query

Builds a new TermQuery instance

NewWildcardQuery ( Lucene.Net.Index.Term t ) : Query

Builds a new WildcardQuery instance

QueryParser ( ICharStream stream ) : System

Constructor with user supplied CharStream.

QueryParser ( Lucene.Net.QueryParsers.QueryParserTokenManager tm ) : System

Constructor with generated Token Manager.

Private Methods

Method Description
DiscardEscapeChar ( String input ) : String

Returns a String where the escape char has been removed, or kept only once if there was a double escape. Supports escaped unicode characters, e. g. translates \\u0041 to A.

HexToInt ( char c ) : int

Returns the numeric value of the hexadecimal character

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
Main ( String args ) : void
QueryParser ( ) : System
jj_scan_token ( int kind ) : bool

Method Details

AddClause() protected method

protected AddClause ( List clauses, int conj, int mods, Query q ) : void
clauses List
conj int
mods int
q Lucene.Net.Search.Query
return void

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

Escape() public static method

Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding \.
public static Escape ( String s ) : String
s String
return String

GenerateParseException() public method

Generate ParseException.
public GenerateParseException ( ) : Lucene.Net.QueryParsers.ParseException
return Lucene.Net.QueryParsers.ParseException

GetBooleanQuery() protected method

Factory method for generating query, given a set of clauses. By default creates a boolean query composed of clauses passed in. Can be overridden by extending classes, to modify query being returned.
throw in overridden method to disallow ///
protected GetBooleanQuery ( IList clauses ) : Query
clauses IList List that contains {@link BooleanClause} instances /// to join. /// ///
return Lucene.Net.Search.Query

GetBooleanQuery() protected method

Factory method for generating query, given a set of clauses. By default creates a boolean query composed of clauses passed in. Can be overridden by extending classes, to modify query being returned.
throw in overridden method to disallow ///
protected GetBooleanQuery ( IList clauses, bool disableCoord ) : Query
clauses IList List that contains {@link BooleanClause} instances /// to join. ///
disableCoord bool true if coord scoring should be disabled. /// ///
return Lucene.Net.Search.Query

GetFieldQuery() protected method

throw in overridden method to disallow ///
protected GetFieldQuery ( String field, String queryText ) : Query
field String
queryText String
return Lucene.Net.Search.Query

GetFieldQuery() protected method

Base implementation delegates to {@link #GetFieldQuery(String,String)}. This method may be overridden, for example, to return a SpanNearQuery instead of a PhraseQuery.
throw in overridden method to disallow ///
protected GetFieldQuery ( String field, String queryText, int slop ) : Query
field String
queryText String
slop int
return Lucene.Net.Search.Query

GetFuzzyQuery() protected method

Factory method for generating a query (similar to {@link #getWildcardQuery}). Called when parser parses an input term token that has the fuzzy suffix (~) appended.
throw in overridden method to disallow ///
protected GetFuzzyQuery ( String field, String termStr, float minSimilarity ) : Query
field String Name of the field query will use. ///
termStr String Term token to use for building term for the query /// ///
minSimilarity float
return Lucene.Net.Search.Query

GetNextToken() public method

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

GetPrefixQuery() protected method

Factory method for generating a query (similar to {@link #getWildcardQuery}). Called when parser parses an input term token that uses prefix notation; that is, contains a single '*' wildcard character as its last character. Since this is a special case of generic wildcard term, and such a query can be optimized easily, this usually results in a different query object.

Depending on settings, a prefix term may be lower-cased automatically. It will not go through the default Analyzer, however, since normal Analyzers are unlikely to work properly with wildcard templates.

Can be overridden by extending classes, to provide custom handling for wild card queries, which may be necessary due to missing analyzer calls.

throw in overridden method to disallow ///
protected GetPrefixQuery ( String field, String termStr ) : Query
field String Name of the field query will use. ///
termStr String Term token to use for building term for the query /// (without trailing '*' character!) /// ///
return Lucene.Net.Search.Query

GetRangeQuery() protected method

throw in overridden method to disallow ///
protected GetRangeQuery ( String field, String part1, String part2, bool inclusive ) : Query
field String
part1 String
part2 String
inclusive bool
return Lucene.Net.Search.Query

GetWildcardQuery() protected method

Factory method for generating a query. Called when parser parses an input term token that contains one or more wildcard characters (? and *), but is not a prefix term token (one that has just a single * character at the end)

Depending on settings, prefix term may be lower-cased automatically. It will not go through the default Analyzer, however, since normal Analyzers are unlikely to work properly with wildcard templates.

Can be overridden by extending classes, to provide custom handling for wildcard queries, which may be necessary due to missing analyzer calls.

throw in overridden method to disallow ///
protected GetWildcardQuery ( String field, String termStr ) : Query
field String Name of the field query will use. ///
termStr String Term token that contains one or more wild card /// characters (? or *), but is not simple prefix term /// ///
return Lucene.Net.Search.Query

Modifiers() public method

public Modifiers ( ) : int
return int

NewBooleanClause() protected method

Builds a new BooleanClause instance
protected NewBooleanClause ( Query q, Occur occur ) : BooleanClause
q Lucene.Net.Search.Query sub query ///
occur Lucene.Net.Search.Occur how this clause should occur when matching documents ///
return Lucene.Net.Search.BooleanClause

NewBooleanQuery() protected method

Builds a new BooleanQuery instance
protected NewBooleanQuery ( bool disableCoord ) : Lucene.Net.Search.BooleanQuery
disableCoord bool disable coord ///
return Lucene.Net.Search.BooleanQuery

NewFuzzyQuery() protected method

Builds a new FuzzyQuery instance
protected NewFuzzyQuery ( Lucene.Net.Index.Term term, float minimumSimilarity, int prefixLength ) : Query
term Lucene.Net.Index.Term Term ///
minimumSimilarity float minimum similarity ///
prefixLength int prefix length ///
return Lucene.Net.Search.Query

NewMatchAllDocsQuery() protected method

Builds a new MatchAllDocsQuery instance
protected NewMatchAllDocsQuery ( ) : Query
return Lucene.Net.Search.Query

NewMultiPhraseQuery() protected method

Builds a new MultiPhraseQuery instance
protected NewMultiPhraseQuery ( ) : MultiPhraseQuery
return Lucene.Net.Search.MultiPhraseQuery

NewPhraseQuery() protected method

Builds a new PhraseQuery instance
protected NewPhraseQuery ( ) : PhraseQuery
return Lucene.Net.Search.PhraseQuery

NewPrefixQuery() protected method

Builds a new PrefixQuery instance
protected NewPrefixQuery ( Lucene.Net.Index.Term prefix ) : Query
prefix Lucene.Net.Index.Term Prefix term ///
return Lucene.Net.Search.Query

NewRangeQuery() protected method

Builds a new TermRangeQuery instance
protected NewRangeQuery ( String field, String part1, String part2, bool inclusive ) : Query
field String Field ///
part1 String min ///
part2 String max ///
inclusive bool true if range is inclusive ///
return Lucene.Net.Search.Query

NewTermQuery() protected method

Builds a new TermQuery instance
protected NewTermQuery ( Lucene.Net.Index.Term term ) : Query
term Lucene.Net.Index.Term term ///
return Lucene.Net.Search.Query

NewWildcardQuery() protected method

Builds a new WildcardQuery instance
protected NewWildcardQuery ( Lucene.Net.Index.Term t ) : Query
t Lucene.Net.Index.Term wildcard term ///
return Lucene.Net.Search.Query

Parse() public method

Parses a query string, returning a {@link Lucene.Net.Search.Query}.
public Parse ( String query ) : Query
query String the query string to be parsed. ///
return Lucene.Net.Search.Query

Query() public method

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

QueryParser() protected method

Constructor with user supplied CharStream.
protected QueryParser ( ICharStream stream ) : System
stream ICharStream
return System

QueryParser() protected method

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

QueryParser() public method

public QueryParser ( Lucene.Net.Util.Version matchVersion, String f, Analyzer a ) : System
matchVersion Lucene.Net.Util.Version
f String
a Lucene.Net.Analysis.Analyzer
return System

ReInit() public method

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

ReInit() public method

Reinitialise.
public ReInit ( Lucene.Net.QueryParsers.QueryParserTokenManager tm ) : void
tm Lucene.Net.QueryParsers.QueryParserTokenManager
return void

SetDateResolution() public method

Sets the default date resolution used by RangeQueries for fields for which no specific date resolutions has been set. Field specific resolutions can be set with {@link #SetDateResolution(String, DateTools.Resolution)}.
public SetDateResolution ( Lucene.Net.Documents.DateTools dateResolution ) : void
dateResolution Lucene.Net.Documents.DateTools the default date resolution to set ///
return void

SetDateResolution() public method

Sets the date resolution used by RangeQueries for a specific field.
public SetDateResolution ( String fieldName, Lucene.Net.Documents.DateTools dateResolution ) : void
fieldName String field for which the date resolution is to be set ///
dateResolution Lucene.Net.Documents.DateTools date resolution to set ///
return void

Term() public method

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

TopLevelQuery() public method

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

getDateResolution() public method

Returns the date resolution that is used by RangeQueries for the given field. Returns null, if no default or field specific date resolution has been set for the given field.
public getDateResolution ( String fieldName ) : Lucene.Net.Documents.DateTools.Resolution
fieldName String
return Lucene.Net.Documents.DateTools.Resolution

getToken() public method

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

Property Details

AND_OPERATOR public_oe static_oe property

Alternative form of QueryParser.Operator.AND
public static Operator AND_OPERATOR
return Operator

OR_OPERATOR public_oe static_oe property

Alternative form of QueryParser.Operator.OR
public static Operator OR_OPERATOR
return Operator

jj_nt public_oe property

public Token jj_nt
return Token

token public_oe property

public Token token
return Token

token_source public_oe property

public QueryParserTokenManager token_source
return QueryParserTokenManager