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.
Inheritance
Inherited Members
Namespace: Lucene.Net.Util
Assembly: Lucene.Net.dll
Syntax
public class QueryBuilder
Constructors
| Improve this Doc View SourceQueryBuilder(Analyzer)
Creates a new QueryBuilder using the given analyzer.
Declaration
public QueryBuilder(Analyzer analyzer)
Parameters
Type | Name | Description |
---|---|---|
Analyzer | analyzer |
Properties
| Improve this Doc View SourceAnalyzer
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.
When true
, 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 |
---|---|
System.Boolean |
Methods
| Improve this Doc View SourceCreateBooleanQuery(String, String)
Creates a boolean query from the query text.
This is equivalent to CreateBooleanQuery(field, queryText, Occur.SHOULD)
Declaration
public virtual Query CreateBooleanQuery(string field, string queryText)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | Field name. |
System.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 |
---|---|---|
System.String | field | Field name |
System.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, Boolean, Int32)
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. |
System.String | field | Field to create queries against. |
System.String | queryText | Text to be passed to the analysis chain. |
System.Boolean | quoted |
|
System.Int32 | phraseSlop | Slop factor for phrase/multiphrase queries. |
Returns
Type | Description |
---|---|
Query |
CreateMinShouldMatchQuery(String, String, Single)
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 |
---|---|---|
System.String | field | Field name. |
System.String | queryText | Text to be passed to the analyzer. |
System.Single | 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 to CreatePhraseQuery(field, queryText, 0)
Declaration
public virtual Query CreatePhraseQuery(string field, string queryText)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | Field name. |
System.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, Int32)
Creates a phrase query from the query text.
Declaration
public virtual Query CreatePhraseQuery(string field, string queryText, int phraseSlop)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | Field name. |
System.String | queryText | Text to be passed to the analyzer. |
System.Int32 | 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(Boolean)
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 |
---|---|---|
System.Boolean | 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. |