lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From busc...@apache.org
Subject svn commit: r822587 [2/2] - in /lucene/java/trunk: ./ contrib/analyzers/common/src/test/org/apache/lucene/analysis/query/ contrib/analyzers/common/src/test/org/apache/lucene/analysis/shingle/ contrib/ant/src/java/org/apache/lucene/ant/ contrib/ant/src/...
Date Wed, 07 Oct 2009 05:08:24 GMT
Modified: lucene/java/trunk/contrib/wordnet/src/java/org/apache/lucene/wordnet/SynLookup.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/wordnet/src/java/org/apache/lucene/wordnet/SynLookup.java?rev=822587&r1=822586&r2=822587&view=diff
==============================================================================
--- lucene/java/trunk/contrib/wordnet/src/java/org/apache/lucene/wordnet/SynLookup.java (original)
+++ lucene/java/trunk/contrib/wordnet/src/java/org/apache/lucene/wordnet/SynLookup.java Wed
Oct  7 05:08:22 2009
@@ -17,9 +17,9 @@
  * limitations under the License.
  */
 
+import java.io.File;
 import java.io.IOException;
 import java.io.StringReader;
-import java.io.File;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -30,12 +30,15 @@
 import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.analysis.tokenattributes.TermAttribute;
 import org.apache.lucene.document.Document;
+import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.BooleanClause;
 import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.Hits;
