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.FieldCache;
21
import org.apache.lucene.index.IndexReader;
23
import java.io.IOException;
25
/** Internal class, subject to change.
26
* Serves as base class for DocValues based on StringIndex
28
public abstract class StringIndexDocValues extends DocValues {
29
protected final FieldCache.StringIndex index;
30
protected final int[] order;
31
protected final String[] lookup;
32
protected final ValueSource vs;
34
public StringIndexDocValues(ValueSource vs, IndexReader reader, String field) throws IOException {
36
index = FieldCache.DEFAULT.getStringIndex(reader, field);
37
} catch (RuntimeException e) {
38
throw new StringIndexException(field, e);
41
lookup = index.lookup;
45
protected abstract String toTerm(String readableValue);
48
public ValueSourceScorer getRangeScorer(IndexReader reader, String lowerVal, String upperVal, boolean includeLower, boolean includeUpper) {
49
// TODO: are lowerVal and upperVal in indexed form or not?
50
lowerVal = lowerVal == null ? null : toTerm(lowerVal);
51
upperVal = upperVal == null ? null : toTerm(upperVal);
53
int lower = Integer.MIN_VALUE;
54
if (lowerVal != null) {
55
lower = index.binarySearchLookup(lowerVal);
58
} else if (!includeLower) {
63
int upper = Integer.MAX_VALUE;
64
if (upperVal != null) {
65
upper = index.binarySearchLookup(upperVal);
68
} else if (!includeUpper) {
76
return new ValueSourceScorer(reader, this) {
78
public boolean matchesValue(int doc) {
80
return ord >= ll && ord <= uu;
86
public String toString(int doc) {
87
return vs.description() + '=' + strVal(doc);
90
public static final class StringIndexException extends RuntimeException {
91
public StringIndexException(final String fieldName,
92
final RuntimeException cause) {
93
super("Can't initialize StringIndex to generate (function) " +
94
"DocValues for field: " + fieldName, cause);