You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2014/01/15 20:03:07 UTC

svn commit: r1558516 - in /lucene/dev/branches/lucene539399/lucene/core/src: java/org/apache/lucene/search/ test/org/apache/lucene/search/

Author: mikemccand
Date: Wed Jan 15 19:03:06 2014
New Revision: 1558516

URL: http://svn.apache.org/r1558516
Log:
LUCENE-5399: add fangs, fix 2 bugs

Modified:
    lucene/dev/branches/lucene539399/lucene/core/src/java/org/apache/lucene/search/FieldComparator.java
    lucene/dev/branches/lucene539399/lucene/core/src/java/org/apache/lucene/search/SortField.java
    lucene/dev/branches/lucene539399/lucene/core/src/java/org/apache/lucene/search/TopFieldCollector.java
    lucene/dev/branches/lucene539399/lucene/core/src/test/org/apache/lucene/search/TestSearchAfter.java

Modified: lucene/dev/branches/lucene539399/lucene/core/src/java/org/apache/lucene/search/FieldComparator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene539399/lucene/core/src/java/org/apache/lucene/search/FieldComparator.java?rev=1558516&r1=1558515&r2=1558516&view=diff
==============================================================================
--- lucene/dev/branches/lucene539399/lucene/core/src/java/org/apache/lucene/search/FieldComparator.java (original)
+++ lucene/dev/branches/lucene539399/lucene/core/src/java/org/apache/lucene/search/FieldComparator.java Wed Jan 15 19:03:06 2014
@@ -876,6 +876,7 @@ public abstract class FieldComparator<T>
         topOrd = missingOrd;
         topSameReader = true;
       }
+      //System.out.println("  setNextReader topOrd=" + topOrd + " topSameReader=" + topSameReader);
 
       if (bottomSlot != -1) {
         // Recompute bottomOrd/SameReader
@@ -921,6 +922,7 @@ public abstract class FieldComparator<T>
       // null is fine: it means the last doc of the prior
       // search was missing this value
       topValue = value;
+      //System.out.println("setTopValue " + topValue);
     }
 
     @Override
