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

« back to all changes in this revision

Viewing changes to solr/core/src/java/org/apache/solr/search/function/DualFloatFunction.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
 
/**
2
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 
 * contributor license agreements.  See the NOTICE file distributed with
4
 
 * this work for additional information regarding copyright ownership.
5
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 
 * (the "License"); you may not use this file except in compliance with
7
 
 * the License.  You may obtain a copy of the License at
8
 
 *
9
 
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 
 *
11
 
 * Unless required by applicable law or agreed to in writing, software
12
 
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 
 * See the License for the specific language governing permissions and
15
 
 * limitations under the License.
16
 
 */
17
 
 
18
 
package org.apache.solr.search.function;
19
 
 
20
 
import org.apache.lucene.index.IndexReader;
21
 
import org.apache.lucene.search.Searcher;
22
 
 
23
 
import java.io.IOException;
24
 
import java.util.Map;
25
 
 
26
 
public abstract class DualFloatFunction extends ValueSource {
27
 
  protected final ValueSource a;
28
 
  protected final ValueSource b;
29
 
 
30
 
 /**
31
 
   * @param   a  the base.
32
 
   * @param   b  the exponent.
33
 
   */
34
 
  public DualFloatFunction(ValueSource a, ValueSource b) {
35
 
    this.a = a;
36
 
    this.b = b;
37
 
  }
38
 
 
39
 
  protected abstract String name();
40
 
  protected abstract float func(int doc, DocValues aVals, DocValues bVals);
41
 
 
42
 
  @Override
43
 
  public String description() {
44
 
    return name() + "(" + a.description() + "," + b.description() + ")";
45
 
  }
46
 
 
47
 
  @Override
48
 
  public DocValues getValues(Map context, IndexReader reader) throws IOException {
49
 
    final DocValues aVals =  a.getValues(context, reader);
50
 
    final DocValues bVals =  b.getValues(context, reader);
51
 
    return new DocValues() {
52
 
      @Override
53
 
      public float floatVal(int doc) {
54
 
        return func(doc, aVals, bVals);
55
 
      }
56
 
      @Override
57
 
      public int intVal(int doc) {
58
 
        return (int)floatVal(doc);
59
 
      }
60
 
      @Override
61
 
      public long longVal(int doc) {
62
 
        return (long)floatVal(doc);
63
 
      }
64
 
      @Override
65
 
      public double doubleVal(int doc) {
66
 
        return floatVal(doc);
67
 
      }
68
 
      @Override
69
 
      public String strVal(int doc) {
70
 
        return Float.toString(floatVal(doc));
71
 
      }
72
 
      @Override
73
 
      public String toString(int doc) {
74
 
        return name() + '(' + aVals.toString(doc) + ',' + bVals.toString(doc) + ')';
75
 
      }
76
 
    };
77
 
  }
78
 
 
79
 
  @Override
80
 
  public void createWeight(Map context, Searcher searcher) throws IOException {
81
 
    a.createWeight(context,searcher);
82
 
    b.createWeight(context,searcher);
83
 
  }
84
 
 
85
 
  @Override
86
 
  public int hashCode() {
87
 
    int h = a.hashCode();
88
 
    h ^= (h << 13) | (h >>> 20);
89
 
    h += b.hashCode();
90
 
    h ^= (h << 23) | (h >>> 10);
91
 
    h += name().hashCode();
92
 
    return h;
93
 
  }
94
 
 
95
 
  @Override
96
 
  public boolean equals(Object o) {
97
 
    if (this.getClass() != o.getClass()) return false;
98
 
    DualFloatFunction other = (DualFloatFunction)o;
99
 
    return this.a.equals(other.a)
100
 
        && this.b.equals(other.b);
101
 
  }
102
 
}