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.search.*;
21
import org.apache.lucene.index.IndexReader;
24
* Represents field values as different types.
25
* Normally created via a {@link ValueSource} for a particular field and reader.
27
* @version $Id: DocValues.java 1140724 2011-06-28 17:00:20Z yonik $
30
// DocValues is distinct from ValueSource because
31
// there needs to be an object created at query evaluation time that
32
// is not referenced by the query itself because:
33
// - Query objects should be MT safe
34
// - For caching, Query objects are often used as keys... you don't
35
// want the Query carrying around big objects
36
public abstract class DocValues {
38
public byte byteVal(int doc) { throw new UnsupportedOperationException(); }
39
public short shortVal(int doc) { throw new UnsupportedOperationException(); }
41
public float floatVal(int doc) { throw new UnsupportedOperationException(); }
42
public int intVal(int doc) { throw new UnsupportedOperationException(); }
43
public long longVal(int doc) { throw new UnsupportedOperationException(); }
44
public double doubleVal(int doc) { throw new UnsupportedOperationException(); }
45
public String strVal(int doc) { throw new UnsupportedOperationException(); }
46
public abstract String toString(int doc);
48
//For Functions that can work with multiple values from the same document. This does not apply to all functions
49
public void byteVal(int doc, byte [] vals) { throw new UnsupportedOperationException(); }
50
public void shortVal(int doc, short [] vals) { throw new UnsupportedOperationException(); }
52
public void floatVal(int doc, float [] vals) { throw new UnsupportedOperationException(); }
53
public void intVal(int doc, int [] vals) { throw new UnsupportedOperationException(); }
54
public void longVal(int doc, long [] vals) { throw new UnsupportedOperationException(); }
55
public void doubleVal(int doc, double [] vals) { throw new UnsupportedOperationException(); }
56
public void strVal(int doc, String [] vals) { throw new UnsupportedOperationException(); }
58
public Explanation explain(int doc) {
59
return new Explanation(floatVal(doc), toString(doc));
62
public ValueSourceScorer getScorer(IndexReader reader) {
63
return new ValueSourceScorer(reader, this);
66
// A RangeValueSource can't easily be a ValueSource that takes another ValueSource
67
// because it needs different behavior depending on the type of fields. There is also
68
// a setup cost - parsing and normalizing params, and doing a binary search on the StringIndex.
69
// TODO: change "reader" to AtomicReaderContext
70
public ValueSourceScorer getRangeScorer(IndexReader reader, String lowerVal, String upperVal, boolean includeLower, boolean includeUpper) {
74
if (lowerVal == null) {
75
lower = Float.NEGATIVE_INFINITY;
77
lower = Float.parseFloat(lowerVal);
79
if (upperVal == null) {
80
upper = Float.POSITIVE_INFINITY;
82
upper = Float.parseFloat(upperVal);
85
final float l = lower;
86
final float u = upper;
88
if (includeLower && includeUpper) {
89
return new ValueSourceScorer(reader, this) {
91
public boolean matchesValue(int doc) {
92
float docVal = floatVal(doc);
93
return docVal >= l && docVal <= u;
97
else if (includeLower && !includeUpper) {
98
return new ValueSourceScorer(reader, this) {
100
public boolean matchesValue(int doc) {
101
float docVal = floatVal(doc);
102
return docVal >= l && docVal < u;
106
else if (!includeLower && includeUpper) {
107
return new ValueSourceScorer(reader, this) {
109
public boolean matchesValue(int doc) {
110
float docVal = floatVal(doc);
111
return docVal > l && docVal <= u;
116
return new ValueSourceScorer(reader, this) {
118
public boolean matchesValue(int doc) {
119
float docVal = floatVal(doc);
120
return docVal > l && docVal < u;