Methods Summary |
---|
private void | add(java.lang.String value, org.apache.lucene.index.IndexWriter iw)
Document d = new Document();
d.add(new Field(FIELD_NAME, value, Field.Store.YES, Field.Index.TOKENIZED));
iw.addDocument(d);
|
private void | addCollection1(org.apache.lucene.index.IndexWriter iw)
add("one blah three", iw);
add("one foo three multiOne", iw);
add("one foobar three multiThree", iw);
add("blueberry pie", iw);
add("blueberry strudel", iw);
add("blueberry pizza", iw);
|
private void | addCollection2(org.apache.lucene.index.IndexWriter iw)
add("two blah three", iw);
add("two foo xxx multiTwo", iw);
add("two foobar xxx multiThreee", iw);
add("blueberry chewing gum", iw);
add("bluebird pizza", iw);
add("bluebird foobar pizza", iw);
add("piccadilly circus", iw);
|
private void | checkQuery(java.lang.String queryStr)checks if a query yields the same result when executed on
a single IndexSearcher containing all documents and on a
MultiSearcher aggregating sub-searchers
// check result hit ranking
if(verbose) System.out.println("Query: " + queryStr);
QueryParser queryParser = new QueryParser(FIELD_NAME, new StandardAnalyzer());
Query query = queryParser.parse(queryStr);
Hits multiSearcherHits = multiSearcher.search(query);
Hits singleSearcherHits = singleSearcher.search(query);
assertEquals(multiSearcherHits.length(), singleSearcherHits.length());
for (int i = 0; i < multiSearcherHits.length(); i++) {
Document docMulti = multiSearcherHits.doc(i);
Document docSingle = singleSearcherHits.doc(i);
if(verbose) System.out.println("Multi: " + docMulti.get(FIELD_NAME) + " score="
+ multiSearcherHits.score(i));
if(verbose) System.out.println("Single: " + docSingle.get(FIELD_NAME) + " score="
+ singleSearcherHits.score(i));
assertEquals(multiSearcherHits.score(i), singleSearcherHits.score(i),
0.001f);
assertEquals(docMulti.get(FIELD_NAME), docSingle.get(FIELD_NAME));
}
if(verbose) System.out.println();
|
protected void | setUp()initializes multiSearcher and singleSearcher with the same document set
// create MultiSearcher from two seperate searchers
Directory d1 = new RAMDirectory();
IndexWriter iw1 = new IndexWriter(d1, new StandardAnalyzer(), true);
addCollection1(iw1);
iw1.close();
Directory d2 = new RAMDirectory();
IndexWriter iw2 = new IndexWriter(d2, new StandardAnalyzer(), true);
addCollection2(iw2);
iw2.close();
Searchable[] s = new Searchable[2];
s[0] = new IndexSearcher(d1);
s[1] = new IndexSearcher(d2);
multiSearcher = new MultiSearcher(s);
// create IndexSearcher which contains all documents
Directory d = new RAMDirectory();
IndexWriter iw = new IndexWriter(d, new StandardAnalyzer(), true);
addCollection1(iw);
addCollection2(iw);
iw.close();
singleSearcher = new IndexSearcher(d);
|
public void | testFuzzyQuery()
checkQuery("multiThree~");
|
public void | testMultiPhraseQuery()
checkQuery("\"blueberry pi*\"");
|
public void | testNoMatchQuery()
checkQuery("+three +nomatch");
|
public void | testOneTermQuery()
checkQuery("three");
|
public void | testPrefixQuery()
checkQuery("multi*");
|
public void | testRangeQuery()
checkQuery("{multiA TO multiP}");
|
public void | testTwoTermQuery()
checkQuery("three foo");
|