You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2011/06/28 18:30:55 UTC

svn commit: r1140713 - in /lucene/dev/trunk/lucene/contrib/queries/src: java/org/apache/lucene/search/SlowCollatedStringComparator.java test/org/apache/lucene/search/TestSlowCollationMethods.java

Author: uschindler
Date: Tue Jun 28 16:30:55 2011
New Revision: 1140713

URL: http://svn.apache.org/viewvc?rev=1140713&view=rev
Log:
LUCENE-3191: Fix SlowCollatedStringComparator and add tests

Modified:
    lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/SlowCollatedStringComparator.java
    lucene/dev/trunk/lucene/contrib/queries/src/test/org/apache/lucene/search/TestSlowCollationMethods.java

Modified: lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/SlowCollatedStringComparator.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/SlowCollatedStringComparator.java?rev=1140713&r1=1140712&r2=1140713&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/SlowCollatedStringComparator.java (original)
+++ lucene/dev/trunk/lucene/contrib/queries/src/java/org/apache/lucene/search/SlowCollatedStringComparator.java Tue Jun 28 16:30:55 2011
@@ -33,7 +33,7 @@ import org.apache.lucene.util.BytesRef;
  * This class will be removed in Lucene 5.0
  */
 @Deprecated
-public final class SlowCollatedStringComparator extends FieldComparator<BytesRef> {
+public final class SlowCollatedStringComparator extends FieldComparator<String> {
 
   private final String[] values;
   private DocTerms currentDocTerms;
@@ -99,13 +99,12 @@ public final class SlowCollatedStringCom
   }
 
   @Override
-  public BytesRef value(int slot) {
-    final String s = values[slot];
-    return s == null ? null : new BytesRef(values[slot]);
+  public String value(int slot) {
+    return values[slot];
   }
 
   @Override
-  public int compareValues(BytesRef first, BytesRef second) {
+  public int compareValues(String first, String second) {
     if (first == null) {
       if (second == null) {
         return 0;

Modified: lucene/dev/trunk/lucene/contrib/queries/src/test/org/apache/lucene/search/TestSlowCollationMethods.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/queries/src/test/org/apache/lucene/search/TestSlowCollationMethods.java?rev=1140713&r1=1140712&r2=1140713&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/queries/src/test/org/apache/lucene/search/TestSlowCollationMethods.java (original)
+++ lucene/dev/trunk/lucene/contrib/queries/src/test/org/apache/lucene/search/TestSlowCollationMethods.java Tue Jun 28 16:30:55 2011
@@ -41,6 +41,7 @@ public class TestSlowCollationMethods ex
   private static IndexReader reader;
   private static Directory dir;
   private static int numDocs;
+  private static String splitDoc;
 
   @BeforeClass
   public static void beforeClass() throws Exception {
@@ -59,6 +60,7 @@ public class TestSlowCollationMethods ex
       doc.add(field);
       iw.addDocument(doc);
     }
+    splitDoc = _TestUtil.randomUnicodeString(random);
     reader = iw.getReader();
     iw.close();
 
@@ -76,6 +78,15 @@ public class TestSlowCollationMethods ex
     dir = null;
   }
   
+  private void doCheckSorting(TopDocs docs) throws Exception {
+    String prev = "";
+    for (ScoreDoc doc : docs.scoreDocs) {
+      String value = reader.document(doc.doc).get("field");
+      assertTrue(collator.compare(value, prev) >= 0);
+      prev = value;
+    }
+  }
+  
   public void testSort() throws Exception {
     SortField sf = new SortField("field", new FieldComparatorSource() {
       @Override
@@ -83,13 +94,16 @@ public class TestSlowCollationMethods ex
         return new SlowCollatedStringComparator(numHits, fieldname, collator);
       }
     });
-    TopFieldDocs docs = searcher.search(new MatchAllDocsQuery(), null, numDocs, new Sort(sf));
-    String prev = "";
-    for (ScoreDoc doc : docs.scoreDocs) {
-      String value = reader.document(doc.doc).get("field");
-      assertTrue(collator.compare(value, prev) >= 0);
-      prev = value;
-    }
+    final Sort sort = new Sort(sf);
+    
+    final TopDocs docs1 = searcher.search(TermRangeQuery.newStringRange("field", null, splitDoc, true, true), null, numDocs/(1+random.nextInt(4)), sort);
+    doCheckSorting(docs1);
+    
+    final TopDocs docs2 = searcher.search(TermRangeQuery.newStringRange("field", splitDoc, null, true, true), null, numDocs/(1+random.nextInt(4)), sort);
+    doCheckSorting(docs2);
+    
+    final TopDocs docs = TopDocs.merge(sort, numDocs/(1+random.nextInt(4)), new TopDocs[]{docs1, docs2});
+    doCheckSorting(docs);
   }
   
   private void doTestRanges(String startPoint, String endPoint, Query query) throws Exception {