lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r332229 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/search/FieldDocSortedHitQueue.java src/test/org/apache/lucene/search/TestSort.java
Date Thu, 10 Nov 2005 05:57:36 GMT
Author: yonik
Date: Wed Nov  9 21:57:32 2005
New Revision: 332229

URL: http://svn.apache.org/viewcvs?rev=332229&view=rev
Log:
fix comparison of null strings in FieldDocSortedHitQueue: LUCENE-453

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/search/FieldDocSortedHitQueue.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/CHANGES.txt?rev=332229&r1=332228&r2=332229&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Wed Nov  9 21:57:32 2005
@@ -240,6 +240,11 @@
 	
 14.	Fixed WildcardQuery to prevent "cat" matching "ca??".
 	(Xiaozheng Ma via Bernhard, LUCENE-306)
+
+15. Fixed a bug where MultiSearcher and ParallelMultiSearcher could
+    change the sort order when sorting by string for documents without
+    a value for the sort field.
+    (Luc Vanlerberghe via Yonik, LUCENE-453)
 	
 Optimizations
      

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/FieldDocSortedHitQueue.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/search/FieldDocSortedHitQueue.java?rev=332229&r1=332228&r2=332229&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/FieldDocSortedHitQueue.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/FieldDocSortedHitQueue.java Wed Nov
 9 21:57:32 2005
@@ -126,9 +126,9 @@
 					String s2 = (String) docB.fields[i];
 					// null values need to be sorted first, because of how FieldCache.getStringIndex()
 					// works - in that routine, any documents without a value in the given field are
-					// put first.
-					if (s1 == null) c = -1;      // could be null if there are
-					else if (s2 == null) c = 1;  // no terms in the given field
+					// put first.  If both are null, the next SortField is used
+					if (s1 == null) c = (s2==null) ? 0 : -1;
+					else if (s2 == null) c = 1;  // 
 					else if (fields[i].getLocale() == null) {
 						c = s1.compareTo(s2);
 					} else {

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java?rev=332229&r1=332228&r2=332229&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java Wed Nov  9 21:57:32
2005
@@ -60,6 +60,7 @@
 	private Query queryA;
 	private Query queryE;
 	private Query queryF;
+	private Query queryG;
 	private Sort sort;
 
 
@@ -105,7 +106,10 @@
 	{   "H",   "y a b c d",     "0",           "1.4E-45",      "e",     "C-88"  },
 	{   "I",   "x a b c d e f", "-2147483648", "1.0e+0",       "d",     "A-10"  },
 	{   "J",   "y a b c d e f", "4",           ".5",           "b",     "C-7"   },
-	{   "Z",   "f",             null,          null,           null,    null    }
+	{   "W",   "g",             "1",           null,           null,    null    },
+	{   "X",   "g",             "1",           "0.1",          null,    null    },
+	{   "Y",   "g",             "1",           "0.2",          null,    null    },
+	{   "Z",   "f g",           null,          null,           null,    null    }
 	};
 
 	// create an index of all the documents, or just the x, or just the y documents
@@ -160,6 +164,7 @@
 		queryA = new TermQuery (new Term ("contents", "a"));
     queryE = new TermQuery (new Term ("contents", "e"));
 		queryF = new TermQuery (new Term ("contents", "f"));
+		queryG = new TermQuery (new Term ("contents", "g"));
 		sort = new Sort();
 	}
 
@@ -271,6 +276,47 @@
 
 		sort.setSort ("float", true);
 		assertMatches (full, queryF, sort, "IJZ");
+
+		// When a field is null for both documents, the next SortField should be used.
+                // Works for
+		sort.setSort (new SortField[] { new SortField ("int"),
+                                new SortField ("string", SortField.STRING),
+				new SortField ("float") });
+		assertMatches (full, queryG, sort, "ZWXY");
+
+		// Reverse the last criterium to make sure the test didn't pass by chance
+		sort.setSort (new SortField[] { new SortField ("int"),
+                                new SortField ("string", SortField.STRING),
+				new SortField ("float", true) });
+		assertMatches (full, queryG, sort, "ZYXW");
+
+		// Do the same for a MultiSearcher
+		Searcher multiSearcher=new MultiSearcher (new Searchable[] { full });
+
+		sort.setSort (new SortField[] { new SortField ("int"),
+                                new SortField ("string", SortField.STRING),
+				new SortField ("float") });
+		assertMatches (multiSearcher, queryG, sort, "ZWXY");
+
+		sort.setSort (new SortField[] { new SortField ("int"),
+                                new SortField ("string", SortField.STRING),
+				new SortField ("float", true) });
+		assertMatches (multiSearcher, queryG, sort, "ZYXW");
+		// Don't close the multiSearcher. it would close the full searcher too!
+
+		// Do the same for a ParallelMultiSearcher
+                Searcher parallelSearcher=new ParallelMultiSearcher (new Searchable[] { full
});
+
+		sort.setSort (new SortField[] { new SortField ("int"),
+                                new SortField ("string", SortField.STRING),
+				new SortField ("float") });
+		assertMatches (parallelSearcher, queryG, sort, "ZWXY");
+
+		sort.setSort (new SortField[] { new SortField ("int"),
+                                new SortField ("string", SortField.STRING),
+				new SortField ("float", true) });
+		assertMatches (parallelSearcher, queryG, sort, "ZYXW");
+		// Don't close the parallelSearcher. it would close the full searcher too!
 	}
 
 	// test sorts using a series of fields
@@ -449,6 +495,9 @@
 	}
 
   public void testTopDocsScores() throws Exception {
+
+    // There was previously a bug in FieldSortedHitQueue.maxscore when only a single
+    // doc was added.  That is what the following tests for.
     Sort sort = new Sort();
     int nDocs=10;
 
@@ -466,10 +515,7 @@
     };
 
     TopDocs docs2 = full.search(queryE, filt, nDocs, sort);
-
-    // This test currently fails because of a bug in FieldSortedHitQueue
-    // with a single document matching.
-    // TODO: uncomment when fixed.
+    
     // assertEquals(docs1.scoreDocs[0].score, docs2.scoreDocs[0].score, 1e-6);
   }
 



Mime
View raw message