~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to lucene/contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/config/FieldBoostMapAttributeImpl.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 java.util.LinkedHashMap;
21
 
import java.util.Map;
22
 
 
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;
29
 
 
30
 
/**
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/>
35
 
 * <br/>
36
 
 * 
37
 
 * @see org.apache.lucene.queryParser.standard.config.BoostAttribute
38
 
 * 
39
 
 * @deprecated
40
 
 * 
41
 
 */
42
 
@Deprecated
43
 
public class FieldBoostMapAttributeImpl extends AttributeImpl 
44
 
                                implements FieldBoostMapAttribute, ConfigAttribute {
45
 
 
46
 
  private static final long serialVersionUID = -2104763012523049527L;
47
 
  
48
 
  private AbstractQueryConfig config;
49
 
 
50
 
  { enableBackwards = false; }
51
 
  
52
 
  public FieldBoostMapAttributeImpl() {
53
 
    // empty constructor
54
 
  }
55
 
 
56
 
  public void setFieldBoostMap(Map<String, Float> boosts) {
57
 
    config.set(ConfigurationKeys.FIELD_BOOST_MAP, boosts);
58
 
  }
59
 
  
60
 
  public Map<String, Float> getFieldBoostMap() {
61
 
    return config.get(ConfigurationKeys.FIELD_BOOST_MAP);
62
 
  }
63
 
 
64
 
  @Override
65
 
  public void clear() {
66
 
    throw new UnsupportedOperationException();
67
 
  }
68
 
 
69
 
  @Override
70
 
  public void copyTo(AttributeImpl target) {
71
 
    throw new UnsupportedOperationException();
72
 
  }
73
 
 
74
 
  @Override
75
 
  public boolean equals(Object other) {
76
 
 
77
 
    if (other instanceof FieldBoostMapAttributeImpl
78
 
        && ((FieldBoostMapAttributeImpl) other).getFieldBoostMap().equals(getFieldBoostMap()) ) {
79
 
 
80
 
      return true;
81
 
 
82
 
    }
83
 
 
84
 
    return false;
85
 
 
86
 
  }
87
 
 
88
 
  @Override
89
 
  public int hashCode() {
90
 
    final int prime = 97;
91
 
    Map<String, Float> boostMap = getFieldBoostMap();
92
 
    if (boostMap != null) 
93
 
      return boostMap.hashCode() * prime;
94
 
    else 
95
 
      return Float.valueOf(prime).hashCode();
96
 
  }
97
 
 
98
 
  @Override
99
 
  public String toString() {
100
 
    return "<fieldBoostMapAttribute map=" + getFieldBoostMap() + "/>";
101
 
  }
102
 
  
103
 
  public void setQueryConfigHandler(AbstractQueryConfig config) {
104
 
    this.config = config;
105
 
    
106
 
    if (!config.has(ConfigurationKeys.FIELD_BOOST_MAP)) {
107
 
      setFieldBoostMap(new LinkedHashMap<String, Float>());
108
 
    }
109
 
    
110
 
  }
111
 
 
112
 
}