~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/DocValues.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.search.*;
21
 
import org.apache.lucene.index.IndexReader;
22
 
 
23
 
/**
24
 
 * Represents field values as different types.
25
 
 * Normally created via a {@link ValueSource} for a particular field and reader.
26
 
 *
27
 
 * @version $Id: DocValues.java 1140724 2011-06-28 17:00:20Z yonik $
28
 
 */
29
 
 
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 {
37
 
 
38
 
  public byte byteVal(int doc) { throw new UnsupportedOperationException(); }
39
 
  public short shortVal(int doc) { throw new UnsupportedOperationException(); }
40
 
 
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);
47
 
 
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(); }
51
 
 
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(); }
57
 
 
58
 
  public Explanation explain(int doc) {
59
 
    return new Explanation(floatVal(doc), toString(doc));
60
 
  }
61
 
 
62
 
  public ValueSourceScorer getScorer(IndexReader reader) {
63
 
    return new ValueSourceScorer(reader, this);
64
 
  }
65
 
 
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) {
71
 
    float lower;
72
 
    float upper;
73
 
 
74
 
    if (lowerVal == null) {
75
 
      lower = Float.NEGATIVE_INFINITY;
76
 
    } else {
77
 
      lower = Float.parseFloat(lowerVal);
78
 
    }
79
 
    if (upperVal == null) {
80
 
      upper = Float.POSITIVE_INFINITY;
81
 
    } else {
82
 
      upper = Float.parseFloat(upperVal);
83
 
    }
84
 
 
85
 
    final float l = lower;
86
 
    final float u = upper;
87
 
 
88
 
    if (includeLower && includeUpper) {
89
 
      return new ValueSourceScorer(reader, this) {
90
 
        @Override
91
 
        public boolean matchesValue(int doc) {
92
 
          float docVal = floatVal(doc);
93
 
          return docVal >= l && docVal <= u;
94
 
        }
95
 
      };
96
 
    }
97
 
    else if (includeLower && !includeUpper) {
98
 
       return new ValueSourceScorer(reader, this) {
99
 
        @Override
100
 
        public boolean matchesValue(int doc) {
101
 
          float docVal = floatVal(doc);
102
 
          return docVal >= l && docVal < u;
103
 
        }
104
 
      };
105
 
    }
106
 
    else if (!includeLower && includeUpper) {
107
 
       return new ValueSourceScorer(reader, this) {
108
 
        @Override
109
 
        public boolean matchesValue(int doc) {
110
 
          float docVal = floatVal(doc);
111
 
          return docVal > l && docVal <= u;
112
 
        }
113
 
      };
114
 
    }
115
 
    else {
116
 
       return new ValueSourceScorer(reader, this) {
117
 
        @Override
118
 
        public boolean matchesValue(int doc) {
119
 
          float docVal = floatVal(doc);
120
 
          return docVal > l && docVal < u;
121
 
        }
122
 
      };
123
 
    }
124
 
  }
125
 
}
126
 
 
127
 
 
128