use of io.anserini.search.SimpleSearcher in project Anserini by castorini.
the class IndexReaderUtilsTest method testComputeQueryDocumentScore.
@Test
public void testComputeQueryDocumentScore() throws Exception {
SimpleSearcher searcher = new SimpleSearcher(tempDir1.toString());
Directory dir = FSDirectory.open(tempDir1);
IndexReader reader = DirectoryReader.open(dir);
Similarity similarity = new BM25Similarity(0.9f, 0.4f);
// A bunch of test queries...
String[] queries = { "text city", "text", "city" };
for (String query : queries) {
SimpleSearcher.Result[] results = searcher.search(query);
// Strategy is to loop over the results, compute query-document score individually, and compare.
for (int i = 0; i < results.length; i++) {
float score = IndexReaderUtils.computeQueryDocumentScoreWithSimilarity(reader, results[i].docid, query, similarity);
assertEquals(score, results[i].score, 10e-5);
}
// This is hard coded - doc3 isn't retrieved by any of the queries.
assertEquals(0.0f, IndexReaderUtils.computeQueryDocumentScoreWithSimilarity(reader, "doc3", query, similarity), 10e-6);
}
reader.close();
dir.close();
}
Aggregations