lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gsing...@apache.org
Subject svn commit: r605225 - in /lucene/java/trunk/src/java/org/apache/lucene/search: ExtendedFieldCacheImpl.java FieldCacheImpl.java FieldSortedHitQueue.java
Date Tue, 18 Dec 2007 15:13:07 GMT
Author: gsingers
Date: Tue Dec 18 07:13:05 2007
New Revision: 605225

URL: http://svn.apache.org/viewvc?rev=605225&view=rev
Log:
LUCENE-1045: Applied original LUCENE-1045.patch that refactors original 1045 patch to use
ExtendedFieldCache and DOES NOT make FieldCache a class

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/search/ExtendedFieldCacheImpl.java
    lucene/java/trunk/src/java/org/apache/lucene/search/FieldCacheImpl.java
    lucene/java/trunk/src/java/org/apache/lucene/search/FieldSortedHitQueue.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/ExtendedFieldCacheImpl.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/ExtendedFieldCacheImpl.java?rev=605225&r1=605224&r2=605225&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/ExtendedFieldCacheImpl.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/ExtendedFieldCacheImpl.java Tue Dec
18 07:13:05 2007
@@ -25,17 +25,6 @@
       }
   };
 
-  private static final ByteParser BYTE_PARSER = new ByteParser() {
-    public byte parseByte(String string) {
-      return Byte.parseByte(string);
-    }
-  };
-
-  private static final ShortParser SHORT_PARSER = new ShortParser() {
-    public short parseShort(String string) {
-      return Short.parseShort(string);
-    }
-  };
 
   public long[] getLongs(IndexReader reader, String field) throws IOException {
     return getLongs(reader, field, LONG_PARSER);
@@ -114,4 +103,63 @@
       return retArray;
     }
   };
+
+
+  // inherit javadocs
+  public Object getAuto(IndexReader reader, String field) throws IOException {
+    return autoCache.get(reader, field);
+  }
+
+  Cache autoCache = new Cache() {
+
+    protected Object createValue(IndexReader reader, Object fieldKey)
+        throws IOException {
+      String field = ((String)fieldKey).intern();
+      TermEnum enumerator = reader.terms (new Term (field, ""));
+      try {
+        Term term = enumerator.term();
+        if (term == null) {
+          throw new RuntimeException ("no terms in field " + field + " - cannot determine
sort type");
+        }
+        Object ret = null;
+        if (term.field() == field) {
+          String termtext = term.text().trim();
+
+          /**
+           * Java 1.4 level code:
+
+           if (pIntegers.matcher(termtext).matches())
+           return IntegerSortedHitQueue.comparator (reader, enumerator, field);
+
+           else if (pFloats.matcher(termtext).matches())
+           return FloatSortedHitQueue.comparator (reader, enumerator, field);
+           */
+
+          // Java 1.3 level code:
+          try {
+            Integer.parseInt (termtext);
+            ret = getInts (reader, field);
+          } catch (NumberFormatException nfe1) {
+            try {
+              Long.parseLong(termtext);
+              ret = getLongs (reader, field);
+            } catch (NumberFormatException nfe2) {
+              try {
+                Float.parseFloat (termtext);
+                ret = getFloats (reader, field);
+              } catch (NumberFormatException nfe3) {
+                ret = getStringIndex (reader, field);
+              }
+            }
+          }
+        } else {
+          throw new RuntimeException ("field \"" + field + "\" does not appear to be indexed");
+        }
+        return ret;
+      } finally {
+        enumerator.close();
+      }
+    }
+  };
+
 }

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/FieldCacheImpl.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/FieldCacheImpl.java?rev=605225&r1=605224&r2=605225&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 Tue Dec 18 07:13:05
2007
@@ -21,13 +21,12 @@
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermDocs;
 import org.apache.lucene.index.TermEnum;
-import org.apache.lucene.search.ExtendedFieldCache.LongParser;
 
 import java.io.IOException;
+import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
 import java.util.WeakHashMap;
-import java.util.HashMap;
 
 /**
  * Expert: The default cache implementation, storing all values in memory.
@@ -150,11 +149,6 @@
       }
   };
 
-  private static final LongParser LONG_PARSER = new LongParser() {
-    public long parseLong(String value) {
-      return Long.parseLong(value);
-    }
-  };
 
   private static final FloatParser FLOAT_PARSER = new FloatParser() {
       public float parseFloat(String value) {
@@ -279,44 +273,6 @@
     }
   };
 
-  // inherit javadocs
-  public long[] getLongs (IndexReader reader, String field) throws IOException {
-    return getLongs(reader, field, LONG_PARSER);
-  }
-
-  // inherit javadocs
-  public long[] getLongs(IndexReader reader, String field, LongParser parser)
-      throws IOException {
-    return (long[]) longsCache.get(reader, new Entry(field, parser));
-  }
-
-  Cache longsCache = new Cache() {
-
-    protected Object createValue(IndexReader reader, Object entryKey)
-        throws IOException {
-      Entry entry = (Entry) entryKey;
-      String field = entry.field;
-      LongParser parser = (LongParser) entry.custom;
-      final long[] retArray = new long[reader.maxDoc()];
-      TermDocs termDocs = reader.termDocs();
-      TermEnum termEnum = reader.terms (new Term (field, ""));
-      try {
-        do {
-          Term term = termEnum.term();
-          if (term==null || term.field() != field) break;
-          long termval = parser.parseLong(term.text());
-          termDocs.seek (termEnum);
-          while (termDocs.next()) {
-            retArray[termDocs.doc()] = termval;
-          }
-        } while (termEnum.next());
-      } finally {
-        termDocs.close();
-        termEnum.close();
-      }
-      return retArray;
-    }
-  };
 
   // inherit javadocs
   public float[] getFloats (IndexReader reader, String field)
@@ -501,16 +457,11 @@
             ret = getInts (reader, field);
           } catch (NumberFormatException nfe1) {
             try {
-              Long.parseLong(termtext);
-              ret = getLongs (reader, field);
-            } catch (NumberFormatException nfe2) {
-              try {
                 Float.parseFloat (termtext);
                 ret = getFloats (reader, field);
               } catch (NumberFormatException nfe3) {
                 ret = getStringIndex (reader, field);
               }
-            }
           }          
         } else {
           throw new RuntimeException ("field \"" + field + "\" does not appear to be indexed");

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/FieldSortedHitQueue.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/FieldSortedHitQueue.java?rev=605225&r1=605224&r2=605225&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/FieldSortedHitQueue.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/FieldSortedHitQueue.java Tue Dec 18
07:13:05 2007
@@ -417,7 +417,7 @@
   static ScoreDocComparator comparatorAuto (final IndexReader reader, final String fieldname)
   throws IOException {
     final String field = fieldname.intern();
-    Object lookupArray = FieldCache.DEFAULT.getAuto (reader, field);
+    Object lookupArray = ExtendedFieldCache.EXT_DEFAULT.getAuto (reader, field);
     if (lookupArray instanceof FieldCache.StringIndex) {
       return comparatorString (reader, field);
     } else if (lookupArray instanceof int[]) {



Mime
View raw message