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

ReverseOrdFieldSource

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

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

Field values (terms) are lexicographically ordered by unicode value, and numbered starting at 1.
Example of reverse ordinal (rord):
If there were only three field values: "apple","banana","pear"
then rord("apple")=3, rord("banana")=2, ord("pear")=1

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

param
field field whose values reverse order is used.

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

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

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

    final FieldCache.StringIndex sindex = FieldCache.DEFAULT.getStringIndex(reader, field);

    final int arr[] = sindex.order;
    final int end = sindex.lookup.length;

    return new DocValues(arr.length) {
      /*(non-Javadoc) @see org.apache.lucene.search.function.DocValues#floatVal(int) */
      public float floatVal(int doc) {
        return (float)(end - arr[doc]);
      }
      /* (non-Javadoc) @see org.apache.lucene.search.function.DocValues#intVal(int) */
      public int intVal(int doc) {
        return end - 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(intVal(doc));
      }
      /*(non-Javadoc) @see org.apache.lucene.search.function.DocValues#toString(int) */
      public String toString(int doc) {
        return description() + '=" + strVal(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();