1 package org.apache.lucene.queryParser.surround.query;
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 import org.apache.lucene.search.BooleanClause;
20 import org.apache.lucene.search.BooleanQuery;
21 import org.apache.lucene.search.Query;
23 public abstract class SrndQuery implements Cloneable {
26 private float weight = (float) 1.0;
27 private boolean weighted = false;
29 public void setWeight(float w) {
30 weight = w; /* as parsed from the query text */
33 public boolean isWeighted() {return weighted;}
34 public float getWeight() { return weight; }
35 public String getWeightString() {return Float.toString(getWeight());}
37 public String getWeightOperator() {return "^";}
39 protected void weightToString(StringBuilder r) { /* append the weight part of a query */
41 r.append(getWeightOperator());
42 r.append(getWeightString());
46 public Query makeLuceneQueryField(String fieldName, BasicQueryFactory qf){
47 Query q = makeLuceneQueryFieldNoBoost(fieldName, qf);
49 q.setBoost(getWeight() * q.getBoost()); /* weight may be at any level in a SrndQuery */
54 public abstract Query makeLuceneQueryFieldNoBoost(String fieldName, BasicQueryFactory qf);
57 public abstract String toString();
59 public boolean isFieldsSubQueryAcceptable() {return true;}
62 public Object clone() {
65 } catch (CloneNotSupportedException cns) {
70 /* An empty Lucene query */
71 public final static Query theEmptyLcnQuery = new BooleanQuery() { /* no changes allowed */
73 public void setBoost(float boost) {
74 throw new UnsupportedOperationException();
77 public void add(BooleanClause clause) {
78 throw new UnsupportedOperationException();
81 public void add(Query query, BooleanClause.Occur occur) {
82 throw new UnsupportedOperationException();