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
9
* http://www.apache.org/licenses/LICENSE-2.0
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.
18
package org.apache.solr.search.function;
20
import org.apache.lucene.index.IndexReader;
21
import org.apache.lucene.search.Searcher;
23
import java.io.IOException;
26
public abstract class DualFloatFunction extends ValueSource {
27
protected final ValueSource a;
28
protected final ValueSource b;
32
* @param b the exponent.
34
public DualFloatFunction(ValueSource a, ValueSource b) {
39
protected abstract String name();
40
protected abstract float func(int doc, DocValues aVals, DocValues bVals);
43
public String description() {
44
return name() + "(" + a.description() + "," + b.description() + ")";
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() {
53
public float floatVal(int doc) {
54
return func(doc, aVals, bVals);
57
public int intVal(int doc) {
58
return (int)floatVal(doc);
61
public long longVal(int doc) {
62
return (long)floatVal(doc);
65
public double doubleVal(int doc) {
69
public String strVal(int doc) {
70
return Float.toString(floatVal(doc));
73
public String toString(int doc) {
74
return name() + '(' + aVals.toString(doc) + ',' + bVals.toString(doc) + ')';
80
public void createWeight(Map context, Searcher searcher) throws IOException {
81
a.createWeight(context,searcher);
82
b.createWeight(context,searcher);
86
public int hashCode() {
88
h ^= (h << 13) | (h >>> 20);
90
h ^= (h << 23) | (h >>> 10);
91
h += name().hashCode();
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);