@@ -932,9 +934,14 @@ public abstract class FieldComparator<T>
     public int compareTop(int doc) {
 
       int ord = termsIndex.getOrd(doc);
+      if (ord == -1) {
+        ord = missingOrd;
+      }
 
       if (topSameReader) {
-        // ord is precisely comparable, even in the equal case
+        // ord is precisely comparable, even in the equal
+        // case
+        //System.out.println("compareTop doc=" + doc + " ord=" + ord + " ret=" + (topOrd-ord));
         return topOrd - ord;
       } else if (ord <= topOrd) {
         // the equals case always means doc is < value
@@ -1066,6 +1073,7 @@ public abstract class FieldComparator<T>
 
     private void setMissingBytes(int doc, BytesRef br) {
       if (br.length == 0) {
+        br.offset = 0;
         if (docsWithField.get(doc) == false) {
           br.bytes = MISSING_BYTES;
         } else {

Modified: lucene/dev/branches/lucene539399/lucene/core/src/java/org/apache/lucene/search/SortField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene539399/lucene/core/src/java/org/apache/lucene/search/SortField.java?rev=1558516&r1=1558515&r2=1558516&view=diff
==============================================================================
--- lucene/dev/branches/lucene539399/lucene/core/src/java/org/apache/lucene/search/SortField.java (original)
+++ lucene/dev/branches/lucene539399/lucene/core/src/java/org/apache/lucene/search/SortField.java Wed Jan 15 19:03:06 2014
@@ -169,13 +169,25 @@ public class SortField {
     this.parser = parser;
   }
 
+  // nocommit should missing first/last not be affected by reverse=true???
+
   /** Pass this to {@link #setMissingValue} to have missing
    *  string values sort first. */
-  public final static Object STRING_FIRST = new Object();
+  public final static Object STRING_FIRST = new Object() {
+      @Override
+      public String toString() {
+        return "SortField.STRING_FIRST";
+      }
+    };
   
   /** Pass this to {@link #setMissingValue} to have missing
    *  string values sort last. */
-  public final static Object STRING_LAST = new Object();
+  public final static Object STRING_LAST = new Object() {
+      @Override
+      public String toString() {
+        return "SortField.STRING_LAST";
+      }
+    };
 
   public void setMissingValue(Object missingValue) {
     if (type == Type.STRING) {
@@ -308,6 +320,10 @@ public class SortField {
     }
 
     if (reverse) buffer.append('!');
+    if (missingValue != null) {
+      buffer.append(" missingValue=");
+      buffer.append(missingValue);
+    }
 
     return buffer.toString();
   }

Modified: lucene/dev/branches/lucene539399/lucene/core/src/java/org/apache/lucene/search/TopFieldCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene539399/lucene/core/src/java/org/apache/lucene/search/TopFieldCollector.java?rev=1558516&r1=1558515&r2=1558516&view=diff
==============================================================================
--- lucene/dev/branches/lucene539399/lucene/core/src/java/org/apache/lucene/search/TopFieldCollector.java (original)
+++ lucene/dev/branches/lucene539399/lucene/core/src/java/org/apache/lucene/search/TopFieldCollector.java Wed Jan 15 19:03:06 2014
@@ -887,6 +887,8 @@ public abstract class TopFieldCollector 
     @SuppressWarnings({"unchecked", "rawtypes"})
     @Override
     public void collect(int doc) throws IOException {
+      //System.out.println("  collect doc=" + doc);
+
       totalHits++;
 
       float score = Float.NaN;
@@ -919,8 +921,6 @@ public abstract class TopFieldCollector 
         }
       }
 
-      //System.out.println("  collect doc=" + doc);
-
       // Check if this hit was already collected on a
       // previous page:
       boolean sameValues = true;
@@ -935,7 +935,7 @@ public abstract class TopFieldCollector 
         } else if (cmp < 0) {
           // Not yet collected
           sameValues = false;
-          //System.out.println("    keep: after");
+          //System.out.println("    keep: after; reverseMul=" + reverseMul[compIDX]);
           break;
         }
       }

Modified: lucene/dev/branches/lucene539399/lucene/core/src/test/org/apache/lucene/search/TestSearchAfter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene539399/lucene/core/src/test/org/apache/lucene/search/TestSearchAfter.java?rev=1558516&r1=1558515&r2=1558516&view=diff
==============================================================================
--- lucene/dev/branches/lucene539399/lucene/core/src/test/org/apache/lucene/search/TestSearchAfter.java (original)
+++ lucene/dev/branches/lucene539399/lucene/core/src/test/org/apache/lucene/search/TestSearchAfter.java Wed Jan 15 19:03:06 2014
@@ -51,8 +51,6 @@ public class TestSearchAfter extends Luc
   private IndexSearcher searcher;
   private int iter;
 
-  // nocommit add SF.setMissingValue too
-
   @Override
   public void setUp() throws Exception {
     super.setUp();
@@ -132,7 +130,7 @@ public class TestSearchAfter extends Luc
     }
   }
 
-  static SortField[] allSortFields = new SortField[] {
+  static List<SortField> allSortFields = new ArrayList<SortField>(Arrays.asList(new SortField[] {
     new SortField("int", SortField.Type.INT, false),
     new SortField("long", SortField.Type.LONG, false),
     new SortField("float", SortField.Type.FLOAT, false),
@@ -157,8 +155,25 @@ public class TestSearchAfter extends Luc
     new SortField("straightbytesdocvalues", SortField.Type.STRING_VAL, true),
     SortField.FIELD_SCORE,
     SortField.FIELD_DOC,
-    // nocommit add RELEVANCE too
-  };
+      }));
+
+  static {
+    // Also test missing first / last for the "string" sorts:
+    for(String field : new String[] {"bytes", "sortedbytesdocvalues"}) {
+      for(int rev=0;rev<2;rev++) {
+        boolean reversed = rev == 0;
+        SortField sf = new SortField(field, SortField.Type.STRING, reversed);
+        sf.setMissingValue(SortField.STRING_FIRST);
+        allSortFields.add(sf);
+
+        sf = new SortField(field, SortField.Type.STRING, reversed);
+        sf.setMissingValue(SortField.STRING_LAST);
+        allSortFields.add(sf);
+      }
+    }
+
+    // nocommit test missing value for numerics too:
+  }
   
   void assertQuery(Query query, Filter filter) throws Exception {
     assertQuery(query, filter, null);
@@ -175,7 +190,7 @@ public class TestSearchAfter extends Luc
   Sort getRandomSort() {
     SortField[] sortFields = new SortField[_TestUtil.nextInt(random(), 2, 7)];
     for(int i=0;i<sortFields.length;i++) {
-      sortFields[i] = allSortFields[random().nextInt(allSortFields.length)];
+      sortFields[i] = allSortFields.get(random().nextInt(allSortFields.size()));
     }
     return new Sort(sortFields);
   }