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.FieldCache;
24
import java.io.IOException;
28
* Obtains float field values from the {@link org.apache.lucene.search.FieldCache}
29
* using <code>getFloats()</code>
30
* and makes those values available as other numeric types, casting as needed.
32
* @version $Id: FloatFieldSource.java 555343 2007-07-11 17:46:25Z hossman $
35
public class LongFieldSource extends FieldCacheSource {
36
protected FieldCache.LongParser parser;
38
public LongFieldSource(String field) {
42
public LongFieldSource(String field, FieldCache.LongParser parser) {
48
public String description() {
49
return "long(" + field + ')';
53
public long externalToLong(String extVal) {
54
return Long.parseLong(extVal);
58
public DocValues getValues(Map context, IndexReader reader) throws IOException {
59
final long[] arr = (parser == null) ?
60
cache.getLongs(reader, field) :
61
cache.getLongs(reader, field, parser);
62
return new DocValues() {
64
public float floatVal(int doc) {
65
return (float) arr[doc];
69
public int intVal(int doc) {
70
return (int) arr[doc];
74
public long longVal(int doc) {
79
public double doubleVal(int doc) {
84
public String strVal(int doc) {
85
return Long.toString(arr[doc]);
89
public String toString(int doc) {
90
return description() + '=' + longVal(doc);
94
public ValueSourceScorer getRangeScorer(IndexReader reader, String lowerVal, String upperVal, boolean includeLower, boolean includeUpper) {
97
// instead of using separate comparison functions, adjust the endpoints.
100
lower = Long.MIN_VALUE;
102
lower = externalToLong(lowerVal);
103
if (!includeLower && lower < Long.MAX_VALUE) lower++;
106
if (upperVal==null) {
107
upper = Long.MAX_VALUE;
109
upper = externalToLong(upperVal);
110
if (!includeUpper && upper > Long.MIN_VALUE) upper--;
113
final long ll = lower;
114
final long uu = upper;
116
return new ValueSourceScorer(reader, this) {
118
public boolean matchesValue(int doc) {
120
// only check for deleted if it's the default value
121
// if (val==0 && reader.isDeleted(doc)) return false;
122
return val >= ll && val <= uu;
132
public boolean equals(Object o) {
133
if (o.getClass() != this.getClass()) return false;
134
LongFieldSource other = (LongFieldSource) o;
135
return super.equals(other)
136
&& (this.parser == null ? other.parser == null :
137
this.parser.getClass() == other.parser.getClass());
141
public int hashCode() {
142
int h = parser == null ? this.getClass().hashCode() : parser.getClass().hashCode();
143
h += super.hashCode();