Lucene++ - a full-featured, c++ search engine
API Documentation

Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes
Lucene::FuzzyQuery Class Reference

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

`#include <FuzzyQuery.h>`

Inheritance diagram for Lucene::FuzzyQuery:

## Public Member Functions

| FuzzyQuery (const TermPtr &term, double minimumSimilarity, int32_t 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 (const TermPtr &term, double minimumSimilarity)
| FuzzyQuery (const TermPtr &term)
virtual | ~FuzzyQuery ()
virtual String | getClassName ()
boost::shared_ptr< FuzzyQuery > | shared_from_this ()
double | getMinSimilarity ()
| Returns the minimum similarity that is required for this query to match.
int32_t | getPrefixLength ()
| 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.
TermPtr | getTerm ()
| Returns the pattern term.
virtual void | setRewriteMethod (const RewriteMethodPtr &method)
| 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 `RewriteMethod`.
virtual QueryPtr | rewrite (const IndexReaderPtr &reader)
| Called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into a BooleanQuery that consists of TermQuerys.
virtual LuceneObjectPtr | clone (const LuceneObjectPtr &other=LuceneObjectPtr())
| Returns a clone of this query.
virtual String | toString (const String &field)
| Prints a query to a string, with field assumed to be the default field and omitted.
virtual int32_t | hashCode ()
| Return hash code for this object.
virtual bool | equals (const LuceneObjectPtr &other)
| Return whether two objects are equal.
Public Member Functions inherited from Lucene::MultiTermQuery
| MultiTermQuery ()
virtual | ~MultiTermQuery ()
boost::shared_ptr< MultiTermQuery > | shared_from_this ()
int32_t | getTotalNumberOfTerms ()
| 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.
void | clearTotalNumberOfTerms ()
| Resets the counting of unique terms. Do this before executing the query/filter.
virtual RewriteMethodPtr | getRewriteMethod ()
Public Member Functions inherited from Lucene::Query
| Query ()
virtual | ~Query ()
boost::shared_ptr< Query > | shared_from_this ()
virtual void | setBoost (double b)
| 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.
virtual double | getBoost ()
| Gets the boost for this clause. Documents matching this clause will (in addition to the normal weightings) have their score multiplied by b. The boost is 1.0 by default.
virtual String | toString ()
| Prints a query to a string.
virtual WeightPtr | createWeight (const SearcherPtr &searcher)
| Constructs an appropriate Weight implementation for this query. Only implemented by primitive queries, which re-write to themselves.
virtual WeightPtr | weight (const SearcherPtr &searcher)
| Constructs and initializes a Weight for a top-level query.
virtual QueryPtr | combine (Collection< QueryPtr > queries)
| Called when re-writing queries under MultiSearcher.
virtual void | extractTerms (SetTerm terms)
| Adds all terms occurring in this query to the terms set. Only works if this query is in its `rewritten` form.
virtual SimilarityPtr | getSimilarity (const SearcherPtr &searcher)
| 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.
String | boostString ()
| Return given boost value as a string.
Public Member Functions inherited from Lucene::LuceneObject
virtual | ~LuceneObject ()
virtual void | initialize ()
| Called directly after instantiation to create objects that depend on this object being fully constructed.
virtual int32_t | compareTo (const LuceneObjectPtr &other)
| Compare two objects.
Public Member Functions inherited from Lucene::LuceneSync
virtual | ~LuceneSync ()
virtual SynchronizePtr | getSync ()
| Return this object synchronize lock.
virtual LuceneSignalPtr | getSignal ()
| Return this object signal.
virtual void | lock (int32_t timeout=0)
| Lock this object using an optional timeout.
virtual void | unlock ()
| Unlock this object.
virtual bool | holdsLock ()
| Returns true if this object is currently locked by current thread.
virtual void | wait (int32_t timeout=0)
| Wait for signal using an optional timeout.
virtual void | notifyAll ()
| Notify all threads waiting for signal.

## Static Public Member Functions

static String | _getClassName ()
static double | defaultMinSimilarity ()
Static Public Member Functions inherited from Lucene::MultiTermQuery
static String | _getClassName ()
static RewriteMethodPtr | CONSTANT_SCORE_FILTER_REWRITE ()
| 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 RewriteMethodPtr | SCORING_BOOLEAN_QUERY_REWRITE ()
| A rewrite method that first translates each term into `BooleanClause.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 RewriteMethodPtr | CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE ()
| 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 RewriteMethodPtr | CONSTANT_SCORE_AUTO_REWRITE_DEFAULT ()
| Read-only default instance of `ConstantScoreAutoRewrite`, with `ConstantScoreAutoRewrite#setTermCountCutoff` set to `ConstantScoreAutoRewrite#DEFAULT_TERM_COUNT_CUTOFF` and `ConstantScoreAutoRewrite#setDocCountPercent` set to `ConstantScoreAutoRewrite#DEFAULT_DOC_COUNT_PERCENT`. Note that you cannot alter the configuration of this instance; you'll need to create a private instance instead.
Static Public Member Functions inherited from Lucene::Query
static String | _getClassName ()
static QueryPtr | mergeBooleanQueries (Collection< BooleanQueryPtr > queries)
| Merges the clauses of a set of BooleanQuery's into a single BooleanQuery.

## Static Public Attributes

static const int32_t | defaultPrefixLength

## Protected Member Functions

void | ConstructQuery (const TermPtr &term, double minimumSimilarity, int32_t prefixLength)
virtual FilteredTermEnumPtr | getEnum (const IndexReaderPtr &reader)
| Construct the enumeration to be used, expanding the pattern term.
Protected Member Functions inherited from Lucene::MultiTermQuery
void | incTotalNumberOfTerms (int32_t inc)
Protected Member Functions inherited from Lucene::LuceneObject
| LuceneObject ()

## Protected Attributes

double | minimumSimilarity
int32_t | prefixLength
bool | termLongEnough
TermPtr | term
Protected Attributes inherited from Lucene::MultiTermQuery
RewriteMethodPtr | rewriteMethod
int32_t | numberOfTerms
Protected Attributes inherited from Lucene::Query
double | boost
Protected Attributes inherited from Lucene::LuceneSync
SynchronizePtr | objectLock
LuceneSignalPtr | objectSignal

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

## Constructor & Destructor Documentation

## ◆ FuzzyQuery() [1/3]

Lucene::FuzzyQuery::FuzzyQuery | ( | const TermPtr & | term,
|  | double | minimumSimilarity,
|  | int32_t | 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

  term | The term to search for
  minimumSimilarity | A 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
  prefixLength | Length of common (non-fuzzy) prefix

References minimumSimilarity, prefixLength, and term.

Referenced by _getClassName().

## ◆ FuzzyQuery() [2/3]

Lucene::FuzzyQuery::FuzzyQuery | ( | const TermPtr & | term,
|  | double | minimumSimilarity )

References minimumSimilarity, and term.

## ◆ FuzzyQuery() [3/3]

Lucene::FuzzyQuery::FuzzyQuery | ( | const TermPtr & | term | ) |

References term.

## ◆ ~FuzzyQuery()

virtual Lucene::FuzzyQuery::~FuzzyQuery | ( |  | ) |

virtual

## Member Function Documentation

## ◆ _getClassName()

String Lucene::FuzzyQuery::_getClassName | ( |  | ) |

inline static

References FuzzyQuery().

## ◆ clone()

virtual LuceneObjectPtr Lucene::FuzzyQuery::clone | ( | const LuceneObjectPtr & | other = LuceneObjectPtr() | ) |

virtual

Returns a clone of this query.

Reimplemented from Lucene::MultiTermQuery.

## ◆ ConstructQuery()

void Lucene::FuzzyQuery::ConstructQuery | ( | const TermPtr & | term,
|  | double | minimumSimilarity,
|  | int32_t | prefixLength )

protected

References minimumSimilarity, prefixLength, and term.

## ◆ defaultMinSimilarity()

double Lucene::FuzzyQuery::defaultMinSimilarity | ( |  | ) |

static

## ◆ equals()

virtual bool Lucene::FuzzyQuery::equals | ( | const LuceneObjectPtr & | other | ) |

virtual

Return whether two objects are equal.

Reimplemented from Lucene::MultiTermQuery.

## ◆ getClassName()

virtual String Lucene::FuzzyQuery::getClassName | ( |  | ) |

inline virtual

Reimplemented from Lucene::MultiTermQuery.

## ◆ getEnum()

virtual FilteredTermEnumPtr Lucene::FuzzyQuery::getEnum | ( | const IndexReaderPtr & | reader | ) |

protected virtual

Construct the enumeration to be used, expanding the pattern term.

Implements Lucene::MultiTermQuery.

## ◆ getMinSimilarity()

double Lucene::FuzzyQuery::getMinSimilarity | ( |  | ) |

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

Returns
  float value between 0.0 and 1.0

## ◆ getPrefixLength()

int32_t Lucene::FuzzyQuery::getPrefixLength | ( |  | ) |

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.

## ◆ getTerm()

TermPtr Lucene::FuzzyQuery::getTerm | ( |  | ) |

Returns the pattern term.

## ◆ hashCode()

virtual int32_t Lucene::FuzzyQuery::hashCode | ( |  | ) |

virtual

Return hash code for this object.

Reimplemented from Lucene::MultiTermQuery.

## ◆ rewrite()

virtual QueryPtr Lucene::FuzzyQuery::rewrite | ( | const IndexReaderPtr & | reader | ) |

virtual

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::MultiTermQuery.

## ◆ setRewriteMethod()

virtual void Lucene::FuzzyQuery::setRewriteMethod | ( | const RewriteMethodPtr & | method | ) |

virtual

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 `RewriteMethod`.

Reimplemented from Lucene::MultiTermQuery.

## ◆ shared_from_this()

boost::shared_ptr< FuzzyQuery > Lucene::FuzzyQuery::shared_from_this | ( |  | ) |

inline

## ◆ toString()

virtual String Lucene::FuzzyQuery::toString | ( | const 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 (eg. span queries) don't have a representation that can be parsed by QueryParser.

Reimplemented from Lucene::Query.

## Field Documentation

## ◆ defaultPrefixLength

const int32_t Lucene::FuzzyQuery::defaultPrefixLength

static

## ◆ minimumSimilarity

double Lucene::FuzzyQuery::minimumSimilarity

protected

Referenced by ConstructQuery(), FuzzyQuery(), and FuzzyQuery().

## ◆ prefixLength

int32_t Lucene::FuzzyQuery::prefixLength

protected

Referenced by ConstructQuery(), and FuzzyQuery().

## ◆ term

TermPtr Lucene::FuzzyQuery::term

protected

Referenced by ConstructQuery(), FuzzyQuery(), FuzzyQuery(), and FuzzyQuery().

## ◆ termLongEnough

bool Lucene::FuzzyQuery::termLongEnough

protected

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

- FuzzyQuery.h

clucene.sourceforge.net