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

BooleanClause

public class BooleanClause extends Object implements Serializable
A clause in a BooleanQuery.

Fields Summary
public Query
query
The query whose matching documents are combined by the boolean query.
public boolean
required
If true, documents documents which do not match this sub-query will not match the boolean query.
public boolean
prohibited
If true, documents documents which do match this sub-query will not match the boolean query.
private Occur
occur
Constructors Summary
public BooleanClause(Query q, boolean r, boolean p)
Constructs a BooleanClause with query q, required r and prohibited p.

deprecated
use BooleanClause(Query, Occur) instead
  • For BooleanClause(query, true, false) use BooleanClause(query, BooleanClause.Occur.MUST)
  • For BooleanClause(query, false, false) use BooleanClause(query, BooleanClause.Occur.SHOULD)
  • For BooleanClause(query, false, true) use BooleanClause(query, BooleanClause.Occur.MUST_NOT)


                                                
         
    // TODO: remove for Lucene 2.0
    query = q;
    required = r;
    prohibited = p;
    if (required) {
      if (prohibited) {
        // prohibited && required doesn't make sense, but we want the old behaviour:
        occur = Occur.MUST_NOT;
      } else {
         occur = Occur.MUST;
      }
    } else {
      if (prohibited) {
         occur = Occur.MUST_NOT;
      } else {
         occur = Occur.SHOULD;
      }
    }
  
public BooleanClause(Query query, Occur occur)
Constructs a BooleanClause.

    this.query = query;
    this.occur = occur;
    setFields(occur);
  
Methods Summary
public booleanequals(java.lang.Object o)
Returns true iff o is equal to this.

    if (!(o instanceof BooleanClause))
      return false;
    BooleanClause other = (BooleanClause)o;
    return this.query.equals(other.query)
      && (this.required == other.required)
      && (this.prohibited == other.prohibited);
  
public org.apache.lucene.search.BooleanClause$OccurgetOccur()

    return occur;
  
public org.apache.lucene.search.QuerygetQuery()

    return query;
  
public inthashCode()
Returns a hash code value for this object.

    return query.hashCode() ^ (this.required?1:0) ^ (this.prohibited?2:0);
  
public booleanisProhibited()

    return prohibited;
  
public booleanisRequired()

    return required;
  
private voidsetFields(org.apache.lucene.search.BooleanClause$Occur occur)

    if (occur == Occur.MUST) {
      required = true;
      prohibited = false;
    } else if (occur == Occur.SHOULD) {
      required = false;
      prohibited = false;
    } else if (occur == Occur.MUST_NOT) {
      required = false;
      prohibited = true;
    } else {
      throw new IllegalArgumentException("Unknown operator " + occur);
    }
  
public voidsetOccur(org.apache.lucene.search.BooleanClause$Occur occur)

    this.occur = occur;
    setFields(occur);
  
public voidsetQuery(org.apache.lucene.search.Query query)

    this.query = query;
  
public java.lang.StringtoString()

    return occur.toString() + query.toString();