FileDocCategorySizeDatePackage
MultiTermQuery.javaAPI DocApache Lucene 1.93281Mon Feb 20 09:20:04 GMT 2006org.apache.lucene.search

MultiTermQuery

public abstract class MultiTermQuery extends Query
A {@link Query} that matches documents containing a subset of terms provided by a {@link FilteredTermEnum} enumeration.

MultiTermQuery is not designed to be used by itself.
The reason being that it is not intialized with a {@link FilteredTermEnum} enumeration. A {@link FilteredTermEnum} enumeration needs to be provided.

For example, {@link WildcardQuery} and {@link FuzzyQuery} extend MultiTermQuery to provide {@link WildcardTermEnum} and {@link FuzzyTermEnum}, respectively.

Fields Summary
private Term
term
Constructors Summary
public MultiTermQuery(Term term)
Constructs a query for terms matching term.

        this.term = term;
    
Methods Summary
public booleanequals(java.lang.Object o)

      if (this == o) return true;
      if (!(o instanceof MultiTermQuery)) return false;

      final MultiTermQuery multiTermQuery = (MultiTermQuery) o;

      if (!term.equals(multiTermQuery.term)) return false;

      return getBoost() == multiTermQuery.getBoost();
    
protected abstract org.apache.lucene.search.FilteredTermEnumgetEnum(org.apache.lucene.index.IndexReader reader)
Construct the enumeration to be used, expanding the pattern term.

public org.apache.lucene.index.TermgetTerm()
Returns the pattern term.

 return term; 
public inthashCode()

      return term.hashCode() + Float.floatToRawIntBits(getBoost());
    
public org.apache.lucene.search.Queryrewrite(org.apache.lucene.index.IndexReader reader)

      FilteredTermEnum enumerator = getEnum(reader);
      BooleanQuery query = new BooleanQuery(true);
      try {
        do {
          Term t = enumerator.term();
          if (t != null) {
            TermQuery tq = new TermQuery(t);      // found a match
            tq.setBoost(getBoost() * enumerator.difference()); // set the boost
            query.add(tq, BooleanClause.Occur.SHOULD);          // add to query
          }
        } while (enumerator.next());
      } finally {
        enumerator.close();
      }
      return query;
    
public java.lang.StringtoString(java.lang.String field)
Prints a user-readable version of this query.

        StringBuffer buffer = new StringBuffer();
        if (!term.field().equals(field)) {
            buffer.append(term.field());
            buffer.append(":");
        }
        buffer.append(term.text());
        buffer.append(ToStringUtils.boost(getBoost()));
        return buffer.toString();