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

OrdFieldSource

public class OrdFieldSource extends ValueSource
Expert: obtains the ordinal of the field value from the default Lucene {@link org.apache.lucene.search.FieldCache Fieldcache} using getStringIndex().

The native lucene index order is used to assign an ordinal value for each field value.

Example:
If there were only three field values: "apple","banana","pear"
then ord("apple")=1, ord("banana")=2, ord("pear")=3

WARNING: ord() depends on the position in an index and can thus change when other documents are inserted or deleted, or if a MultiSearcher is used.

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
protected String
field
private static final int
hcode
Constructors Summary
public OrdFieldSource(String field)
Contructor for a certain field.

param
field field whose values order is used.

    this.field = field;
  
Methods Summary
public java.lang.Stringdescription()

    return "ord(" + field + ')";
  
public booleanequals(java.lang.Object o)

    if (o.getClass() !=  OrdFieldSource.class) return false;
    OrdFieldSource other = (OrdFieldSource)o;
    return this.field.equals(other.field);
  
public org.apache.lucene.search.function.DocValuesgetValues(org.apache.lucene.index.IndexReader reader)

    final int[] arr = FieldCache.DEFAULT.getStringIndex(reader, field).order;
    return new DocValues(arr.length) {
      /*(non-Javadoc) @see org.apache.lucene.search.function.DocValues#floatVal(int) */
      public float floatVal(int doc) {
        return (float)arr[doc];
      }
      /*(non-Javadoc) @see org.apache.lucene.search.function.DocValues#strVal(int) */
      public String strVal(int doc) {
        // the string value of the ordinal, not the string itself
        return Integer.toString(arr[doc]);
      }
      /*(non-Javadoc) @see org.apache.lucene.search.function.DocValues#toString(int) */
      public String toString(int doc) {
        return description() + '=" + intVal(doc);
      }
      /*(non-Javadoc) @see org.apache.lucene.search.function.DocValues#getInnerArray() */
      Object getInnerArray() {
        return arr;
      }
    };
  
public inthashCode()

  
  /*(non-Javadoc) @see java.lang.Object#hashCode() */
     
    return hcode + field.hashCode();