@Test
public void testKatta20SearchLimitMaxNumberOfHits() throws Exception {
deployTestIndices(1, getNodeCount());
final Query query = new QueryParser(Version.LUCENE_30, "", new KeywordAnalyzer()).parse("foo: bar");
ILuceneClient client = new LuceneClient(_miniCluster.getZkConfiguration());
final Hits expectedHits = client.search(query, new String[] { INDEX_NAME }, 4);
assertNotNull(expectedHits);
LOG.info("Expected hits:");
for (final Hit hit : expectedHits.getHits()) {
writeToLog(hit);
}
assertEquals(4, expectedHits.getHits().size());
for (int i = 0; i < 100; i++) {
// Now we redo the search, but limit the max number of hits. We expect the
// same ordering of hits.
for (int maxHits = 1; maxHits < expectedHits.size() + 1; maxHits++) {
final Hits hits = client.search(query, new String[] { INDEX_NAME }, maxHits);
assertNotNull(hits);
assertEquals(maxHits, hits.getHits().size());
for (int j = 0; j < hits.getHits().size(); j++) {
// writeToLog("expected: ", expectedHits.getHits().get(j));
// writeToLog("actual : ", hits.getHits().get(j));
assertEquals(expectedHits.getHits().get(j).getScore(), hits.getHits().get(j).getScore(), 0.0);
}
}
}
client.close();
}