1 package org.apache.lucene.search; 2 3 18 19 22 23 import org.apache.lucene.search.Searcher; 24 import org.apache.lucene.search.Query; 25 import org.apache.lucene.search.Hits; 26 import junit.framework.TestCase; 27 28 import java.io.IOException ; 29 import java.util.Set ; 30 import java.util.TreeSet ; 31 32 public class CheckHits { 33 public static void checkHits( 34 Query query, 35 String defaultFieldName, 36 Searcher searcher, 37 int[] results, 38 TestCase testCase) 39 throws IOException { 40 Hits hits = searcher.search(query); 41 42 Set correct = new TreeSet (); 43 for (int i = 0; i < results.length; i++) { 44 correct.add(new Integer (results[i])); 45 } 46 47 Set actual = new TreeSet (); 48 for (int i = 0; i < hits.length(); i++) { 49 actual.add(new Integer (hits.id(i))); 50 } 51 52 testCase.assertEquals(query.toString(defaultFieldName), correct, actual); 53 } 54 55 public static void printDocNrs(Hits hits) throws IOException { 56 System.out.print("new int[] {"); 57 for (int i = 0; i < hits.length(); i++) { 58 System.out.print(hits.id(i)); 59 if (i != hits.length()-1) 60 System.out.print(", "); 61 } 62 System.out.println("}"); 63 } 64 } 65 66 | Popular Tags |