Home » lucene-3.0.1-src » org.apache » lucene » search » function » [javadoc | source]

    1   package org.apache.lucene.search.function;
    2   
    3   /**
    4    * Licensed to the Apache Software Foundation (ASF) under one or more
    5    * contributor license agreements.  See the NOTICE file distributed with
    6    * this work for additional information regarding copyright ownership.
    7    * The ASF licenses this file to You under the Apache License, Version 2.0
    8    * (the "License"); you may not use this file except in compliance with
    9    * the License.  You may obtain a copy of the License at
   10    *
   11    *     http://www.apache.org/licenses/LICENSE-2.0
   12    *
   13    * Unless required by applicable law or agreed to in writing, software
   14    * distributed under the License is distributed on an "AS IS" BASIS,
   15    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   16    * See the License for the specific language governing permissions and
   17    * limitations under the License.
   18    */
   19   
   20   import java.io.IOException;
   21   
   22   import org.apache.lucene.index.IndexReader;
   23   import org.apache.lucene.search.FieldCache;
   24   
   25   /**
   26    * Expert: A base class for ValueSource implementations that retrieve values for
   27    * a single field from the {@link org.apache.lucene.search.FieldCache FieldCache}.
   28    * <p>
   29    * Fields used herein must be indexed (doesn't matter if these fields are stored or not).
   30    * <p> 
   31    * It is assumed that each such indexed field is untokenized, or at least has a single token in a document.
   32    * For documents with multiple tokens of the same field, behavior is undefined (It is likely that current 
   33    * code would use the value of one of these tokens, but this is not guaranteed).
   34    * <p>
   35    * Document with no tokens in this field are assigned the <code>Zero</code> value.    
   36    * 
   37    * <p><font color="#FF0000">
   38    * WARNING: The status of the <b>search.function</b> package is experimental. 
   39    * The APIs introduced here might change in the future and will not be 
   40    * supported anymore in such a case.</font>
   41    *
   42    * <p><b>NOTE</b>: with the switch in 2.9 to segment-based
   43    * searching, if {@link #getValues} is invoked with a
   44    * composite (multi-segment) reader, this can easily cause
   45    * double RAM usage for the values in the FieldCache.  It's
   46    * best to switch your application to pass only atomic
   47    * (single segment) readers to this API.</p>
   48    */
   49   public abstract class FieldCacheSource extends ValueSource {
   50     private String field;
   51   
   52     /**
   53      * Create a cached field source for the input field.  
   54      */
   55     public FieldCacheSource(String field) {
   56       this.field=field;
   57     }
   58   
   59     /* (non-Javadoc) @see org.apache.lucene.search.function.ValueSource#getValues(org.apache.lucene.index.IndexReader) */
   60     @Override
   61     public final DocValues getValues(IndexReader reader) throws IOException {
   62       return getCachedFieldValues(FieldCache.DEFAULT, field, reader);
   63     }
   64   
   65     /* (non-Javadoc) @see org.apache.lucene.search.function.ValueSource#description() */
   66     @Override
   67     public String description() {
   68       return field;
   69     }
   70   
   71     /**
   72      * Return cached DocValues for input field and reader.
   73      * @param cache FieldCache so that values of a field are loaded once per reader (RAM allowing)
   74      * @param field Field for which values are required.
   75      * @see ValueSource
   76      */
   77     public abstract DocValues getCachedFieldValues(FieldCache cache, String field, IndexReader reader) throws IOException;
   78   
   79     /*(non-Javadoc) @see java.lang.Object#equals(java.lang.Object) */
   80     @Override
   81     public final boolean equals(Object o) {
   82       if (!(o instanceof FieldCacheSource)) {
   83         return false;
   84       }
   85       FieldCacheSource other = (FieldCacheSource) o;
   86       return 
   87         this.field.equals(other.field) && 
   88         cachedFieldSourceEquals(other);
   89     }
   90   
   91     /*(non-Javadoc) @see java.lang.Object#hashCode() */
   92     @Override
   93     public final int hashCode() {
   94       return 
   95         field.hashCode() +
   96         cachedFieldSourceHashCode();
   97     }
   98   
   99     /**
  100      * Check if equals to another {@link FieldCacheSource}, already knowing that cache and field are equal.  
  101      * @see Object#equals(java.lang.Object)
  102      */
  103     public abstract boolean cachedFieldSourceEquals(FieldCacheSource other);
  104   
  105     /**
  106      * Return a hash code of a {@link FieldCacheSource}, without the hash-codes of the field 
  107      * and the cache (those are taken care of elsewhere).  
  108      * @see Object#hashCode()
  109      */
  110     public abstract int cachedFieldSourceHashCode();
  111   }

Home » lucene-3.0.1-src » org.apache » lucene » search » function » [javadoc | source]