Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class MultiPhraseQuery

    MultiPhraseQuery is a generalized version of PhraseQuery, with an added method Add(Term[]).

    To use this class, to search for the phrase "Microsoft app*" first use Add(Term) on the term "Microsoft", then find all terms that have "app" as prefix using MultiFields.GetFields(IndexReader).GetTerms(string), and use Add(Term[]) to add them to the query.

    Collection initializer note: To create and populate a MultiPhraseQuery in a single statement, you can use the following example as a guide:
    var multiPhraseQuery = new MultiPhraseQuery() {
        new Term("field", "microsoft"), 
        new Term("field", "office")
    };

    Note that as long as you specify all of the parameters, you can use either Add(Term), Add(Term[]), or Add(Term[], int) as the method to use to initialize. If there are multiple parameters, each parameter set must be surrounded by curly braces.

    Inheritance
    object
    Query
    MultiPhraseQuery
    Implements
    IEnumerable<Term[]>
    IEnumerable
    Inherited Members
    Query.Boost
    Query.ToString()
    Query.Clone()
    object.Equals(object, object)
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Lucene.Net.Search
    Assembly: Lucene.Net.dll
    Syntax
    public class MultiPhraseQuery : Query, IEnumerable<Term[]>, IEnumerable

    Properties

    Slop

    Sets the phrase slop for this query.

    Declaration
    public virtual int Slop { get; set; }
    Property Value
    Type Description
    int
    See Also
    Slop

    Methods

    Add(Term)

    Add a single term at the next position in the phrase.

    Declaration
    public virtual void Add(Term term)
    Parameters
    Type Name Description
    Term term
    See Also
    Add(Term)

    Add(Term[])

    Add multiple terms at the next position in the phrase. Any of the terms may match.

    Declaration
    public virtual void Add(Term[] terms)
    Parameters
    Type Name Description
    Term[] terms
    See Also
    Add(Term)

    Add(Term[], int)

    Allows to specify the relative position of terms within the phrase.

    Declaration
    public virtual void Add(Term[] terms, int position)
    Parameters
    Type Name Description
    Term[] terms
    int position
    See Also
    Add(Term, int)

    CreateWeight(IndexSearcher)

    Expert: Constructs an appropriate Weight implementation for this query.

    Only implemented by primitive queries, which re-write to themselves.
    Declaration
    public override Weight CreateWeight(IndexSearcher searcher)
    Parameters
    Type Name Description
    IndexSearcher searcher
    Returns
    Type Description
    Weight
    Overrides
    Query.CreateWeight(IndexSearcher)

    Equals(object)

    Returns true if o is equal to this.

    Declaration
    public override bool Equals(object o)
    Parameters
    Type Name Description
    object o
    Returns
    Type Description
    bool
    Overrides
    Query.Equals(object)

    ExtractTerms(ISet<Term>)

    Expert: adds all terms occurring in this query to the terms set. Only works if this query is in its rewritten (Rewrite(IndexReader)) form.

    Declaration
    public override void ExtractTerms(ISet<Term> terms)
    Parameters
    Type Name Description
    ISet<Term> terms
    Overrides
    Query.ExtractTerms(ISet<Term>)
    Exceptions
    Type Condition
    InvalidOperationException

    If this query is not yet rewritten

    GetEnumerator()

    Returns an enumerator that iterates through the termArrays collection.

    Declaration
    public IEnumerator<Term[]> GetEnumerator()
    Returns
    Type Description
    IEnumerator<Term[]>

    An enumerator that can be used to iterate through the termArrays collection.

    GetHashCode()

    Returns a hash code value for this object.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int
    Overrides
    Query.GetHashCode()

    GetPositions()

    Returns the relative positions of terms in this phrase.

    Declaration
    public virtual int[] GetPositions()
    Returns
    Type Description
    int[]

    GetTermArrays()

    Returns a List of the terms in the multiphrase. Do not modify the List or its contents.

    Declaration
    public virtual IList<Term[]> GetTermArrays()
    Returns
    Type Description
    IList<Term[]>

    Rewrite(IndexReader)

    Expert: called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into a BooleanQuery that consists of TermQuerys.

    Declaration
    public override Query Rewrite(IndexReader reader)
    Parameters
    Type Name Description
    IndexReader reader
    Returns
    Type Description
    Query
    Overrides
    Query.Rewrite(IndexReader)

    ToString(string)

    Prints a user-readable version of this query.

    Declaration
    public override sealed string ToString(string f)
    Parameters
    Type Name Description
    string f
    Returns
    Type Description
    string
    Overrides
    Query.ToString(string)

    Implements

    IEnumerable<T>
    IEnumerable
    Back to top Copyright © 2024 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.