add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / queryparser / src / java / org / apache / lucene / queryParser / standard / config / BoostAttributeImpl.java
1 package org.apache.lucene.queryParser.standard.config;
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 import org.apache.lucene.queryParser.core.config.AbstractQueryConfig;
21 import org.apache.lucene.queryParser.core.config.ConfigAttribute;
22 import org.apache.lucene.queryParser.core.config.FieldConfig;
23 import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
24 import org.apache.lucene.queryParser.standard.processors.MultiFieldQueryNodeProcessor;
25 import org.apache.lucene.util.AttributeImpl;
26
27 /**
28  * This attribute is used by {@link MultiFieldQueryNodeProcessor} processor and
29  * it should be defined in a {@link FieldConfig}. This processor uses this
30  * attribute to define which boost a specific field should have when none is
31  * defined to it. <br/>
32  * <br/>
33  * 
34  * @see org.apache.lucene.queryParser.standard.config.BoostAttribute
35  * 
36  * @deprecated
37  * 
38  */
39 @Deprecated
40 public class BoostAttributeImpl extends AttributeImpl 
41                                 implements BoostAttribute, ConfigAttribute {
42
43   private static final long serialVersionUID = -2104763012523049527L;
44   
45   private AbstractQueryConfig config;
46
47   { enableBackwards = false; }
48   
49   public BoostAttributeImpl() {
50     // empty constructor
51   }
52
53   public void setBoost(float boost) {
54     config.set(ConfigurationKeys.BOOST, boost);
55   }
56
57   public float getBoost() {
58     return config.get(ConfigurationKeys.BOOST, 1.0f);
59   }
60
61   @Override
62   public void clear() {
63     throw new UnsupportedOperationException();
64   }
65
66   @Override
67   public void copyTo(AttributeImpl target) {
68     throw new UnsupportedOperationException();
69   }
70
71   @Override
72   public boolean equals(Object other) {
73
74     if (other instanceof BoostAttributeImpl
75         && ((BoostAttributeImpl) other).getBoost() == getBoost()) {
76
77       return true;
78
79     }
80
81     return false;
82
83   }
84
85   @Override
86   public int hashCode() {
87     return Float.valueOf(getBoost()).hashCode();
88   }
89
90   @Override
91   public String toString() {
92     return "<boostAttribute boost=" + getBoost() + "/>";
93   }
94   
95   public void setQueryConfigHandler(AbstractQueryConfig config) {
96     this.config = config;
97     
98     if (!config.has(ConfigurationKeys.BOOST)) {
99       config.set(ConfigurationKeys.BOOST, 1.0f);
100     }
101     
102   }
103
104 }