lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r768385 - in /lucene/java/trunk/src/java/org/apache/lucene/search: FieldValueHitQueue.java IndexSearcher.java SortField.java
Date Fri, 24 Apr 2009 17:59:04 GMT
Author: markrmiller
Date: Fri Apr 24 17:59:04 2009
New Revision: 768385

URL: http://svn.apache.org/viewvc?rev=768385&view=rev
Log:
move detectType to SortField

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/search/FieldValueHitQueue.java
    lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java
    lucene/java/trunk/src/java/org/apache/lucene/search/SortField.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/FieldValueHitQueue.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/FieldValueHitQueue.java?rev=768385&r1=768384&r2=768385&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/FieldValueHitQueue.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/FieldValueHitQueue.java Fri Apr 24
17:59:04 2009
@@ -20,8 +20,6 @@
 import java.io.IOException;
 
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.index.TermEnum;
 import org.apache.lucene.util.PriorityQueue;
 
 /**
@@ -31,7 +29,7 @@
  * 
  * This class will not resolve SortField.AUTO types, and expects the type
  * of all SortFields used for construction to already have been resolved. 
- * {@link #detectFieldType(IndexReader, String)} is a utility method which
+ * {@link SortField#detectFieldType(IndexReader, String)} is a utility method which
  * may be used for field type detection.
  *
  * <b>NOTE:</b> This API is experimental and might change in
@@ -231,53 +229,4 @@
   SortField[] getFields() {
     return fields;
   }
-  
-  /** Attempts to detect the given field type for an IndexReader. */
-  static int detectFieldType(IndexReader reader, String fieldKey) throws IOException {
-    String field = 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");
-      }
-      int ret = 0;
-      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 = SortField.INT;
-        } catch (NumberFormatException nfe1) {
-          try {
-            Long.parseLong(termtext);
-            ret = SortField.LONG;
-          } catch (NumberFormatException nfe2) {
-            try {
-              Float.parseFloat (termtext);
-              ret = SortField.FLOAT;
-            } catch (NumberFormatException nfe3) {
-              ret = SortField.STRING;
-            }
-          }
-        }         
-      } 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/IndexSearcher.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java?rev=768385&r1=768384&r2=768385&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java Fri Apr 24 17:59:04
2009
@@ -211,7 +211,7 @@
       int type = field.getType();
       // Resolve AUTO into its true type
       if (type == SortField.AUTO) {
-        int autotype = FieldValueHitQueue.detectFieldType(reader, fieldname);
+        int autotype = SortField.detectFieldType(reader, fieldname);
         if (autotype == SortField.STRING) {
           fields[i] = new SortField (fieldname, field.getLocale(), field.getReverse());
         } else {

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/SortField.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/SortField.java?rev=768385&r1=768384&r2=768385&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/SortField.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/SortField.java Fri Apr 24 17:59:04
2009
@@ -21,6 +21,10 @@
 import java.io.Serializable;
 import java.util.Locale;
 
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.index.TermEnum;
+
 /**
  * Stores information about how to sort documents by terms in an individual
  * field.  Fields must be indexed in order to sort by them.
@@ -488,4 +492,53 @@
       throw new IllegalStateException("Illegal sort type: " + type);
     }
   }
+  
+  /** Attempts to detect the given field type for an IndexReader. */
+  static int detectFieldType(IndexReader reader, String fieldKey) throws IOException {
+    String field = 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");
+      }
+      int ret = 0;
+      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 = SortField.INT;
+        } catch (NumberFormatException nfe1) {
+          try {
+            Long.parseLong(termtext);
+            ret = SortField.LONG;
+          } catch (NumberFormatException nfe2) {
+            try {
+              Float.parseFloat (termtext);
+              ret = SortField.FLOAT;
+            } catch (NumberFormatException nfe3) {
+              ret = SortField.STRING;
+            }
+          }
+        }         
+      } else {
+        throw new RuntimeException("field \"" + field + "\" does not appear to be indexed");
+      }
+      return ret;
+    } finally {
+      enumerator.close();
+    }
+  }
 }



Mime
View raw message