Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
Classes | Public Member Functions | Public Attributes | Properties | List of all members
Lucene.Net.Search.FuzzyQuery Class Reference

Implements the fuzzy search query. The similarity measurement is based on the Levenshtein (edit distance) algorithm. More...

Inherits Lucene.Net.Search.MultiTermQuery.

Classes

class  ScoreTerm
 

Public Member Functions

 FuzzyQuery (Term term, float minimumSimilarity, int prefixLength)
 Create a new FuzzyQuery that will match terms with a similarity of at least minimumSimilarity to term. If a prefixLength > 0 is specified, a common prefix of that length is also required.
 
 FuzzyQuery (Term term, float minimumSimilarity)
 Calls FuzzyQuery(term, minimumSimilarity, 0).
 
 FuzzyQuery (Term term)
 Calls FuzzyQuery(term, 0.5f, 0).
 
override Query Rewrite (IndexReader reader)
 Expert: called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into a BooleanQuery that consists of TermQuerys.
 
override System.String ToString (System.String field)
 Prints a query to a string, with field assumed to be the default field and omitted. The representation used is one that is supposed to be readable by QueryParser. However, there are the following limitations:

  • If the query was created by the parser, the printed representation may not be exactly what was parsed. For example, characters that need to be escaped will be represented without the required backslash.
  • Some of the more complicated queries (e.g. span queries) don't have a representation that can be parsed by QueryParser.

 
override int GetHashCode ()
 
override bool Equals (System.Object obj)
 
- Public Member Functions inherited from Lucene.Net.Search.MultiTermQuery
virtual void ClearTotalNumberOfTerms ()
 Expert: Resets the counting of unique terms. Do this before executing the query/filter.
 
override Query Rewrite (IndexReader reader)
 Expert: called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into a BooleanQuery that consists of TermQuerys.
 
override int GetHashCode ()
 
override bool Equals (System.Object obj)
 
- Public Member Functions inherited from Lucene.Net.Search.Query
override System.String ToString ()
 Prints a query to a string.
 
virtual Weight CreateWeight (Searcher searcher)
 Expert: Constructs an appropriate Weight implementation for this query.
 
virtual Weight Weight (Searcher searcher)
 Expert: Constructs and initializes a Weight for a top-level query.
 
virtual Query Combine (Query[] queries)
 Expert: called when re-writing queries under MultiSearcher.
 
virtual void ExtractTerms (System.Collections.Generic.ISet< Term > terms)
 Expert: adds all terms occuring in this query to the terms set. Only works if this query is in its rewritten form.
 
virtual Similarity GetSimilarity (Searcher searcher)
 Expert: Returns the Similarity implementation to be used for this query. Subclasses may override this method to specify their own Similarity implementation, perhaps one that delegates through that of the Searcher. By default the Searcher's Similarity implementation is returned.
 
virtual System.Object Clone ()
 Returns a clone of this query.
 
override int GetHashCode ()
 
override bool Equals (System.Object obj)
 

Public Attributes

const float defaultMinSimilarity = 0.5f
 
const int defaultPrefixLength = 0
 

Properties

Term Term [get, set]
 Returns the pattern term.
 
virtual float MinSimilarity [get]
 Returns the minimum similarity that is required for this query to match.
 
virtual int PrefixLength [get]
 Returns the non-fuzzy prefix length. This is the number of characters at the start of a term that must be identical (not fuzzy) to the query term if the query is to match that term.
 
override RewriteMethod RewriteMethod [set]
 
- Properties inherited from Lucene.Net.Search.MultiTermQuery
virtual int TotalNumberOfTerms [get]
 Expert: Return the number of unique terms visited during execution of the query. If there are many of them, you may consider using another query type or optimize your total term count in index. This method is not thread safe, be sure to only call it when no query is running! If you re-use the same query instance for another search, be sure to first reset the term counter with ClearTotalNumberOfTerms. On optimized indexes / no MultiReaders, you get the correct number of unique terms for the whole index. Use this number to compare different queries. For non-optimized indexes this number can also be achived in non-constant-score mode. In constant-score mode you get the total number of terms seeked for all segments / sub-readers.
 
virtual RewriteMethod RewriteMethod [get, set]
 Sets the rewrite method to be used when executing the query. You can use one of the four core methods, or implement your own subclass of Search.RewriteMethod.
 
- Properties inherited from Lucene.Net.Search.Query
virtual float Boost [get, set]
 Gets or sets the boost for this query clause to b. Documents matching this clause will (in addition to the normal weightings) have their score multiplied by b. The boost is 1.0 by default.
 

Additional Inherited Members

- Static Public Member Functions inherited from Lucene.Net.Search.Query
static Query MergeBooleanQueries (params BooleanQuery[] queries)
 Expert: merges the clauses of a set of BooleanQuery's into a single BooleanQuery.
 
- Static Public Attributes inherited from Lucene.Net.Search.MultiTermQuery
static readonly RewriteMethod CONSTANT_SCORE_FILTER_REWRITE = new ConstantScoreFilterRewrite()
 A rewrite method that first creates a private Filter, by visiting each term in sequence and marking all docs for that term. Matching documents are assigned a constant score equal to the query's boost.
 
