Class PhraseQuery
A Query that matches documents containing a particular sequence of terms.
A PhraseQuery is built by QueryParser for input like "new york"
.
var phraseQuery = new PhraseQuery() {
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) 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.
Inherited Members
Namespace: Lucene.Net.Search
Assembly: Lucene.Net.dll
Syntax
public class PhraseQuery : Query, IEnumerable<Term>, IEnumerable
Constructors
PhraseQuery()
Constructs an empty phrase query.
Declaration
public PhraseQuery()
Properties
Slop
Sets the number of other words permitted between words in query phrase.
If zero, then this is an exact phrase search. For larger values this works
like a WITHIN
or NEAR
operator.
Declaration
public virtual int Slop { get; set; }
Property Value
Type | Description |
---|---|
int |
Methods
Add(Term)
Adds a term to the end of the query phrase. The relative position of the term is the one immediately after the last term added.
Declaration
public virtual void Add(Term term)
Parameters
Type | Name | Description |
---|---|---|
Term | term |
Add(Term, int)
Adds a term to the end of the query phrase. The relative position of the term within the phrase is specified explicitly. this allows e.g. phrases with more than one term at the same position or phrases with gaps (e.g. in connection with stopwords).
Declaration
public virtual void Add(Term term, int position)
Parameters
Type | Name | Description |
---|---|---|
Term | term | |
int | position |
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
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
ExtractTerms(ISet<Term>)
A Query that matches documents containing a particular sequence of terms.
A PhraseQuery is built by QueryParser for input like "new york"
.
var phraseQuery = new PhraseQuery() {
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) 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.
Declaration
public override void ExtractTerms(ISet<Term> queryTerms)
Parameters
Type | Name | Description |
---|---|---|
ISet<Term> | queryTerms |
Overrides
See Also
GetEnumerator()
Returns an enumerator that iterates through the terms collection.
Declaration
public IEnumerator<Term> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<Term> | An enumerator that can be used to iterate through the terms collection. |
GetHashCode()
Returns a hash code value for this object.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int |
Overrides
GetPositions()
Returns the relative positions of terms in this phrase.
Declaration
public virtual int[] GetPositions()
Returns
Type | Description |
---|---|
int[] |
GetTerms()
Returns the set of terms in this phrase.
Declaration
public virtual Term[] GetTerms()
Returns
Type | Description |
---|---|
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
ToString(string)
Prints a user-readable version of this query.
Declaration
public override string ToString(string f)
Parameters
Type | Name | Description |
---|---|---|
string | f |
Returns
Type | Description |
---|---|
string |