+import org.apache.lucene.search.Collector;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.Scorer;
 import org.apache.lucene.search.Searcher;
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.store.FSDirectory;
@@ -46,6 +49,20 @@
  */
 public class SynLookup {
 
+  final static class CountingCollector extends Collector {
+    public int numHits = 0;
+    
+    public void setScorer(Scorer scorer) throws IOException {}
+    public void collect(int doc) throws IOException {
+      numHits++;
+    }
+
+    public void setNextReader(IndexReader reader, int docBase) {}
+    public boolean acceptsDocsOutOfOrder() {
+      return true;
+    }    
+  }
+  
 	public static void main(String[] args) throws IOException {
 		if (args.length != 2) {
 			System.out.println(
@@ -56,17 +73,20 @@
 		IndexSearcher searcher = new IndexSearcher(directory, true);
 
 		String word = args[1];
-		Hits hits = searcher.search(
-									new TermQuery(new Term(Syns2Index.F_WORD, word)));
+		Query query = new TermQuery(new Term(Syns2Index.F_WORD, word));
+		CountingCollector countingCollector = new CountingCollector();
+		searcher.search(query, countingCollector);
 
-		if (hits.length() == 0) {
+		if (countingCollector.numHits == 0) {
 			System.out.println("No synonyms found for " + word);
 		} else {
 			System.out.println("Synonyms found for \"" + word + "\":");
 		}
 
-		for (int i = 0; i < hits.length(); i++) {
-			Document doc = hits.doc(i);
+		ScoreDoc[] hits = searcher.search(query, countingCollector.numHits).scoreDocs;
+		
+		for (int i = 0; i < hits.length; i++) {
+			Document doc = searcher.doc(hits[i].doc);
 
 			String[] values = doc.getValues(Syns2Index.F_SYN);
 
@@ -92,11 +112,11 @@
 	public static Query expand( String query,
 								Searcher syns,
 								Analyzer a,
-								String field,
-								float boost)
+								final String field,
+								final float boost)
 		throws IOException
 	{
-		Set already = new HashSet(); // avoid dups		
+		final Set already = new HashSet(); // avoid dups		
 		List top = new LinkedList(); // needs to be separately listed..
 
 		// [1] Parse query into separate words so that when we expand we can avoid dups
@@ -108,7 +128,7 @@
 			if ( already.add( word))
 				top.add( word);
 		}
-		BooleanQuery tmp = new BooleanQuery();
+		final BooleanQuery tmp = new BooleanQuery();
 		
 		// [2] form query
 		Iterator it = top.iterator();
@@ -120,23 +140,40 @@
 			tmp.add( tq, BooleanClause.Occur.SHOULD);
 
 			// [2b] add in unique synonums
-			Hits hits = syns.search( new TermQuery( new Term(Syns2Index.F_WORD, word)));
-			for (int i = 0; i < hits.length(); i++)
-			{
-				Document doc = hits.doc(i);
-				String[] values = doc.getValues( Syns2Index.F_SYN);
-				for ( int j = 0; j < values.length; j++)
-				{
-					String syn = values[ j];
-					if ( already.add( syn))
-					{
-						tq = new TermQuery( new Term( field, syn));
-						if ( boost > 0) // else keep normal 1.0
-							tq.setBoost( boost);
-						tmp.add( tq, BooleanClause.Occur.SHOULD); 
-					}
-				}
-			}
+			syns.search(new TermQuery( new Term(Syns2Index.F_WORD, word)), new Collector() {
+			  IndexReader reader;
+			  
+        @Override
+        public boolean acceptsDocsOutOfOrder() {
+          return true;
+        }
+
+        @Override
+        public void collect(int doc) throws IOException {
+          Document d = reader.document(doc);
+          String[] values = d.getValues( Syns2Index.F_SYN);
+          for ( int j = 0; j < values.length; j++)
+          {
+            String syn = values[ j];
+            if ( already.add( syn))
+            {
+              TermQuery tq = new TermQuery( new Term( field, syn));
+              if ( boost > 0) // else keep normal 1.0
+                tq.setBoost( boost);
+              tmp.add( tq, BooleanClause.Occur.SHOULD); 
+            }
+          }
+        }
+
+        @Override
+        public void setNextReader(IndexReader reader, int docBase)
+            throws IOException {
+          this.reader = reader;
+        }
+
+        @Override
+        public void setScorer(Scorer scorer) throws IOException {}
+			});
 		}
 
 

Modified: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java?rev=822587&r1=822586&r2=822587&view=diff
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java
(original)
+++ lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java
Wed Oct  7 05:08:22 2009
@@ -1,6 +1,9 @@
 package org.apache.lucene.xmlparser;
 
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 
 import junit.framework.TestCase;
 
@@ -9,9 +12,10 @@
 import org.apache.lucene.document.Field;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.search.Hits;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.TopDocs;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.RAMDirectory;
 /**
@@ -116,8 +120,8 @@
 	public void testCustomFieldUserQueryXML() throws ParserException, IOException
 	{
 			Query q=parse("UserInputQueryCustomField.xml");
-			Hits h = searcher.search(q);
-			assertEquals("UserInputQueryCustomField should produce 0 result ", 0,h.length());
+			int h = searcher.search(q, null, 1000).totalHits;
+			assertEquals("UserInputQueryCustomField should produce 0 result ", 0,h);
 	}
 	
 	public void testLikeThisQueryXML() throws Exception
@@ -183,8 +187,8 @@
 	public void testDuplicateFilterQueryXML() throws ParserException, IOException
 	{
 			Query q=parse("DuplicateFilterQuery.xml");
-			Hits h = searcher.search(q);
-			assertEquals("DuplicateFilterQuery should produce 1 result ", 1,h.length());
+			int h = searcher.search(q, null, 1000).totalHits;
+			assertEquals("DuplicateFilterQuery should produce 1 result ", 1,h);
 	}
 	
 
@@ -199,14 +203,15 @@
 	}
 	private void dumpResults(String qType,Query q, int numDocs) throws IOException
 	{
-		Hits h = searcher.search(q);
-		assertTrue(qType +" should produce results ", h.length()>0);
+		TopDocs hits = searcher.search(q, null, numDocs);
+		assertTrue(qType +" should produce results ", hits.totalHits>0);
 		if(printResults)
 		{
 			System.out.println("========="+qType+"============");
-			for(int i=0;i<Math.min(numDocs,h.length());i++)
+			ScoreDoc[] scoreDocs = hits.scoreDocs;
+			for(int i=0;i<Math.min(numDocs,hits.totalHits);i++)
 			{
-				org.apache.lucene.document.Document ldoc=h.doc(i);
+				org.apache.lucene.document.Document ldoc=searcher.doc(scoreDocs[i].doc);
 				System.out.println("["+ldoc.get("date")+"]"+ldoc.get("contents"));
 			}
 			System.out.println();

Modified: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestQueryTemplateManager.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestQueryTemplateManager.java?rev=822587&r1=822586&r2=822587&view=diff
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestQueryTemplateManager.java
(original)
+++ lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestQueryTemplateManager.java
Wed Oct  7 05:08:22 2009
@@ -13,7 +13,6 @@
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.search.Hits;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.store.RAMDirectory;
@@ -90,11 +89,11 @@
 			Query q=builder.getQuery(doc.getDocumentElement());
 			
 			//Run the query
-			Hits h=searcher.search(q);
+			int h=searcher.search(q, null, 1000).totalHits;
 			
 			//Check we have the expected number of results
 			int expectedHits=Integer.parseInt(queryFormProperties.getProperty("expectedMatches"));
-			assertEquals("Number of results should match for query "+queryForms[i],expectedHits,h.length());
+			assertEquals("Number of results should match for query "+queryForms[i],expectedHits,h);
 			
 		}
 	}

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/Searcher.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/Searcher.java?rev=822587&r1=822586&r2=822587&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/Searcher.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/Searcher.java Wed Oct  7 05:08:22
2009
@@ -32,48 +32,6 @@
  * closed, otherwise an IOException will be thrown.
  */
 public abstract class Searcher implements Searchable {
-
-  /** Returns the documents matching <code>query</code>. 
-   * @throws BooleanQuery.TooManyClauses
-   * @deprecated Hits will be removed in Lucene 3.0. Use
-   * {@link #search(Query, Filter, int)} instead.
-   */
-  public final Hits search(Query query) throws IOException {
-    return search(query, (Filter)null);
-  }
-
-  /** Returns the documents matching <code>query</code> and
-   * <code>filter</code>.
-   * @throws BooleanQuery.TooManyClauses
-   * @deprecated Hits will be removed in Lucene 3.0. Use
-   * {@link #search(Query, Filter, int)} instead.
-   */
-  public Hits search(Query query, Filter filter) throws IOException {
-    return new Hits(this, query, filter);
-  }
-
-  /** Returns documents matching <code>query</code> sorted by
-   * <code>sort</code>.
-   * @throws BooleanQuery.TooManyClauses
-   * @deprecated Hits will be removed in Lucene 3.0. Use 
-   * {@link #search(Query, Filter, int, Sort)} instead.
-   */
-  public Hits search(Query query, Sort sort)
-    throws IOException {
-    return new Hits(this, query, null, sort);
-  }
-
-  /** Returns documents matching <code>query</code> and <code>filter</code>,
-   * sorted by <code>sort</code>.
-   * @throws BooleanQuery.TooManyClauses
-   * @deprecated Hits will be removed in Lucene 3.0. Use 
-   * {@link #search(Query, Filter, int, Sort)} instead.
-   */
-  public Hits search(Query query, Filter filter, Sort sort)
-    throws IOException {
-    return new Hits(this, query, filter, sort);
-  }
-
   /** Search implementation with arbitrary sorting.  Finds
    * the top <code>n</code> hits for <code>query</code>, applying
    * <code>filter</code> if non-null, and sorting the hits by the criteria in

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestTermRangeFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestTermRangeFilter.java?rev=822587&r1=822586&r2=822587&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestTermRangeFilter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestTermRangeFilter.java Wed Oct 
7 05:08:22 2009
@@ -146,70 +146,68 @@
 
         assertEquals("num of docs", numDocs, 1+ maxId - minId);
 
-        Hits result;
         Query q = new TermQuery(new Term("body","body"));
 
         // test id, bounded on both ends
+        int numHits = search.search(q,new TermRangeFilter("id",minIP,maxIP,T,T,c), 1000).totalHits;
+        assertEquals("find all", numDocs, numHits);
 
-        result = search.search(q,new TermRangeFilter("id",minIP,maxIP,T,T,c));
-        assertEquals("find all", numDocs, result.length());
+        numHits = search.search(q,new TermRangeFilter("id",minIP,maxIP,T,F,c), 1000).totalHits;
+        assertEquals("all but last", numDocs-1, numHits);
 
-        result = search.search(q,new TermRangeFilter("id",minIP,maxIP,T,F,c));
-        assertEquals("all but last", numDocs-1, result.length());
+        numHits = search.search(q,new TermRangeFilter("id",minIP,maxIP,F,T,c), 1000).totalHits;
+        assertEquals("all but first", numDocs-1, numHits);
 
-        result = search.search(q,new TermRangeFilter("id",minIP,maxIP,F,T,c));
-        assertEquals("all but first", numDocs-1, result.length());
+        numHits = search.search(q,new TermRangeFilter("id",minIP,maxIP,F,F,c), 1000).totalHits;
+        assertEquals("all but ends", numDocs-2, numHits);
 
-        result = search.search(q,new TermRangeFilter("id",minIP,maxIP,F,F,c));
-        assertEquals("all but ends", numDocs-2, result.length());
+        numHits = search.search(q,new TermRangeFilter("id",medIP,maxIP,T,T,c), 1000).totalHits;
+        assertEquals("med and up", 1+ maxId-medId, numHits);
 
-        result = search.search(q,new TermRangeFilter("id",medIP,maxIP,T,T,c));
-        assertEquals("med and up", 1+ maxId-medId, result.length());
-
-        result = search.search(q,new TermRangeFilter("id",minIP,medIP,T,T,c));
-        assertEquals("up to med", 1+ medId-minId, result.length());
+        numHits = search.search(q,new TermRangeFilter("id",minIP,medIP,T,T,c), 1000).totalHits;
+        assertEquals("up to med", 1+ medId-minId, numHits);
 
         // unbounded id
 
-        result = search.search(q,new TermRangeFilter("id",minIP,null,T,F,c));
-        assertEquals("min and up", numDocs, result.length());
+        numHits = search.search(q,new TermRangeFilter("id",minIP,null,T,F,c), 1000).totalHits;
+        assertEquals("min and up", numDocs, numHits);
 
-        result = search.search(q,new TermRangeFilter("id",null,maxIP,F,T,c));
-        assertEquals("max and down", numDocs, result.length());
+        numHits = search.search(q,new TermRangeFilter("id",null,maxIP,F,T,c), 1000).totalHits;
+        assertEquals("max and down", numDocs, numHits);
 
-        result = search.search(q,new TermRangeFilter("id",minIP,null,F,F,c));
-        assertEquals("not min, but up", numDocs-1, result.length());
+        numHits = search.search(q,new TermRangeFilter("id",minIP,null,F,F,c), 1000).totalHits;
+        assertEquals("not min, but up", numDocs-1, numHits);
 
-        result = search.search(q,new TermRangeFilter("id",null,maxIP,F,F,c));
-        assertEquals("not max, but down", numDocs-1, result.length());
+        numHits = search.search(q,new TermRangeFilter("id",null,maxIP,F,F,c), 1000).totalHits;
+        assertEquals("not max, but down", numDocs-1, numHits);
 
-        result = search.search(q,new TermRangeFilter("id",medIP,maxIP,T,F,c));
-        assertEquals("med and up, not max", maxId-medId, result.length());
+        numHits = search.search(q,new TermRangeFilter("id",medIP,maxIP,T,F,c), 1000).totalHits;
+        assertEquals("med and up, not max", maxId-medId, numHits);
 
-        result = search.search(q,new TermRangeFilter("id",minIP,medIP,F,T,c));
-        assertEquals("not min, up to med", medId-minId, result.length());
+        numHits = search.search(q,new TermRangeFilter("id",minIP,medIP,F,T,c), 1000).totalHits;
+        assertEquals("not min, up to med", medId-minId, numHits);
 
         // very small sets
 
-        result = search.search(q,new TermRangeFilter("id",minIP,minIP,F,F,c));
-        assertEquals("min,min,F,F", 0, result.length());
-        result = search.search(q,new TermRangeFilter("id",medIP,medIP,F,F,c));
-        assertEquals("med,med,F,F", 0, result.length());
-        result = search.search(q,new TermRangeFilter("id",maxIP,maxIP,F,F,c));
-        assertEquals("max,max,F,F", 0, result.length());
-
-        result = search.search(q,new TermRangeFilter("id",minIP,minIP,T,T,c));
-        assertEquals("min,min,T,T", 1, result.length());
-        result = search.search(q,new TermRangeFilter("id",null,minIP,F,T,c));
-        assertEquals("nul,min,F,T", 1, result.length());
-
-        result = search.search(q,new TermRangeFilter("id",maxIP,maxIP,T,T,c));
-        assertEquals("max,max,T,T", 1, result.length());
-        result = search.search(q,new TermRangeFilter("id",maxIP,null,T,F,c));
-        assertEquals("max,nul,T,T", 1, result.length());
+        numHits = search.search(q,new TermRangeFilter("id",minIP,minIP,F,F,c), 1000).totalHits;
+        assertEquals("min,min,F,F", 0, numHits);
+        numHits = search.search(q,new TermRangeFilter("id",medIP,medIP,F,F,c), 1000).totalHits;
+        assertEquals("med,med,F,F", 0, numHits);
+        numHits = search.search(q,new TermRangeFilter("id",maxIP,maxIP,F,F,c), 1000).totalHits;
+        assertEquals("max,max,F,F", 0, numHits);
+
+        numHits = search.search(q,new TermRangeFilter("id",minIP,minIP,T,T,c), 1000).totalHits;
+        assertEquals("min,min,T,T", 1, numHits);
+        numHits = search.search(q,new TermRangeFilter("id",null,minIP,F,T,c), 1000).totalHits;
+        assertEquals("nul,min,F,T", 1, numHits);
+
+        numHits = search.search(q,new TermRangeFilter("id",maxIP,maxIP,T,T,c), 1000).totalHits;
+        assertEquals("max,max,T,T", 1, numHits);
+        numHits = search.search(q,new TermRangeFilter("id",maxIP,null,T,F,c), 1000).totalHits;
+        assertEquals("max,nul,T,T", 1, numHits);
 
-        result = search.search(q,new TermRangeFilter("id",medIP,medIP,T,T,c));
-        assertEquals("med,med,T,T", 1, result.length());
+        numHits = search.search(q,new TermRangeFilter("id",medIP,medIP,T,T,c), 1000).totalHits;
+        assertEquals("med,med,T,T", 1, numHits);
     }
 
     public void testRangeFilterRand() throws IOException {
@@ -289,53 +287,52 @@
 
         assertEquals("num of docs", numDocs, 1+ maxId - minId);
 
-        Hits result;
         Query q = new TermQuery(new Term("body","body"));
 
         // test extremes, bounded on both ends
 
-        result = search.search(q,new TermRangeFilter("rand",minRP,maxRP,T,T,c));
-        assertEquals("find all", numDocs, result.length());
+        int numHits = search.search(q,new TermRangeFilter("rand",minRP,maxRP,T,T,c), 1000).totalHits;
+        assertEquals("find all", numDocs, numHits);
 
-        result = search.search(q,new TermRangeFilter("rand",minRP,maxRP,T,F,c));
-        assertEquals("all but biggest", numDocs-1, result.length());
+        numHits = search.search(q,new TermRangeFilter("rand",minRP,maxRP,T,F,c), 1000).totalHits;
+        assertEquals("all but biggest", numDocs-1, numHits);
 
-        result = search.search(q,new TermRangeFilter("rand",minRP,maxRP,F,T,c));
-        assertEquals("all but smallest", numDocs-1, result.length());
+        numHits = search.search(q,new TermRangeFilter("rand",minRP,maxRP,F,T,c), 1000).totalHits;
+        assertEquals("all but smallest", numDocs-1, numHits);
 
-        result = search.search(q,new TermRangeFilter("rand",minRP,maxRP,F,F,c));
-        assertEquals("all but extremes", numDocs-2, result.length());
+        numHits = search.search(q,new TermRangeFilter("rand",minRP,maxRP,F,F,c), 1000).totalHits;
+        assertEquals("all but extremes", numDocs-2, numHits);
 
         // unbounded
 
-        result = search.search(q,new TermRangeFilter("rand",minRP,null,T,F,c));
-        assertEquals("smallest and up", numDocs, result.length());
+        numHits = search.search(q,new TermRangeFilter("rand",minRP,null,T,F,c), 1000).totalHits;
+        assertEquals("smallest and up", numDocs, numHits);
 
-        result = search.search(q,new TermRangeFilter("rand",null,maxRP,F,T,c));
-        assertEquals("biggest and down", numDocs, result.length());
+        numHits = search.search(q,new TermRangeFilter("rand",null,maxRP,F,T,c), 1000).totalHits;
+        assertEquals("biggest and down", numDocs, numHits);
 
-        result = search.search(q,new TermRangeFilter("rand",minRP,null,F,F,c));
-        assertEquals("not smallest, but up", numDocs-1, result.length());
+        numHits = search.search(q,new TermRangeFilter("rand",minRP,null,F,F,c), 1000).totalHits;
+        assertEquals("not smallest, but up", numDocs-1, numHits);
 
-        result = search.search(q,new TermRangeFilter("rand",null,maxRP,F,F,c));
-        assertEquals("not biggest, but down", numDocs-1, result.length());
+        numHits = search.search(q,new TermRangeFilter("rand",null,maxRP,F,F,c), 1000).totalHits;
+        assertEquals("not biggest, but down", numDocs-1, numHits);
 
         // very small sets
 
-        result = search.search(q,new TermRangeFilter("rand",minRP,minRP,F,F,c));
-        assertEquals("min,min,F,F", 0, result.length());
-        result = search.search(q,new TermRangeFilter("rand",maxRP,maxRP,F,F,c));
-        assertEquals("max,max,F,F", 0, result.length());
-
-        result = search.search(q,new TermRangeFilter("rand",minRP,minRP,T,T,c));
-        assertEquals("min,min,T,T", 1, result.length());
-        result = search.search(q,new TermRangeFilter("rand",null,minRP,F,T,c));
-        assertEquals("nul,min,F,T", 1, result.length());
-
-        result = search.search(q,new TermRangeFilter("rand",maxRP,maxRP,T,T,c));
-        assertEquals("max,max,T,T", 1, result.length());
-        result = search.search(q,new TermRangeFilter("rand",maxRP,null,T,F,c));
-        assertEquals("max,nul,T,T", 1, result.length());
+        numHits = search.search(q,new TermRangeFilter("rand",minRP,minRP,F,F,c), 1000).totalHits;
+        assertEquals("min,min,F,F", 0, numHits);
+        numHits = search.search(q,new TermRangeFilter("rand",maxRP,maxRP,F,F,c), 1000).totalHits;
+        assertEquals("max,max,F,F", 0, numHits);
+
+        numHits = search.search(q,new TermRangeFilter("rand",minRP,minRP,T,T,c), 1000).totalHits;
+        assertEquals("min,min,T,T", 1, numHits);
+        numHits = search.search(q,new TermRangeFilter("rand",null,minRP,F,T,c), 1000).totalHits;
+        assertEquals("nul,min,F,T", 1, numHits);
+
+        numHits = search.search(q,new TermRangeFilter("rand",maxRP,maxRP,T,T,c), 1000).totalHits;
+        assertEquals("max,max,T,T", 1, numHits);
+        numHits = search.search(q,new TermRangeFilter("rand",maxRP,null,T,F,c), 1000).totalHits;
+        assertEquals("max,nul,T,T", 1, numHits);
     }
     
     public void testFarsi() throws Exception {
@@ -367,13 +364,13 @@
         // orders the U+0698 character before the U+0633 character, so the single
         // index Term below should NOT be returned by a TermRangeFilter with a Farsi
         // Collator (or an Arabic one for the case when Farsi is not supported).
-        Hits result = search.search
-            (q, new TermRangeFilter("content", "\u062F", "\u0698", T, T, collator));
-        assertEquals("The index Term should not be included.", 0, result.length());
-
-        result = search.search
-            (q, new TermRangeFilter("content", "\u0633", "\u0638", T, T, collator));
-        assertEquals("The index Term should be included.", 1, result.length());
+        int numHits = search.search
+            (q, new TermRangeFilter("content", "\u062F", "\u0698", T, T, collator), 1000).totalHits;
+        assertEquals("The index Term should not be included.", 0, numHits);
+
+        numHits = search.search
+            (q, new TermRangeFilter("content", "\u0633", "\u0638", T, T, collator), 1000).totalHits;
+        assertEquals("The index Term should be included.", 1, numHits);
         search.close();
     }
 
@@ -408,14 +405,14 @@
 
         // Unicode order would not include "H\u00C5T" in [ "H\u00D8T", "MAND" ],
         // but Danish collation does.
-        Hits result = search.search
-            (q, new TermRangeFilter("content", "H\u00D8T", "MAND", F, F, collator));
-        assertEquals("The index Term should be included.", 1, result.length());
+        int numHits = search.search
+            (q, new TermRangeFilter("content", "H\u00D8T", "MAND", F, F, collator), 1000).totalHits;
+        assertEquals("The index Term should be included.", 1, numHits);
 
-        result = search.search
-            (q, new TermRangeFilter("content", "H\u00C5T", "MAND", F, F, collator));
+        numHits = search.search
+            (q, new TermRangeFilter("content", "H\u00C5T", "MAND", F, F, collator), 1000).totalHits;
         assertEquals
-            ("The index Term should not be included.", 0, result.length());
+            ("The index Term should not be included.", 0, numHits);
         search.close();
     }
 }

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestTermRangeQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestTermRangeQuery.java?rev=822587&r1=822586&r2=822587&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestTermRangeQuery.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestTermRangeQuery.java Wed Oct  7
05:08:22 2009
@@ -319,26 +319,26 @@
                                  false, false);
     initializeIndex(new String[] {"A", "B", "", "C", "D"}, analyzer);
     IndexSearcher searcher = new IndexSearcher(dir, true);
-    Hits hits = searcher.search(query);
+    int numHits = searcher.search(query, null, 1000).totalHits;
     // When Lucene-38 is fixed, use the assert on the next line:
-    assertEquals("A,B,<empty string>,C,D => A, B & <empty string> are
in range", 3, hits.length());
+    assertEquals("A,B,<empty string>,C,D => A, B & <empty string> are
in range", 3, numHits);
     // until Lucene-38 is fixed, use this assert:
     //assertEquals("A,B,<empty string>,C,D => A, B & <empty string> are
in range", 2, hits.length());
 
     searcher.close();
     initializeIndex(new String[] {"A", "B", "", "D"}, analyzer);
     searcher = new IndexSearcher(dir, true);
-    hits = searcher.search(query);
+    numHits = searcher.search(query, null, 1000).totalHits;
     // When Lucene-38 is fixed, use the assert on the next line:
-    assertEquals("A,B,<empty string>,D => A, B & <empty string> are in
range", 3, hits.length());
+    assertEquals("A,B,<empty string>,D => A, B & <empty string> are in
range", 3, numHits);
     // until Lucene-38 is fixed, use this assert:
     //assertEquals("A,B,<empty string>,D => A, B & <empty string> are
in range", 2, hits.length());
     searcher.close();
     addDoc("C");
     searcher = new IndexSearcher(dir, true);
-    hits = searcher.search(query);
+    numHits = searcher.search(query, null, 1000).totalHits;
     // When Lucene-38 is fixed, use the assert on the next line:
-    assertEquals("C added, still A, B & <empty string> are in range", 3, hits.length());
+    assertEquals("C added, still A, B & <empty string> are in range", 3, numHits);
     // until Lucene-38 is fixed, use this assert
     //assertEquals("C added, still A, B & <empty string> are in range", 2, hits.length());
     searcher.close();
@@ -351,25 +351,25 @@
     Query query = new TermRangeQuery("content", null, "C", true, true);
     initializeIndex(new String[]{"A", "B", "","C", "D"}, analyzer);
     IndexSearcher searcher = new IndexSearcher(dir, true);
-    Hits hits = searcher.search(query);
+    int numHits = searcher.search(query, null, 1000).totalHits;
     // When Lucene-38 is fixed, use the assert on the next line:
-    assertEquals("A,B,<empty string>,C,D => A,B,<empty string>,C in range",
4, hits.length());
+    assertEquals("A,B,<empty string>,C,D => A,B,<empty string>,C in range",
4, numHits);
     // until Lucene-38 is fixed, use this assert
     //assertEquals("A,B,<empty string>,C,D => A,B,<empty string>,C in range",
3, hits.length());
     searcher.close();
     initializeIndex(new String[]{"A", "B", "", "D"}, analyzer);
     searcher = new IndexSearcher(dir, true);
-    hits = searcher.search(query);
+    numHits = searcher.search(query, null, 1000).totalHits;
     // When Lucene-38 is fixed, use the assert on the next line:
-    assertEquals("A,B,<empty string>,D - A, B and <empty string> in range", 3,
hits.length());
+    assertEquals("A,B,<empty string>,D - A, B and <empty string> in range", 3,
numHits);
     // until Lucene-38 is fixed, use this assert
     //assertEquals("A,B,<empty string>,D => A, B and <empty string> in range",
2, hits.length());
     searcher.close();
     addDoc("C");
     searcher = new IndexSearcher(dir, true);
-    hits = searcher.search(query);
+    numHits = searcher.search(query, null, 1000).totalHits;
     // When Lucene-38 is fixed, use the assert on the next line:
-    assertEquals("C added => A,B,<empty string>,C in range", 4, hits.length());
+    assertEquals("C added => A,B,<empty string>,C in range", 4, numHits);
     // until Lucene-38 is fixed, use this assert
     //assertEquals("C added => A,B,<empty string>,C in range", 3, hits.length());
      searcher.close();



Mime
View raw message