static readonly RewriteMethod SCORING_BOOLEAN_QUERY_REWRITE = new ScoringBooleanQueryRewrite()
 A rewrite method that first translates each term into Occur.SHOULD clause in a BooleanQuery, and keeps the scores as computed by the query. Note that typically such scores are meaningless to the user, and require non-trivial CPU to compute, so it's almost always better to use CONSTANT_SCORE_AUTO_REWRITE_DEFAULT instead.
 
static readonly RewriteMethod CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE = new ConstantScoreBooleanQueryRewrite()
 Like SCORING_BOOLEAN_QUERY_REWRITE except scores are not computed. Instead, each matching document receives a constant score equal to the query's boost.
 
static readonly RewriteMethod CONSTANT_SCORE_AUTO_REWRITE_DEFAULT
 Read-only default instance of ConstantScoreAutoRewrite , with ConstantScoreAutoRewrite.TermCountCutoff set to ConstantScoreAutoRewrite.DEFAULT_TERM_COUNT_CUTOFF
 
- Protected Member Functions inherited from Lucene.Net.Search.MultiTermQuery
 MultiTermQuery ()
 Constructs a query matching terms that cannot be represented with a single Term.
 

Detailed Description

Implements the fuzzy search query. The similarity measurement is based on the Levenshtein (edit distance) algorithm.

Warning: this query is not very scalable with its default prefix length of 0 - in this case, every term will be enumerated and cause an edit score calculation.

Definition at line 41 of file FuzzyQuery.cs.

Constructor & Destructor Documentation

Lucene.Net.Search.FuzzyQuery.FuzzyQuery ( Term  term,
float  minimumSimilarity,
int  prefixLength 
)

Create a new FuzzyQuery that will match terms with a similarity of at least minimumSimilarity to term. If a prefixLength > 0 is specified, a common prefix of that length is also required.

Parameters
termthe term to search for
minimumSimilaritya value between 0 and 1 to set the required similarity between the query term and the matching terms. For example, for a minimumSimilarity of 0.5 a term of the same length as the query term is considered similar to the query term if the edit distance between both terms is less than length(term)*0.5
prefixLengthlength of common (non-fuzzy) prefix

<throws> IllegalArgumentException if minimumSimilarity is >= 1 or < 0 </throws>

or if prefixLength < 0

Definition at line 73 of file FuzzyQuery.cs.

Lucene.Net.Search.FuzzyQuery.FuzzyQuery ( Term  term,
float  minimumSimilarity 
)

Calls FuzzyQuery(term, minimumSimilarity, 0).

Definition at line 95 of file FuzzyQuery.cs.

Lucene.Net.Search.FuzzyQuery.FuzzyQuery ( Term  term)

Calls FuzzyQuery(term, 0.5f, 0).

Definition at line 100 of file FuzzyQuery.cs.

Member Function Documentation

override bool Lucene.Net.Search.FuzzyQuery.Equals ( System.Object  obj)

Definition at line 233 of file FuzzyQuery.cs.

override int Lucene.Net.Search.FuzzyQuery.GetHashCode ( )

Definition at line 223 of file FuzzyQuery.cs.

override Query Lucene.Net.Search.FuzzyQuery.Rewrite ( IndexReader  reader)
virtual

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

Reimplemented from Lucene.Net.Search.Query.

Definition at line 130 of file FuzzyQuery.cs.

override System.String Lucene.Net.Search.FuzzyQuery.ToString ( System.String  field)
virtual

Prints a query to a string, with field assumed to be the default field and omitted. The representation used is one that is supposed to be readable by QueryParser. However, there are the following limitations:

  • If the query was created by the parser, the printed representation may not be exactly what was parsed. For example, characters that need to be escaped will be represented without the required backslash.
  • Some of the more complicated queries (e.g. span queries) don't have a representation that can be parsed by QueryParser.

Implements Lucene.Net.Search.Query.

Definition at line 190 of file FuzzyQuery.cs.

Member Data Documentation

const float Lucene.Net.Search.FuzzyQuery.defaultMinSimilarity = 0.5f

Definition at line 44 of file FuzzyQuery.cs.

const int Lucene.Net.Search.FuzzyQuery.defaultPrefixLength = 0

Definition at line 45 of file FuzzyQuery.cs.

Property Documentation

virtual float Lucene.Net.Search.FuzzyQuery.MinSimilarity
get

Returns the minimum similarity that is required for this query to match.

float value between 0.0 and 1.0

Definition at line 107 of file FuzzyQuery.cs.

virtual int Lucene.Net.Search.FuzzyQuery.PrefixLength
get

Returns the non-fuzzy prefix length. This is the number of characters at the start of a term that must be identical (not fuzzy) to the query term if the query is to match that term.

Definition at line 116 of file FuzzyQuery.cs.

override RewriteMethod Lucene.Net.Search.FuzzyQuery.RewriteMethod
set

Definition at line 126 of file FuzzyQuery.cs.

Term Lucene.Net.Search.FuzzyQuery.Term
getset

Returns the pattern term.

Definition at line 52 of file FuzzyQuery.cs.


The documentation for this class was generated from the following file: