FileDocCategorySizeDatePackage
SpanRegexQuery.javaAPI DocApache Lucene 2.1.03937Wed Feb 14 10:46:32 GMT 2007org.apache.lucene.search.regex

SpanRegexQuery

public class SpanRegexQuery extends SpanQuery implements RegexQueryCapable
A SpanQuery version of {@link RegexQuery} allowing regular expression queries to be nested within other SpanQuery subclasses.

Fields Summary
private RegexCapabilities
regexImpl
private Term
term
Constructors Summary
public SpanRegexQuery(Term term)


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

    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    final SpanRegexQuery that = (SpanRegexQuery) o;

    if (!regexImpl.equals(that.regexImpl)) return false;
    if (!term.equals(that.term)) return false;

    return true;
  
public java.lang.StringgetField()

    return term.field();
  
public RegexCapabilitiesgetRegexImplementation()

    return regexImpl;
  
public org.apache.lucene.search.spans.SpansgetSpans(org.apache.lucene.index.IndexReader reader)

    throw new UnsupportedOperationException("Query should have been rewritten");
  
public org.apache.lucene.index.TermgetTerm()

 return term; 
public java.util.CollectiongetTerms()

    Collection terms = new ArrayList();
    terms.add(term);
    return terms;
  
public inthashCode()

    int result;
    result = regexImpl.hashCode();
    result = 29 * result + term.hashCode();
    return result;
  
public org.apache.lucene.search.Queryrewrite(org.apache.lucene.index.IndexReader reader)

    RegexQuery orig = new RegexQuery(term);
    orig.setRegexImplementation(regexImpl);

    // RegexQuery (via MultiTermQuery).rewrite always returns a BooleanQuery
    BooleanQuery bq = (BooleanQuery) orig.rewrite(reader);

    BooleanClause[] clauses = bq.getClauses();
    SpanQuery[] sqs = new SpanQuery[clauses.length];
    for (int i = 0; i < clauses.length; i++) {
      BooleanClause clause = clauses[i];

      // Clauses from RegexQuery.rewrite are always TermQuery's
      TermQuery tq = (TermQuery) clause.getQuery();

      sqs[i] = new SpanTermQuery(tq.getTerm());
      sqs[i].setBoost(tq.getBoost());
    }

    SpanOrQuery query = new SpanOrQuery(sqs);
    query.setBoost(orig.getBoost());

    return query;
  
public voidsetRegexImplementation(RegexCapabilities impl)

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

    StringBuffer buffer = new StringBuffer();
    buffer.append("spanRegexQuery(");
    buffer.append(term);
    buffer.append(")");
    buffer.append(ToStringUtils.boost(getBoost()));
    return buffer.toString();