lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r377502 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/search/FieldCacheImpl.java
Date Mon, 13 Feb 2006 21:46:14 GMT
Author: yonik
Date: Mon Feb 13 13:46:13 2006
New Revision: 377502

URL: http://svn.apache.org/viewcvs?rev=377502&view=rev
Log:
Removed constrait that a sort field must have some terms indexed: LUCENE-374

Modified:
    lucene/java/trunk/CHANGES.txt
    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=377502&r1=377501&r2=377502&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Mon Feb 13 13:46:13 2006
@@ -337,6 +337,9 @@
     "[1/16/2000 TO 1/18/2000]". This query did not include the documents
     of 1/18/2000, i.e. the last day was not included. (Daniel Naber)
 
+24. Removed sorting constraint that threw an exception if there were
+    not yet any values for the sort field (Yonik Seeley, LUCENE-374)
+
 Optimizations
      
  1. Disk usage (peak requirements during indexing and optimization)

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=377502&r1=377501&r2=377502&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 Mon Feb 13 13:46:13
2006
@@ -154,26 +154,21 @@
     Object ret = lookup (reader, field, parser);
     if (ret == null) {
       final int[] retArray = new int[reader.maxDoc()];
-      if (retArray.length > 0) {
-        TermDocs termDocs = reader.termDocs();
-        TermEnum termEnum = reader.terms (new Term (field, ""));
-        try {
-          if (termEnum.term() == null) {
-            throw new RuntimeException ("no terms in field " + field);
-          }
-          do {
-            Term term = termEnum.term();
-            if (term.field() != field) break;
-            int termval = parser.parseInt(term.text());
-            termDocs.seek (termEnum);
-            while (termDocs.next()) {
-              retArray[termDocs.doc()] = termval;
-            }
-          } while (termEnum.next());
-        } finally {
-          termDocs.close();
-          termEnum.close();
-        }
+      TermDocs termDocs = reader.termDocs();
+      TermEnum termEnum = reader.terms (new Term (field, ""));
+      try {
+        do {
+          Term term = termEnum.term();
+          if (term==null || term.field() != field) break;
+          int termval = parser.parseInt(term.text());
+          termDocs.seek (termEnum);
+          while (termDocs.next()) {
+            retArray[termDocs.doc()] = termval;
+          }
+        } while (termEnum.next());
+      } finally {
+        termDocs.close();
+        termEnum.close();
       }
       store (reader, field, parser, retArray);
       return retArray;
@@ -194,26 +189,21 @@
     Object ret = lookup (reader, field, parser);
     if (ret == null) {
       final float[] retArray = new float[reader.maxDoc()];
-      if (retArray.length > 0) {
-        TermDocs termDocs = reader.termDocs();
-        TermEnum termEnum = reader.terms (new Term (field, ""));
-        try {
-          if (termEnum.term() == null) {
-            throw new RuntimeException ("no terms in field " + field);
-          }
-          do {
-            Term term = termEnum.term();
-            if (term.field() != field) break;
-            float termval = parser.parseFloat(term.text());
-            termDocs.seek (termEnum);
-            while (termDocs.next()) {
-              retArray[termDocs.doc()] = termval;
-            }
-          } while (termEnum.next());
-        } finally {
-          termDocs.close();
-          termEnum.close();
-        }
+      TermDocs termDocs = reader.termDocs();
+      TermEnum termEnum = reader.terms (new Term (field, ""));
+      try {
+        do {
+          Term term = termEnum.term();
+          if (term==null || term.field() != field) break;
+          float termval = parser.parseFloat(term.text());
+          termDocs.seek (termEnum);
+          while (termDocs.next()) {
+            retArray[termDocs.doc()] = termval;
+          }
+        } while (termEnum.next());
+      } finally {
+        termDocs.close();
+        termEnum.close();
       }
       store (reader, field, parser, retArray);
       return retArray;
@@ -228,26 +218,21 @@
     Object ret = lookup (reader, field, SortField.STRING);
     if (ret == null) {
       final String[] retArray = new String[reader.maxDoc()];
-      if (retArray.length > 0) {
-        TermDocs termDocs = reader.termDocs();
-        TermEnum termEnum = reader.terms (new Term (field, ""));
-        try {
-          if (termEnum.term() == null) {
-            throw new RuntimeException ("no terms in field " + field);
-          }
-          do {
-            Term term = termEnum.term();
-            if (term.field() != field) break;
-            String termval = term.text();
-            termDocs.seek (termEnum);
-            while (termDocs.next()) {
-              retArray[termDocs.doc()] = termval;
-            }
-          } while (termEnum.next());
-        } finally {
-          termDocs.close();
-          termEnum.close();
-        }
+      TermDocs termDocs = reader.termDocs();
+      TermEnum termEnum = reader.terms (new Term (field, ""));
+      try {
+        do {
+          Term term = termEnum.term();
+          if (term==null || term.field() != field) break;
+          String termval = term.text();
+          termDocs.seek (termEnum);
+          while (termDocs.next()) {
+            retArray[termDocs.doc()] = termval;
+          }
+        } while (termEnum.next());
+      } finally {
+        termDocs.close();
+        termEnum.close();
       }
       store (reader, field, SortField.STRING, retArray);
       return retArray;
@@ -263,56 +248,52 @@
     if (ret == null) {
       final int[] retArray = new int[reader.maxDoc()];
       String[] mterms = new String[reader.maxDoc()+1];
-      if (retArray.length > 0) {
-        TermDocs termDocs = reader.termDocs();
-        TermEnum termEnum = reader.terms (new Term (field, ""));
-        int t = 0;  // current term number
-
-        // an entry for documents that have no terms in this field
-        // should a document with no terms be at top or bottom?
-        // this puts them at the top - if it is changed, FieldDocSortedHitQueue
-        // needs to change as well.
-        mterms[t++] = null;
-
-        try {
-          if (termEnum.term() == null) {
-            throw new RuntimeException ("no terms in field " + field);
-          }
-          do {
-            Term term = termEnum.term();
-            if (term.field() != field) break;
-
-            // store term text
-            // we expect that there is at most one term per document
-            if (t >= mterms.length) throw new RuntimeException ("there are more terms
than " +
-            		"documents in field \"" + field + "\", but it's impossible to sort on " +
-            		"tokenized fields");
-            mterms[t] = term.text();
-
-            termDocs.seek (termEnum);
-            while (termDocs.next()) {
-              retArray[termDocs.doc()] = t;
-            }
+      TermDocs termDocs = reader.termDocs();
+      TermEnum termEnum = reader.terms (new Term (field, ""));
+      int t = 0;  // current term number
+
+      // an entry for documents that have no terms in this field
+      // should a document with no terms be at top or bottom?
+      // this puts them at the top - if it is changed, FieldDocSortedHitQueue
+      // needs to change as well.
+      mterms[t++] = null;
 
-            t++;
-          } while (termEnum.next());
-        } finally {
-          termDocs.close();
-          termEnum.close();
-        }
+      try {
+        do {
+          Term term = termEnum.term();
+          if (term==null || term.field() != field) break;
+
+          // store term text
+          // we expect that there is at most one term per document
+          if (t >= mterms.length) throw new RuntimeException ("there are more terms than
" +
+                  "documents in field \"" + field + "\", but it's impossible to sort on "
+
+                  "tokenized fields");
+          mterms[t] = term.text();
+
+          termDocs.seek (termEnum);
+          while (termDocs.next()) {
+            retArray[termDocs.doc()] = t;
+          }
 
-        if (t == 0) {
-          // if there are no terms, make the term array
-          // have a single null entry
-          mterms = new String[1];
-        } else if (t < mterms.length) {
-          // if there are less terms than documents,
-          // trim off the dead array space
-          String[] terms = new String[t];
-          System.arraycopy (mterms, 0, terms, 0, t);
-          mterms = terms;
-        }
+          t++;
+        } while (termEnum.next());
+      } finally {
+        termDocs.close();
+        termEnum.close();
+      }
+
+      if (t == 0) {
+        // if there are no terms, make the term array
+        // have a single null entry
+        mterms = new String[1];
+      } else if (t < mterms.length) {
+        // if there are less terms than documents,
+        // trim off the dead array space
+        String[] terms = new String[t];
+        System.arraycopy (mterms, 0, terms, 0, t);
+        mterms = terms;
       }
+
       StringIndex value = new StringIndex (retArray, mterms);
       store (reader, field, STRING_INDEX, value);
       return value;
@@ -389,26 +370,21 @@
     Object ret = lookup (reader, field, comparator);
     if (ret == null) {
       final Comparable[] retArray = new Comparable[reader.maxDoc()];
-      if (retArray.length > 0) {
-        TermDocs termDocs = reader.termDocs();
-        TermEnum termEnum = reader.terms (new Term (field, ""));
-        try {
-          if (termEnum.term() == null) {
-            throw new RuntimeException ("no terms in field " + field);
-          }
-          do {
-            Term term = termEnum.term();
-            if (term.field() != field) break;
-            Comparable termval = comparator.getComparable (term.text());
-            termDocs.seek (termEnum);
-            while (termDocs.next()) {
-              retArray[termDocs.doc()] = termval;
-            }
-          } while (termEnum.next());
-        } finally {
-          termDocs.close();
-          termEnum.close();
-        }
+      TermDocs termDocs = reader.termDocs();
+      TermEnum termEnum = reader.terms (new Term (field, ""));
+      try {
+        do {
+          Term term = termEnum.term();
+          if (term==null || term.field() != field) break;
+          Comparable termval = comparator.getComparable (term.text());
+          termDocs.seek (termEnum);
+          while (termDocs.next()) {
+            retArray[termDocs.doc()] = termval;
+          }
+        } while (termEnum.next());
+      } finally {
+        termDocs.close();
+        termEnum.close();
       }
       store (reader, field, comparator, retArray);
       return retArray;



Mime
View raw message