org.elasticsearch.index.query.xcontent
Class MoreLikeThisQueryBuilder

java.lang.Object
  extended by org.elasticsearch.index.query.xcontent.BaseQueryBuilder
      extended by org.elasticsearch.index.query.xcontent.MoreLikeThisQueryBuilder
All Implemented Interfaces:
ToXContent, QueryBuilder, XContentQueryBuilder

public class MoreLikeThisQueryBuilder
extends BaseQueryBuilder

A more like this query that finds documents that are "like" the provided likeText(String) which is checked against the fields the query is constructed with.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.MapParams, ToXContent.Params
 
Field Summary
 
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
 
Constructor Summary
MoreLikeThisQueryBuilder()
          Constructs a new more like this query which uses the "_all" field.
MoreLikeThisQueryBuilder(java.lang.String... fields)
          Sets the field names that will be used when generating the 'More Like This' query.
 
Method Summary
 MoreLikeThisQueryBuilder boost(float boost)
           
 MoreLikeThisQueryBuilder boostTerms(float boostTerms)
          Sets the boost factor to use when boosting terms.
protected  void doXContent(XContentBuilder builder, ToXContent.Params params)
           
 MoreLikeThisQueryBuilder likeText(java.lang.String likeText)
          The text to use in order to find documents that are "like" this.
 MoreLikeThisQueryBuilder maxDocFreq(int maxDocFreq)
          Set the maximum frequency in which words may still appear.
 MoreLikeThisQueryBuilder maxQueryTerms(int maxQueryTerms)
          Sets the maximum number of query terms that will be included in any generated query.
 MoreLikeThisQueryBuilder maxWordLen(int maxWordLen)
          Sets the maximum word length above which words will be ignored.
 MoreLikeThisQueryBuilder minDocFreq(int minDocFreq)
          Sets the frequency at which words will be ignored which do not occur in at least this many docs.
 MoreLikeThisQueryBuilder minTermFreq(int minTermFreq)
          The frequency below which terms will be ignored in the source doc.
 MoreLikeThisQueryBuilder minWordLen(int minWordLen)
          Sets the minimum word length below which words will be ignored.
 MoreLikeThisQueryBuilder percentTermsToMatch(float percentTermsToMatch)
          The percentage of terms to match.
 MoreLikeThisQueryBuilder stopWords(java.lang.String... stopWords)
          Set the set of stopwords.
 
Methods inherited from class org.elasticsearch.index.query.xcontent.BaseQueryBuilder
buildAsBytes, buildAsBytes, buildAsUnsafeBytes, buildAsUnsafeBytes, toXContent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MoreLikeThisQueryBuilder

public MoreLikeThisQueryBuilder()
Constructs a new more like this query which uses the "_all" field.


MoreLikeThisQueryBuilder

public MoreLikeThisQueryBuilder(java.lang.String... fields)
Sets the field names that will be used when generating the 'More Like This' query.

Parameters:
fields - the field names that will be used when generating the 'More Like This' query.
Method Detail

likeText

public MoreLikeThisQueryBuilder likeText(java.lang.String likeText)
The text to use in order to find documents that are "like" this.


percentTermsToMatch

public MoreLikeThisQueryBuilder percentTermsToMatch(float percentTermsToMatch)
The percentage of terms to match. Defaults to 0.3.


minTermFreq

public MoreLikeThisQueryBuilder minTermFreq(int minTermFreq)
The frequency below which terms will be ignored in the source doc. The default frequency is 2.


maxQueryTerms

public MoreLikeThisQueryBuilder maxQueryTerms(int maxQueryTerms)
Sets the maximum number of query terms that will be included in any generated query. Defaults to 25.


stopWords

public MoreLikeThisQueryBuilder stopWords(java.lang.String... stopWords)
Set the set of stopwords.

Any word in this set is considered "uninteresting" and ignored. Even if your Analyzer allows stopwords, you might want to tell the MoreLikeThis code to ignore them, as for the purposes of document similarity it seems reasonable to assume that "a stop word is never interesting".


minDocFreq

public MoreLikeThisQueryBuilder minDocFreq(int minDocFreq)
Sets the frequency at which words will be ignored which do not occur in at least this many docs. Defaults to 5.


maxDocFreq

public MoreLikeThisQueryBuilder maxDocFreq(int maxDocFreq)
Set the maximum frequency in which words may still appear. Words that appear in more than this many docs will be ignored. Defaults to unbounded.


minWordLen

public MoreLikeThisQueryBuilder minWordLen(int minWordLen)
Sets the minimum word length below which words will be ignored. Defaults to 0.


maxWordLen

public MoreLikeThisQueryBuilder maxWordLen(int maxWordLen)
Sets the maximum word length above which words will be ignored. Defaults to unbounded (0).


boostTerms

public MoreLikeThisQueryBuilder boostTerms(float boostTerms)
Sets the boost factor to use when boosting terms. Defaults to 1.


boost

public MoreLikeThisQueryBuilder boost(float boost)

doXContent

protected void doXContent(XContentBuilder builder,
                          ToXContent.Params params)
                   throws java.io.IOException
Specified by:
doXContent in class BaseQueryBuilder
Throws:
java.io.IOException