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[], Int32) as the method to use to initialize. If there are multiple parameters, each parameter set must be surrounded by curly braces.
Inherited Members
Namespace: Lucene.Net.Search
Assembly: Lucene.Net.dll
Syntax
public class MultiPhraseQuery : Query, IEnumerable<Term[]>, IEnumerable
Properties
| Improve this Doc View SourceSlop
Sets the phrase slop for this query.
Declaration
public virtual int Slop { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
See Also
Methods
| Improve this Doc View SourceAdd(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
| Improve this Doc View SourceAdd(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
| Improve this Doc View SourceAdd(Term[], Int32)
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 | |
System.Int32 | position |
See Also
| Improve this Doc View SourceCreateWeight(IndexSearcher)
Declaration
public override Weight CreateWeight(IndexSearcher searcher)
Parameters
Type | Name | Description |
---|---|---|
IndexSearcher | searcher |
Returns
Type | Description |
---|---|
Weight |
Overrides
| Improve this Doc View SourceEquals(Object)
Returns true
if o
is equal to this.
Declaration
public override bool Equals(object o)
Parameters
Type | Name | Description |
---|---|---|
System.Object | o |
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
| Improve this Doc View SourceExtractTerms(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 |
---|---|---|
System.Collections.Generic.ISet<Term> | terms |
Overrides
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | If this query is not yet rewritten |
GetEnumerator()
Returns an enumerator that iterates through the Lucene.Net.Search.MultiPhraseQuery.termArrays collection.
Declaration
public IEnumerator<Term[]> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<Term[]> | An enumerator that can be used to iterate through the Lucene.Net.Search.MultiPhraseQuery.termArrays collection. |
GetHashCode()
Returns a hash code value for this object.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 |
Overrides
| Improve this Doc View SourceGetPositions()
Returns the relative positions of terms in this phrase.
Declaration
public virtual int[] GetPositions()
Returns
Type | Description |
---|---|
System.Int32[] |
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 |
---|---|
System.Collections.Generic.IList<Term[]> |
Rewrite(IndexReader)
Declaration
public override Query Rewrite(IndexReader reader)
Parameters
Type | Name | Description |
---|---|---|
IndexReader | reader |
Returns
Type | Description |
---|---|
Query |
Overrides
| Improve this Doc View SourceToString(String)
Prints a user-readable version of this query.
Declaration
public override sealed string ToString(string f)
Parameters
Type | Name | Description |
---|---|---|
System.String | f |
Returns
Type | Description |
---|---|
System.String |
Overrides
Explicit Interface Implementations
| Improve this Doc View SourceIEnumerable.GetEnumerator()
Returns an enumerator that iterates through the Lucene.Net.Search.MultiPhraseQuery.termArrays.
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator | An enumerator that can be used to iterate through the Lucene.Net.Search.MultiPhraseQuery.termArrays collection. |