Class QueryBuilder
Creates queries from the Analyzer chain.
Example usage:QueryBuilder builder = new QueryBuilder(analyzer);
Query a = builder.CreateBooleanQuery("body", "just a test");
Query b = builder.CreatePhraseQuery("body", "another test");
Query c = builder.CreateMinShouldMatchQuery("body", "another test", 0.5f);
This can also be used as a subclass for query parsers to make it easier
to interact with the analysis chain. Factory methods such as NewTermQuery(Term)
are provided so that the generated queries can be customized.
Inherited Members
Namespace: Lucene.Net.Util
Assembly: Lucene.Net.dll
Syntax
public class QueryBuilder
Constructors
QueryBuilder(Analyzer)
Creates a new QueryBuilder using the given analyzer.
Declaration
public QueryBuilder(Analyzer analyzer)
Parameters
Type | Name | Description |
---|---|---|
Analyzer | analyzer |
Properties
Analyzer
Gets or Sets the analyzer.
Declaration
public virtual Analyzer Analyzer { get; set; }
Property Value
Type | Description |
---|---|
Analyzer |
EnablePositionIncrements
Gets or Sets whether position increments are enabled.
Whentrue
, result phrase and multi-phrase queries will
be aware of position increments.
Useful when e.g. a StopFilter increases the position increment of
the token that follows an omitted token.
Default: true.
Declaration
public virtual bool EnablePositionIncrements { get; set; }
Property Value
Type | Description |
---|---|
bool |
Methods
CreateBooleanQuery(string, string)
Creates a boolean query from the query text.
This is equivalent toCreateBooleanQuery(field, queryText, Occur.SHOULD)
Declaration
public virtual Query CreateBooleanQuery(string field, string queryText)
Parameters
Type | Name | Description |
---|---|---|
string | field | Field name. |
string | queryText | Text to be passed to the analyzer. |
Returns
Type | Description |
---|---|
Query | TermQuery or BooleanQuery, based on the analysis
of |
CreateBooleanQuery(string, string, Occur)
Creates a boolean query from the query text.
Declaration
public virtual Query CreateBooleanQuery(string field, string queryText, Occur @operator)
Parameters
Type | Name | Description |
---|---|---|
string | field | Field name |
string | queryText | Text to be passed to the analyzer. |
Occur | operator | Operator used for clauses between analyzer tokens. |
Returns
Type | Description |
---|---|
Query | TermQuery or BooleanQuery, based on the analysis
of |
CreateFieldQuery(Analyzer, Occur, string, string, bool, int)
Creates a query from the analysis chain.
Expert: this is more useful for subclasses such as queryparsers. If using this class directly, just use CreateBooleanQuery(string, string) and CreatePhraseQuery(string, string).Declaration
protected Query CreateFieldQuery(Analyzer analyzer, Occur @operator, string field, string queryText, bool quoted, int phraseSlop)
Parameters
Type | Name | Description |
---|---|---|
Analyzer | analyzer | Analyzer used for this query. |
Occur | operator | Default boolean operator used for this query. |
string | field | Field to create queries against. |
string | queryText | Text to be passed to the analysis chain. |
bool | quoted |
|
int | phraseSlop | Slop factor for phrase/multiphrase queries. |
Returns
Type | Description |
---|---|
Query |
CreateMinShouldMatchQuery(string, string, float)
Creates a minimum-should-match query from the query text.
Declaration
public virtual Query CreateMinShouldMatchQuery(string field, string queryText, float fraction)
Parameters
Type | Name | Description |
---|---|---|
string | field | Field name. |
string | queryText | Text to be passed to the analyzer. |
float | fraction | of query terms |
Returns
Type | Description |
---|---|
Query | TermQuery or BooleanQuery, based on the analysis
of |
CreatePhraseQuery(string, string)
Creates a phrase query from the query text.
This is equivalent toCreatePhraseQuery(field, queryText, 0)
Declaration
public virtual Query CreatePhraseQuery(string field, string queryText)
Parameters
Type | Name | Description |
---|---|---|
string | field | Field name. |
string | queryText | Text to be passed to the analyzer. |
Returns
Type | Description |
---|---|
Query | TermQuery, BooleanQuery, PhraseQuery, or
MultiPhraseQuery, based on the analysis of |
CreatePhraseQuery(string, string, int)
Creates a phrase query from the query text.
Declaration
public virtual Query CreatePhraseQuery(string field, string queryText, int phraseSlop)
Parameters
Type | Name | Description |
---|---|---|
string | field | Field name. |
string | queryText | Text to be passed to the analyzer. |
int | phraseSlop | number of other words permitted between words in query phrase |
Returns
Type | Description |
---|---|
Query | TermQuery, BooleanQuery, PhraseQuery, or
MultiPhraseQuery, based on the analysis of |
NewBooleanQuery(bool)
Builds a new BooleanQuery instance.
This is intended for subclasses that wish to customize the generated queries.Declaration
protected virtual BooleanQuery NewBooleanQuery(bool disableCoord)
Parameters
Type | Name | Description |
---|---|---|
bool | disableCoord | Disable coord. |
Returns
Type | Description |
---|---|
BooleanQuery | New BooleanQuery instance. |
NewMultiPhraseQuery()
Builds a new MultiPhraseQuery instance.
This is intended for subclasses that wish to customize the generated queries.Declaration
protected virtual MultiPhraseQuery NewMultiPhraseQuery()
Returns
Type | Description |
---|---|
MultiPhraseQuery | New MultiPhraseQuery instance. |
NewPhraseQuery()
Builds a new PhraseQuery instance.
This is intended for subclasses that wish to customize the generated queries.Declaration
protected virtual PhraseQuery NewPhraseQuery()
Returns
Type | Description |
---|---|
PhraseQuery | New PhraseQuery instance. |
NewTermQuery(Term)
Builds a new TermQuery instance.
This is intended for subclasses that wish to customize the generated queries.Declaration
protected virtual Query NewTermQuery(Term term)
Parameters
Type | Name | Description |
---|---|---|
Term | term | Term. |
Returns
Type | Description |
---|---|
Query | New TermQuery instance. |