FileDocCategorySizeDatePackage
MoreLikeThisQuery.javaAPI DocApache Lucene 1.93118Mon Feb 27 11:12:30 GMT 2006org.apache.lucene.search.similar

MoreLikeThisQuery

public class MoreLikeThisQuery extends Query
A simple wrapper for MoreLikeThis for use in scenarios where a Query object is required eg in custom QueryParser extensions. At query.rewrite() time the reader is used to construct the actual MoreLikeThis object and obtain the real Query object.
author
maharwood

Fields Summary
private String
likeText
private String[]
moreLikeFields
private Analyzer
analyzer
float
percentTermsToMatch
int
minTermFrequency
int
maxQueryTerms
Constructors Summary
public MoreLikeThisQuery(String likeText, String[] moreLikeFields, Analyzer analyzer)

param
docId
param
moreLikeFields

    
    
             
          
    
        this.likeText=likeText;
        this.moreLikeFields=moreLikeFields;
        this.analyzer=analyzer;
    
Methods Summary
public org.apache.lucene.analysis.AnalyzergetAnalyzer()

		return analyzer;
	
public java.lang.StringgetLikeText()

		return likeText;
	
public intgetMaxQueryTerms()

		return maxQueryTerms;
	
public intgetMinTermFrequency()

		return minTermFrequency;
	
public java.lang.String[]getMoreLikeFields()

		return moreLikeFields;
	
public floatgetPercentTermsToMatch()

		return percentTermsToMatch;
	
public org.apache.lucene.search.Queryrewrite(org.apache.lucene.index.IndexReader reader)

        MoreLikeThis mlt=new MoreLikeThis(reader);
        
        mlt.setFieldNames(moreLikeFields);
        mlt.setAnalyzer(analyzer);
        mlt.setMinTermFreq(minTermFrequency);
        mlt.setMaxQueryTerms(maxQueryTerms);
        BooleanQuery bq= (BooleanQuery) mlt.like(new ByteArrayInputStream(likeText.getBytes()));        
        BooleanClause[] clauses = bq.getClauses();
        //make at least half the terms match
        bq.setMinimumNumberShouldMatch((int)(clauses.length*percentTermsToMatch));
        return bq;
    
public voidsetAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)

		this.analyzer = analyzer;
	
public voidsetLikeText(java.lang.String likeText)

		this.likeText = likeText;
	
public voidsetMaxQueryTerms(int maxQueryTerms)

		this.maxQueryTerms = maxQueryTerms;
	
public voidsetMinTermFrequency(int minTermFrequency)

		this.minTermFrequency = minTermFrequency;
	
public voidsetMoreLikeFields(java.lang.String[] moreLikeFields)

		this.moreLikeFields = moreLikeFields;
	
public voidsetPercentTermsToMatch(float percentTermsToMatch)

		this.percentTermsToMatch = percentTermsToMatch;
	
public java.lang.StringtoString(java.lang.String field)

       
        return "like:"+likeText;