lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r179605 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/search/FieldCache.java src/java/org/apache/lucene/search/FieldCacheImpl.java
Date Thu, 02 Jun 2005 16:48:42 GMT
Author: cutting
Date: Thu Jun  2 09:48:40 2005
New Revision: 179605

URL: http://svn.apache.org/viewcvs?rev=179605&view=rev
Log:
Add IntParser and FloatParser interfaces to FieldCache.

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/search/FieldCache.java
    lucene/java/trunk/src/java/org/apache/lucene/search/FieldCacheImpl.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/CHANGES.txt?rev=179605&r1=179604&r2=179605&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Thu Jun  2 09:48:40 2005
@@ -109,6 +109,11 @@
 16. Add ParallelReader, an IndexReader that combines separate indexes
     over different fields into a single virtual index.  (Doug Cutting)
 
+17. Add IntParser and FloatParser interfaces to FieldCache, so that
+    fields in arbitrarily formats can be cached as ints and floats.
+    (Doug Cutting)
+
+
 API Changes
 
  1. Several methods and fields have been deprecated. The API documentation 

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/FieldCache.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/search/FieldCache.java?rev=179605&r1=179604&r2=179605&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/FieldCache.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/FieldCache.java Thu Jun  2 09:48:40
2005
@@ -52,6 +52,22 @@
     }
   }
 
+  /** Interface to parse ints from document fields.
+   * @see #getInts(IndexReader, String, IntParser)
+   */
+  public interface IntParser {
+    /** Return an integer representation of this field's value. */
+    public int parseInt(String string);
+  }
+
+
+  /** Interface to parse floats from document fields.
+   * @see #getFloats(IndexReader, String, FloatParser)
+   */
+  public interface FloatParser {
+    /** Return an float representation of this field's value. */
+    public float parseFloat(String string);
+  }
 
   /** Expert: The cache used internally by sorting and range query classes. */
   public static FieldCache DEFAULT = new FieldCacheImpl();
@@ -69,6 +85,19 @@
   public int[] getInts (IndexReader reader, String field)
   throws IOException;
 
+  /** Checks the internal cache for an appropriate entry, and if none is found,
+   * reads the terms in <code>field</code> as integers and returns an array of
+   * size <code>reader.maxDoc()</code> of the value each document has in the
+   * given field.
+   * @param reader  Used to get field values.
+   * @param field   Which field contains the integers.
+   * @param parser  Computes integer for string values.
+   * @return The values in the given field for each document.
+   * @throws IOException  If any error occurs.
+   */
+  public int[] getInts (IndexReader reader, String field, IntParser parser)
+  throws IOException;
+
   /** Checks the internal cache for an appropriate entry, and if
    * none is found, reads the terms in <code>field</code> as floats and returns
an array
    * of size <code>reader.maxDoc()</code> of the value each document
@@ -80,6 +109,19 @@
    */
   public float[] getFloats (IndexReader reader, String field)
   throws IOException;
+
+  /** Checks the internal cache for an appropriate entry, and if
+   * none is found, reads the terms in <code>field</code> as floats and returns
an array
+   * of size <code>reader.maxDoc()</code> of the value each document
+   * has in the given field.
+   * @param reader  Used to get field values.
+   * @param field   Which field contains the floats.
+   * @param parser  Computes float for string values.
+   * @return The values in the given field for each document.
+   * @throws IOException  If any error occurs.
+   */
+  public float[] getFloats (IndexReader reader, String field,
+                            FloatParser parser) throws IOException;
 
   /** Checks the internal cache for an appropriate entry, and if none
    * is found, reads the term values in <code>field</code> and returns an array

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/FieldCacheImpl.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/search/FieldCacheImpl.java?rev=179605&r1=179604&r2=179605&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/FieldCacheImpl.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/FieldCacheImpl.java Thu Jun  2 09:48:40
2005
@@ -81,6 +81,17 @@
     }
   }
 
+  private static final IntParser INT_PARSER = new IntParser() {
+      public int parseInt(String value) {
+        return Integer.parseInt(value);
+      }
+    };
+
+  private static final FloatParser FLOAT_PARSER = new FloatParser() {
+      public float parseFloat(String value) {
+        return Float.parseFloat(value);
+      }
+    };
 
   /** The internal cache. Maps Entry to array of interpreted term values. **/
   final Map cache = new WeakHashMap();
@@ -132,10 +143,15 @@
   }
 
   // inherit javadocs
-  public int[] getInts (IndexReader reader, String field)
+  public int[] getInts (IndexReader reader, String field) throws IOException {
+    return getInts(reader, field, INT_PARSER);
+  }
+
+  // inherit javadocs
+  public int[] getInts (IndexReader reader, String field, IntParser parser)
   throws IOException {
     field = field.intern();
-    Object ret = lookup (reader, field, SortField.INT);
+    Object ret = lookup (reader, field, parser);
     if (ret == null) {
       final int[] retArray = new int[reader.maxDoc()];
       if (retArray.length > 0) {
@@ -159,7 +175,7 @@
           termEnum.close();
         }
       }
-      store (reader, field, SortField.INT, retArray);
+      store (reader, field, parser, retArray);
       return retArray;
     }
     return (int[]) ret;
@@ -167,9 +183,15 @@
 
   // inherit javadocs
   public float[] getFloats (IndexReader reader, String field)
-  throws IOException {
+    throws IOException {
+    return getFloats(reader, field, FLOAT_PARSER);
+  }
+
+  // inherit javadocs
+  public float[] getFloats (IndexReader reader, String field,
+                            FloatParser parser) throws IOException {
     field = field.intern();
-    Object ret = lookup (reader, field, SortField.FLOAT);
+    Object ret = lookup (reader, field, parser);
     if (ret == null) {
       final float[] retArray = new float[reader.maxDoc()];
       if (retArray.length > 0) {
@@ -193,7 +215,7 @@
           termEnum.close();
         }
       }
-      store (reader, field, SortField.FLOAT, retArray);
+      store (reader, field, parser, retArray);
       return retArray;
     }
     return (float[]) ret;
@@ -388,7 +410,7 @@
           termEnum.close();
         }
       }
-      store (reader, field, SortField.CUSTOM, retArray);
+      store (reader, field, comparator, retArray);
       return retArray;
     }
     return (Comparable[]) ret;



Mime
View raw message