add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / queryparser / src / java / org / apache / lucene / queryParser / surround / query / SrndQuery.java
1 package org.apache.lucene.queryParser.surround.query;
2 /**
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements.  See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License.  You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 import org.apache.lucene.search.BooleanClause;
20 import org.apache.lucene.search.BooleanQuery;
21 import org.apache.lucene.search.Query;
22
23 public abstract class SrndQuery implements Cloneable {
24   public SrndQuery() {}
25   
26   private float weight = (float) 1.0;
27   private boolean weighted = false;
28
29   public void setWeight(float w) {
30     weight = w; /* as parsed from the query text */
31     weighted = true;
32   } 
33   public boolean isWeighted() {return weighted;}
34   public float getWeight() { return weight; }
35   public String getWeightString() {return Float.toString(getWeight());}
36
37   public String getWeightOperator() {return "^";}
38
39   protected void weightToString(StringBuilder r) { /* append the weight part of a query */
40     if (isWeighted()) {
41       r.append(getWeightOperator());
42       r.append(getWeightString());
43     }
44   }
45   
46   public Query makeLuceneQueryField(String fieldName, BasicQueryFactory qf){
47     Query q = makeLuceneQueryFieldNoBoost(fieldName, qf);
48     if (isWeighted()) {
49       q.setBoost(getWeight() * q.getBoost()); /* weight may be at any level in a SrndQuery */
50     }
51     return q;
52   }
53   
54   public abstract Query makeLuceneQueryFieldNoBoost(String fieldName, BasicQueryFactory qf);
55   
56   @Override
57   public abstract String toString();
58   
59   public boolean isFieldsSubQueryAcceptable() {return true;}
60     
61   @Override
62   public Object clone() {
63     try {
64       return super.clone();
65     } catch (CloneNotSupportedException cns) {
66       throw new Error(cns);
67     }
68   }
69   
70 /* An empty Lucene query */
71   public final static Query theEmptyLcnQuery = new BooleanQuery() { /* no changes allowed */
72     @Override
73     public void setBoost(float boost) {
74       throw new UnsupportedOperationException();
75     }
76     @Override
77     public void add(BooleanClause clause) {
78       throw new UnsupportedOperationException();
79     }
80     @Override
81     public void add(Query query, BooleanClause.Occur occur) {
82       throw new UnsupportedOperationException();
83     }
84   };
85 }
86