Class SlowFuzzyQuery

  • Deprecated. 
    Use FuzzyQuery instead.

    public class SlowFuzzyQuery
    extends MultiTermQuery
    Implements the classic fuzzy search query. The similarity measurement is based on the Levenshtein (edit distance) algorithm.

    Note that, unlike FuzzyQuery, this query will silently allow for a (possibly huge) number of edit distances in comparisons, and may be extremely slow (comparing every term in the index).

    • Constructor Detail

      • SlowFuzzyQuery

        public SlowFuzzyQuery(Term term,
                              float minimumSimilarity,
                              int prefixLength,
                              int maxExpansions)
        Create a new SlowFuzzyQuery 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.
        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

        Alternatively, if minimumSimilarity is >= 1f, it is interpreted as a pure Levenshtein edit distance. For example, a value of 2f will match all terms within an edit distance of 2 from the query term. Edit distances specified in this way may not be fractional.

        prefixLength - length of common (non-fuzzy) prefix
        maxExpansions - the maximum number of terms to match. If this number is greater than BooleanQuery.getMaxClauseCount() when the query is rewritten, then the maxClauseCount will be used instead.
        IllegalArgumentException - if minimumSimilarity is >= 1 or < 0 or if prefixLength < 0
    • Method Detail

      • getMinSimilarity

        public float getMinSimilarity()
        Returns the minimum similarity that is required for this query to match.
        float value between 0.0 and 1.0
      • getPrefixLength

        public int 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

        public Term getTerm()
        Returns the pattern term.
      • toString

        public String toString(String field)
        Description copied from class: Query
        Prints a query to a string, with field assumed to be the default field and omitted.
        Specified by:
        toString in class Query
      • equals

        public boolean equals(Object obj)
        Description copied from class: Query
        Override and implement query instance equivalence properly in a subclass. This is required so that QueryCache works properly. Typically a query will be equal to another only if it's an instance of the same class and its document-filtering properties are identical that other instance. Utility methods are provided for certain repetitive code.
        equals in class MultiTermQuery
        See Also:
        Query.sameClassAs(Object), Query.classHash()