add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / src / java / org / apache / lucene / search / BooleanClause.java
1 package org.apache.lucene.search;
2
3 /**
4  * Licensed to the Apache Software Foundation (ASF) under one or more
5  * contributor license agreements.  See the NOTICE file distributed with
6  * this work for additional information regarding copyright ownership.
7  * The ASF licenses this file to You under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with
9  * the License.  You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 /** A clause in a BooleanQuery. */
21 public class BooleanClause implements java.io.Serializable {
22   
23   /** Specifies how clauses are to occur in matching documents. */
24   public static enum Occur {
25
26     /** Use this operator for clauses that <i>must</i> appear in the matching documents. */
27     MUST     { @Override public String toString() { return "+"; } },
28
29     /** Use this operator for clauses that <i>should</i> appear in the 
30      * matching documents. For a BooleanQuery with no <code>MUST</code> 
31      * clauses one or more <code>SHOULD</code> clauses must match a document 
32      * for the BooleanQuery to match.
33      * @see BooleanQuery#setMinimumNumberShouldMatch
34      */
35     SHOULD   { @Override public String toString() { return "";  } },
36
37     /** Use this operator for clauses that <i>must not</i> appear in the matching documents.
38      * Note that it is not possible to search for queries that only consist
39      * of a <code>MUST_NOT</code> clause. */
40     MUST_NOT { @Override public String toString() { return "-"; } };
41
42   }
43
44   /** The query whose matching documents are combined by the boolean query.
45    */
46   private Query query;
47
48   private Occur occur;
49
50
51   /** Constructs a BooleanClause.
52   */ 
53   public BooleanClause(Query query, Occur occur) {
54     this.query = query;
55     this.occur = occur;
56     
57   }
58
59   public Occur getOccur() {
60     return occur;
61   }
62
63   public void setOccur(Occur occur) {
64     this.occur = occur;
65
66   }
67
68   public Query getQuery() {
69     return query;
70   }
71
72   public void setQuery(Query query) {
73     this.query = query;
74   }
75   
76   public boolean isProhibited() {
77     return Occur.MUST_NOT == occur;
78   }
79
80   public boolean isRequired() {
81     return Occur.MUST == occur;
82   }
83
84
85
86   /** Returns true if <code>o</code> is equal to this. */
87   @Override
88   public boolean equals(Object o) {
89     if (o == null || !(o instanceof BooleanClause))
90       return false;
91     BooleanClause other = (BooleanClause)o;
92     return this.query.equals(other.query)
93       && this.occur == other.occur;
94   }
95
96   /** Returns a hash code value for this object.*/
97   @Override
98   public int hashCode() {
99     return query.hashCode() ^ (Occur.MUST == occur?1:0) ^ (Occur.MUST_NOT == occur?2:0);
100   }
101
102
103   @Override
104   public String toString() {
105     return occur.toString() + query.toString();
106   }
107 }