Class QueryParserBase
This class is overridden by QueryParser.
Implements
Inherited Members
Namespace: Lucene.Net.QueryParsers.Classic
Assembly: Lucene.Net.QueryParser.dll
Syntax
public abstract class QueryParserBase : QueryBuilder, ICommonQueryParserConfiguration
Constructors
| Improve this Doc View SourceQueryParserBase()
So the generated QueryParser(CharStream) won't error out
Declaration
protected QueryParserBase()
Fields
| Improve this Doc View SourceAND_OPERATOR
Alternative form of AND
Declaration
public const Operator AND_OPERATOR = Operator.AND
Field Value
Type | Description |
---|---|
Operator |
CONJ_AND
Declaration
protected const int CONJ_AND = 1
Field Value
Type | Description |
---|---|
System.Int32 |
CONJ_NONE
Declaration
protected const int CONJ_NONE = 0
Field Value
Type | Description |
---|---|
System.Int32 |
CONJ_OR
Declaration
protected const int CONJ_OR = 2
Field Value
Type | Description |
---|---|
System.Int32 |
m_field
Declaration
protected string m_field
Field Value
Type | Description |
---|---|
System.String |
MOD_NONE
Declaration
protected const int MOD_NONE = 0
Field Value
Type | Description |
---|---|
System.Int32 |
MOD_NOT
Declaration
protected const int MOD_NOT = 10
Field Value
Type | Description |
---|---|
System.Int32 |
MOD_REQ
Declaration
protected const int MOD_REQ = 11
Field Value
Type | Description |
---|---|
System.Int32 |
OR_OPERATOR
Alternative form of OR
Declaration
public const Operator OR_OPERATOR = Operator.OR
Field Value
Type | Description |
---|---|
Operator |
Properties
| Improve this Doc View SourceAllowLeadingWildcard
Set to true
to allow leading wildcard characters.
When set, *
or ?
are allowed as
the first character of a PrefixQuery and WildcardQuery.
Note that this can produce very slow
queries on big indexes.
Default: false.
Declaration
public virtual bool AllowLeadingWildcard { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
AnalyzeRangeTerms
Get or Set whether or not to analyze range terms when constructing TermRangeQuerys. For example, setting this to true can enable analyzing terms into collation keys for locale-sensitive TermRangeQuery.
Declaration
public virtual bool AnalyzeRangeTerms { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
AutoGeneratePhraseQueries
Set to true if phrase queries will be automatically generated when the analyzer returns more than one term from whitespace delimited text. NOTE: this behavior may not be suitable for all languages.
Set to false if phrase queries should only be generated when surrounded by double quotes.
Declaration
public bool AutoGeneratePhraseQueries { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
DefaultOperator
Gets or Sets the boolean operator of the QueryParser.
In default mode (OR_OPERATOR) terms without any modifiers
are considered optional: for example capital of Hungary
is equal to
capital OR of OR Hungary
.
In AND_OPERATOR mode terms are considered to be in conjunction: the
above mentioned query is parsed as capital AND of AND Hungary
Declaration
public virtual Operator DefaultOperator { get; set; }
Property Value
Type | Description |
---|---|
Operator |
Field
Returns the default field.
Declaration
public virtual string Field { get; }
Property Value
Type | Description |
---|---|
System.String |
FuzzyMinSim
Get or Set the minimum similarity for fuzzy queries. Default is 2f.
Declaration
public virtual float FuzzyMinSim { get; set; }
Property Value
Type | Description |
---|---|
System.Single |
FuzzyPrefixLength
Get or Set the prefix length for fuzzy queries. Default is 0.
Declaration
public virtual int FuzzyPrefixLength { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Locale
Get or Set locale used by date range parsing, lowercasing, and other locale-sensitive operations.
By default, the culture is null
, which indicates to read the culture on the fly
from System.Globalization.CultureInfo.CurrentCulture. This ensures if you change the culture on
the current thread, QueryParser will utilize it. You can also explicitly set a culture.
Setting the culture to null
will restore the default behavior if you have explicitly set a culture.
Declaration
public virtual CultureInfo Locale { get; set; }
Property Value
Type | Description |
---|---|
System.Globalization.CultureInfo |
LowercaseExpandedTerms
Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically
lower-cased or not. Default is true
.
Declaration
public virtual bool LowercaseExpandedTerms { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
MultiTermRewriteMethod
By default QueryParser uses CONSTANT_SCORE_AUTO_REWRITE_DEFAULT when creating a PrefixQuery, WildcardQuery or TermRangeQuery. This implementation is generally preferable because it a) Runs faster b) Does not have the scarcity of terms unduly influence score c) avoids any BooleanQuery.TooManyClausesException exception. However, if your application really needs to use the old-fashioned Lucene.Net.Search.BooleanQuery expansion rewriting and the above points are not relevant then use this to change the rewrite method.
Declaration
public virtual MultiTermQuery.RewriteMethod MultiTermRewriteMethod { get; set; }
Property Value
Type | Description |
---|---|
Lucene.Net.Search.MultiTermQuery.RewriteMethod |
PhraseSlop
Gets or Sets the default slop for phrases. If zero, then exact phrase matches are required. Default value is zero.
Declaration
public virtual int PhraseSlop { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
TimeZone
Get or Set the current time zone for date and time parsing operations.
By default, the time zone is null
, which indicates to read the time zone on the fly
from System.TimeZoneInfo.Local. This ensures if you change the time zone on
the current system, QueryParser will utilize it. You can also explicitly set a time zone.
Setting the time zone to null
will restore the default behavior if you have explicitly set a time zone.
Declaration
public virtual TimeZoneInfo TimeZone { get; set; }
Property Value
Type | Description |
---|---|
System.TimeZoneInfo |
Methods
| Improve this Doc View SourceAddClause(IList<BooleanClause>, Int32, Int32, Query)
Declaration
protected virtual void AddClause(IList<BooleanClause> clauses, int conj, int mods, Query q)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IList<Lucene.Net.Search.BooleanClause> | clauses | |
System.Int32 | conj | |
System.Int32 | mods | |
Lucene.Net.Search.Query | q |
AnalyzeMultitermTerm(String, String, Analyzer)
Declaration
protected virtual BytesRef AnalyzeMultitermTerm(string field, string part, Analyzer analyzerIn)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | |
System.String | part | |
Lucene.Net.Analysis.Analyzer | analyzerIn |
Returns
Type | Description |
---|---|
Lucene.Net.Util.BytesRef |
Escape(String)
Returns a string where those characters that QueryParser expects to be escaped are escaped by a preceding
\
.
Declaration
public static string Escape(string s)
Parameters
Type | Name | Description |
---|---|---|
System.String | s |
Returns
Type | Description |
---|---|
System.String |
GetBooleanQuery(IList<BooleanClause>)
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.
Declaration
protected virtual Query GetBooleanQuery(IList<BooleanClause> clauses)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IList<Lucene.Net.Search.BooleanClause> | clauses | List that contains Lucene.Net.Search.BooleanClause instances to join. |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query | Resulting Lucene.Net.Search.Query object. |
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
GetBooleanQuery(IList<BooleanClause>, Boolean)
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.
Declaration
protected virtual Query GetBooleanQuery(IList<BooleanClause> clauses, bool disableCoord)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IList<Lucene.Net.Search.BooleanClause> | clauses | List that contains Lucene.Net.Search.BooleanClause instances to join. |
System.Boolean | disableCoord | true if coord scoring should be disabled. |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query | Resulting Lucene.Net.Search.Query object. |
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
GetDateResolution(String)
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.
Declaration
public virtual DateTools.Resolution GetDateResolution(string fieldName)
Parameters
Type | Name | Description |
---|---|---|
System.String | fieldName |
Returns
Type | Description |
---|---|
Lucene.Net.Documents.DateTools.Resolution |
GetFieldQuery(String, String, Boolean)
Declaration
protected virtual Query GetFieldQuery(string field, string queryText, bool quoted)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | |
System.String | queryText | |
System.Boolean | quoted |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query |
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
GetFieldQuery(String, String, Int32)
Base implementation delegates to GetFieldQuery(String, String, Boolean). This method may be overridden, for example, to return a SpanNearQuery instead of a PhraseQuery.
Declaration
protected virtual Query GetFieldQuery(string field, string queryText, int slop)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | |
System.String | queryText | |
System.Int32 | slop |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query |
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
GetFuzzyQuery(String, String, Single)
Factory method for generating a query (similar to GetWildcardQuery(String, String)). Called when parser parses an input term token that has the fuzzy suffix (~) appended.
Declaration
protected virtual Query GetFuzzyQuery(string field, string termStr, float minSimilarity)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | Name of the field query will use. |
System.String | termStr | Term token to use for building term for the query |
System.Single | minSimilarity | minimum similarity |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query | Resulting Lucene.Net.Search.Query built for the term |
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
GetPrefixQuery(String, String)
Factory method for generating a query (similar to GetWildcardQuery(String, String)). 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.
Declaration
protected virtual Query GetPrefixQuery(string field, string termStr)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | Name of the field query will use. |
System.String | termStr | Term token to use for building term for the query |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query | Resulting Lucene.Net.Search.Query built for the term |
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
GetRangeQuery(String, String, String, Boolean, Boolean)
Declaration
protected virtual Query GetRangeQuery(string field, string part1, string part2, bool startInclusive, bool endInclusive)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | |
System.String | part1 | |
System.String | part2 | |
System.Boolean | startInclusive | |
System.Boolean | endInclusive |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query |
GetRegexpQuery(String, String)
Factory method for generating a query. Called when parser parses an input term token that contains a regular expression query.
Depending on settings, pattern term may be lower-cased automatically. It will not go through the default Analyzer, however, since normal Analyzers are unlikely to work properly with regular expression templates.
Can be overridden by extending classes, to provide custom handling for regular expression queries, which may be necessary due to missing analyzer calls.
Declaration
protected virtual Query GetRegexpQuery(string field, string termStr)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | Name of the field query will use. |
System.String | termStr | Term token that contains a regular expression |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query | Resulting Lucene.Net.Search.Query built for the term |
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
GetWildcardQuery(String, String)
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.
Declaration
protected virtual Query GetWildcardQuery(string field, string termStr)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | Name of the field query will use. |
System.String | termStr | Term token that contains one or more wild card characters (? or *), but is not simple prefix term |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query | Resulting Lucene.Net.Search.Query built for the term |
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
Init(LuceneVersion, String, Analyzer)
Initializes a query parser. Called by the QueryParser constructor
Declaration
public virtual void Init(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. |
NewBooleanClause(Query, Occur)
Builds a new Lucene.Net.Search.BooleanClause instance
Declaration
protected virtual BooleanClause NewBooleanClause(Query q, Occur occur)
Parameters
Type | Name | Description |
---|---|---|
Lucene.Net.Search.Query | q | sub query |
Lucene.Net.Search.Occur | occur | how this clause should occur when matching documents |
Returns
Type | Description |
---|---|
Lucene.Net.Search.BooleanClause | new Lucene.Net.Search.BooleanClause instance |
NewFieldQuery(Analyzer, String, String, Boolean)
Declaration
protected virtual Query NewFieldQuery(Analyzer analyzer, string field, string queryText, bool quoted)
Parameters
Type | Name | Description |
---|---|---|
Lucene.Net.Analysis.Analyzer | analyzer | |
System.String | field | |
System.String | queryText | |
System.Boolean | quoted |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query |
Exceptions
Type | Condition |
---|---|
ParseException | throw in overridden method to disallow |
NewFuzzyQuery(Term, Single, Int32)
Builds a new FuzzyQuery instance
Declaration
protected virtual Query NewFuzzyQuery(Term term, float minimumSimilarity, int prefixLength)
Parameters
Type | Name | Description |
---|---|---|
Lucene.Net.Index.Term | term | Term |
System.Single | minimumSimilarity | minimum similarity |
System.Int32 | prefixLength | prefix length |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query | new FuzzyQuery Instance |
NewMatchAllDocsQuery()
Builds a new MatchAllDocsQuery instance
Declaration
protected virtual Query NewMatchAllDocsQuery()
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query | new MatchAllDocsQuery instance |
NewPrefixQuery(Term)
Builds a new PrefixQuery instance
Declaration
protected virtual Query NewPrefixQuery(Term prefix)
Parameters
Type | Name | Description |
---|---|---|
Lucene.Net.Index.Term | prefix | Prefix term |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query | new PrefixQuery instance |
NewRangeQuery(String, String, String, Boolean, Boolean)
Builds a new TermRangeQuery instance
Declaration
protected virtual Query NewRangeQuery(string field, string part1, string part2, bool startInclusive, bool endInclusive)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | Field |
System.String | part1 | min |
System.String | part2 | max |
System.Boolean | startInclusive | true if the start of the range is inclusive |
System.Boolean | endInclusive | true if the end of the range is inclusive |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query | new TermRangeQuery instance |
NewRegexpQuery(Term)
Builds a new RegexpQuery instance
Declaration
protected virtual Query NewRegexpQuery(Term regexp)
Parameters
Type | Name | Description |
---|---|---|
Lucene.Net.Index.Term | regexp | Regexp term |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query | new RegexpQuery instance |
NewWildcardQuery(Term)
Builds a new WildcardQuery instance
Declaration
protected virtual Query NewWildcardQuery(Term t)
Parameters
Type | Name | Description |
---|---|---|
Lucene.Net.Index.Term | t | wildcard term |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query | new WildcardQuery instance |
Parse(String)
Parses a query string, returning a Lucene.Net.Search.Query.
Declaration
public virtual Query Parse(string query)
Parameters
Type | Name | Description |
---|---|---|
System.String | query | the query string to be parsed. |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query |
Exceptions
Type | Condition |
---|---|
ParseException | if the parsing fails |
ReInit(ICharStream)
Declaration
public abstract void ReInit(ICharStream stream)
Parameters
Type | Name | Description |
---|---|---|
ICharStream | stream |
SetDateResolution(DateTools.Resolution)
Gets or 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 SetDateResolution(String, DateTools.Resolution).
Declaration
public virtual void SetDateResolution(DateTools.Resolution dateResolution)
Parameters
Type | Name | Description |
---|---|---|
Lucene.Net.Documents.DateTools.Resolution | dateResolution |
SetDateResolution(String, DateTools.Resolution)
Sets the date resolution used by RangeQueries for a specific field.
Declaration
public virtual void SetDateResolution(string fieldName, DateTools.Resolution dateResolution)
Parameters
Type | Name | Description |
---|---|---|
System.String | fieldName | field for which the date resolution is to be set |
Lucene.Net.Documents.DateTools.Resolution | dateResolution | date resolution to set |
TopLevelQuery(String)
Declaration
public abstract Query TopLevelQuery(string field)
Parameters
Type | Name | Description |
---|---|---|
System.String | field |
Returns
Type | Description |
---|---|
Lucene.Net.Search.Query |