Fork me on GitHub
  • API

    Show / Hide Table of Contents

    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
    System.Object
    QueryBuilder
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: Lucene.Net.Util
    Assembly: Lucene.Net.dll
    Syntax
    public class QueryBuilder

    Constructors

    | Improve this Doc View Source

    QueryBuilder(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 Source

    Analyzer

    Gets or Sets the analyzer.

    Declaration
    public virtual Analyzer Analyzer { get; set; }
    Property Value
    Type Description
    Analyzer
    | Improve this Doc View Source

    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 Source

    CreateBooleanQuery(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 queryText.

    | Improve this Doc View Source

    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 queryText.

    | Improve this Doc View Source

    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

    true if phrases should be generated when terms occur at more than one position.

    System.Int32 phraseSlop

    Slop factor for phrase/multiphrase queries.

    Returns
    Type Description
    Query
    | Improve this Doc View Source

    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 [0..1] that should match

    Returns
    Type Description
    Query

    TermQuery or BooleanQuery, based on the analysis of queryText.

    | Improve this Doc View Source

    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 queryText.

    | Improve this Doc View Source

    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 queryText.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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.

    • Improve this Doc
    • View Source
    Back to top Copyright © 2022 The Apache Software Foundation, Licensed under the Apache License, Version 2.0
    Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation.
    All other marks mentioned may be trademarks or registered trademarks of their respective owners.