1 package org.apache.lucene.queryParser.standard.config;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 import java.util.LinkedHashMap;
23 import org.apache.lucene.queryParser.core.config.AbstractQueryConfig;
24 import org.apache.lucene.queryParser.core.config.ConfigAttribute;
25 import org.apache.lucene.queryParser.core.config.FieldConfig;
26 import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
27 import org.apache.lucene.queryParser.standard.processors.MultiFieldQueryNodeProcessor;
28 import org.apache.lucene.util.AttributeImpl;
31 * This attribute is used by {@link MultiFieldQueryNodeProcessor} processor and
32 * it should be defined in a {@link FieldConfig}. This processor uses this
33 * attribute to define which boost a specific field should have when none is
34 * defined to it. <br/>
37 * @see org.apache.lucene.queryParser.standard.config.BoostAttribute
43 public class FieldBoostMapAttributeImpl extends AttributeImpl
44 implements FieldBoostMapAttribute, ConfigAttribute {
46 private static final long serialVersionUID = -2104763012523049527L;
48 private AbstractQueryConfig config;
50 { enableBackwards = false; }
52 public FieldBoostMapAttributeImpl() {
56 public void setFieldBoostMap(Map<String, Float> boosts) {
57 config.set(ConfigurationKeys.FIELD_BOOST_MAP, boosts);
60 public Map<String, Float> getFieldBoostMap() {
61 return config.get(ConfigurationKeys.FIELD_BOOST_MAP);
66 throw new UnsupportedOperationException();
70 public void copyTo(AttributeImpl target) {
71 throw new UnsupportedOperationException();
75 public boolean equals(Object other) {
77 if (other instanceof FieldBoostMapAttributeImpl
78 && ((FieldBoostMapAttributeImpl) other).getFieldBoostMap().equals(getFieldBoostMap()) ) {
89 public int hashCode() {
91 Map<String, Float> boostMap = getFieldBoostMap();
93 return boostMap.hashCode() * prime;
95 return Float.valueOf(prime).hashCode();
99 public String toString() {
100 return "<fieldBoostMapAttribute map=" + getFieldBoostMap() + "/>";
103 public void setQueryConfigHandler(AbstractQueryConfig config) {
104 this.config = config;
106 if (!config.has(ConfigurationKeys.FIELD_BOOST_MAP)) {
107 setFieldBoostMap(new LinkedHashMap<String, Float>());