org.apache.lucene.search.similar

## Class SimilarityQueries

- java.lang.Object
- - org.apache.lucene.search.similar.SimilarityQueries

-     public final class SimilarityQueries
      extends java.lang.Object

  Simple similarity measures.
  See Also:
    `MoreLikeThis`

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static org.apache.lucene.search.Query` | `formSimilarQuery(java.lang.String body, org.apache.lucene.analysis.Analyzer a, java.lang.String field, java.util.Set stop)` Simple similarity query generators.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### formSimilarQuery

          public static org.apache.lucene.search.Query formSimilarQuery(java.lang.String body,
                                                                        org.apache.lucene.analysis.Analyzer a,
                                                                        java.lang.String field,
                                                                        java.util.Set stop)
                                                                 throws java.io.IOException

      Simple similarity query generators. Takes every unique word and forms a boolean query where all words are optional. After you get this you'll use to to query your `IndexSearcher` for similar docs. The only caveat is the first hit returned should be your source document - you'll need to then ignore that.

      So, if you have a code fragment like this:
      `Query q = formSimilaryQuery( "I use Lucene to search fast. Fast searchers are good", new StandardAnalyzer(), "contents", null);`

      The query returned, in string form, will be `'(i use lucene to search fast searchers are good')`.

      The philosophy behind this method is "two documents are similar if they share lots of words". Note that behind the scenes, Lucene's scoring algorithm will tend to give two documents a higher similarity score if the share more uncommon words.

      This method is fail-safe in that if a long 'body' is passed in and `BooleanQuery.add()` (used internally) throws `BooleanQuery.TooManyClauses`, the query as it is will be returned.

      Parameters:
        `body` - the body of the document you want to find similar documents to
        `a` - the analyzer to use to parse the body
        `field` - the field you want to search on, probably something like "contents" or "body"
        `stop` - optional set of stop words to ignore
      Returns:
        a query with all unique words in 'body'
      Throws:
        `java.io.IOException` - this can't happen...

Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.