FileDocCategorySizeDatePackage
DocValues.javaAPI DocApache Lucene 2.2.04983Sat Jun 16 22:20:34 BST 2007org.apache.lucene.search.function

DocValues

public abstract class DocValues extends Object
Expert: represents field values as different types. Normally created via a {@link org.apache.lucene.search.function.ValueSource ValueSuorce} for a particular field and reader.

WARNING: The status of the search.function package is experimental. The APIs introduced here might change in the future and will not be supported anymore in such a case.

author
yonik

Fields Summary
private int
nVals
private float
minVal
private float
maxVal
private float
avgVal
private boolean
computed
Constructors Summary
public DocValues(int nVals)
Constructor with input number of values(docs).

param
nVals

    this.nVals = nVals;
  
private DocValues()

    
  
Methods Summary
private voidcompute()

  // compute optional values
      
    if (computed) {
      return;
    }
    minVal = Float.MAX_VALUE;
    maxVal = 0;
    float sum = 0;
    for (int i=0; i<nVals; i++) {
      float val = floatVal(i); 
      sum += val;
      minVal = Math.min(minVal,val);
      maxVal = Math.max(maxVal,val);
    }
    avgVal = sum / nVals;
    computed = true;
  
public doubledoubleVal(int doc)
Return doc value as a double.

Optional: DocValues implementation can (but don't have to) override this method.

param
doc document whose double value is requested.

    return (double) floatVal(doc);
  
public org.apache.lucene.search.Explanationexplain(int doc)
Explain the scoring value for the input doc.

    return new Explanation(floatVal(doc), toString(doc));
  
public abstract floatfloatVal(int doc)
Return doc value as a float.

Mandatory: every DocValues implementation must implement at least this method.

param
doc document whose float value is requested.

public floatgetAverageValue()
Returns the average of all values.

    compute();
    return avgVal;
  
java.lang.ObjectgetInnerArray()
Expert: for test purposes only, return the inner array of values, or null if not applicable.

Allows tests to verify that loaded values are:

  1. indeed cached/reused.
  2. stored in the expected size/type (byte/short/int/float).
Note: Tested implementations of DocValues must override this method for the test to pass!

    return new Object[0];
  
public floatgetMaxValue()
Optional op. Returns the maximum of all values.

    compute();
    return maxVal;
  
public floatgetMinValue()
Optional op. Returns the minimum of all values.

    compute();
    return minVal;
  
public intintVal(int doc)
Return doc value as an int.

Optional: DocValues implementation can (but don't have to) override this method.

param
doc document whose int value is requested.

 
    return (int) floatVal(doc);
  
public longlongVal(int doc)
Return doc value as a long.

Optional: DocValues implementation can (but don't have to) override this method.

param
doc document whose long value is requested.

    return (long) floatVal(doc);
  
public java.lang.StringstrVal(int doc)
Return doc value as a string.

Optional: DocValues implementation can (but don't have to) override this method.

param
doc document whose string value is requested.

    return Float.toString(floatVal(doc));
  
public abstract java.lang.StringtoString(int doc)
Return a string representation of a doc value, as reuired for Explanations.