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
Afficher le fichier Open project: synhershko/lucene.net Class Usage Examples

Méthodes publiques

Свойство Type Description
AND_OPERATOR Operator
OR_OPERATOR Operator
jj_nt Token
token Token
token_source QueryParserTokenManager

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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

Méthode 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 méthode

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

Clause() public méthode

public Clause ( String field ) : Query
field String
Résultat Lucene.Net.Search.Query

Conjunction() public méthode

public Conjunction ( ) : int
Résultat int

Disable_tracing() public méthode

Disable tracing.
public Disable_tracing ( ) : void
Résultat void

Enable_tracing() public méthode

Enable tracing.
public Enable_tracing ( ) : void
Résultat void

Escape() public static méthode

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
Résultat String

GenerateParseException() public méthode

Generate ParseException.
public GenerateParseException ( ) : Lucene.Net.QueryParsers.ParseException
Résultat Lucene.Net.QueryParsers.ParseException

GetBooleanQuery() protected méthode

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. /// ///
Résultat Lucene.Net.Search.Query

GetBooleanQuery() protected méthode

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. /// ///
Résultat Lucene.Net.Search.Query

GetFieldQuery() protected méthode

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

GetFieldQuery() protected méthode

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
Résultat Lucene.Net.Search.Query

GetFuzzyQuery() protected méthode

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
Résultat Lucene.Net.Search.Query

GetNextToken() public méthode

Get the next Token.
public GetNextToken ( ) : Token
Résultat Token

GetPrefixQuery() protected méthode

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!) /// ///
Résultat Lucene.Net.Search.Query

GetRangeQuery() protected méthode

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
Résultat Lucene.Net.Search.Query

GetWildcardQuery() protected méthode

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 /// ///
Résultat Lucene.Net.Search.Query

Modifiers() public méthode

public Modifiers ( ) : int
Résultat int

NewBooleanClause() protected méthode

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 ///
Résultat Lucene.Net.Search.BooleanClause

NewBooleanQuery() protected méthode

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

NewFuzzyQuery() protected méthode

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 ///
Résultat Lucene.Net.Search.Query

NewMatchAllDocsQuery() protected méthode

Builds a new MatchAllDocsQuery instance
protected NewMatchAllDocsQuery ( ) : Query
Résultat Lucene.Net.Search.Query

NewMultiPhraseQuery() protected méthode

Builds a new MultiPhraseQuery instance
protected NewMultiPhraseQuery ( ) : MultiPhraseQuery
Résultat Lucene.Net.Search.MultiPhraseQuery

NewPhraseQuery() protected méthode

Builds a new PhraseQuery instance
protected NewPhraseQuery ( ) : PhraseQuery
Résultat Lucene.Net.Search.PhraseQuery

NewPrefixQuery() protected méthode

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

NewRangeQuery() protected méthode

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 ///
Résultat Lucene.Net.Search.Query

NewTermQuery() protected méthode

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

NewWildcardQuery() protected méthode

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

Parse() public méthode

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

Query() public méthode

public Query ( String field ) : Query
field String
Résultat Lucene.Net.Search.Query

QueryParser() protected méthode

Constructor with user supplied CharStream.
protected QueryParser ( ICharStream stream ) : System
stream ICharStream
Résultat System

QueryParser() protected méthode

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

QueryParser() public méthode

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

ReInit() public méthode

Reinitialise.
public ReInit ( ICharStream stream ) : void
stream ICharStream
Résultat void

ReInit() public méthode

Reinitialise.
public ReInit ( Lucene.Net.QueryParsers.QueryParserTokenManager tm ) : void
tm Lucene.Net.QueryParsers.QueryParserTokenManager
Résultat void

SetDateResolution() public méthode

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 ///
Résultat void

SetDateResolution() public méthode

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 ///
Résultat void

Term() public méthode

public Term ( String field ) : Query
field String
Résultat Lucene.Net.Search.Query

TopLevelQuery() public méthode

public TopLevelQuery ( String field ) : Query
field String
Résultat Lucene.Net.Search.Query

getDateResolution() public méthode

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
Résultat Lucene.Net.Documents.DateTools.Resolution

getToken() public méthode

Get the specific Token.
public getToken ( int index ) : Token
index int
Résultat Token

Property Details

AND_OPERATOR public_oe static_oe property

Alternative form of QueryParser.Operator.AND
public static Operator AND_OPERATOR
Résultat Operator

OR_OPERATOR public_oe static_oe property

Alternative form of QueryParser.Operator.OR
public static Operator OR_OPERATOR
Résultat Operator

jj_nt public_oe property

public Token jj_nt
Résultat Token

token public_oe property

public Token token
Résultat Token

token_source public_oe property

public QueryParserTokenManager token_source
Résultat QueryParserTokenManager