Hello,
I'm trying to understand the behavior of CustomScoreQuery. It seemed to me,
that default
CustomScoreQuery(Query subQuery, ValueSourceQuery valSrcQuery)
should return a score that is a product of subQuery score
and valSrcQuery score. So I wrote a simple test case given below:
@Test
public void createAndQueryIndex() throws CorruptIndexException,
LockObtainFailedException, IOException {
RAMDirectory dir = new RAMDirectory();
IndexWriter writer = new IndexWriter(dir,
new IndexWriterConfig(Version.LUCENE_35,
new StandardAnalyzer(
Version.LUCENE_35)));
Document doc = new Document();
doc.add(new Field("name", "name", Store.YES, Index.NOT_ANALYZED));
doc.add(new Field("ratio", "0.5", Store.YES, Index.NOT_ANALYZED));
writer.addDocument(doc);
writer.close();
IndexSearcher searcher = new IndexSearcher(IndexReader.open(dir));
Query matchAllDocs = new MatchAllDocsQuery();
float score1 = searcher.search(matchAllDocs,
1).scoreDocs[0].score;
Assert.assertEquals(1.0f, score1, 0);
ValueSourceQuery fieldScoreQuery = new FieldScoreQuery("ratio",
FieldScoreQuery.Type.FLOAT);
float score2 = searcher.search(fieldScoreQuery,
1).scoreDocs[0].score;
Assert.assertEquals(0.5f, score2, 0);
CustomScoreQuery csq = new CustomScoreQuery(matchAllDocs,
fieldScoreQuery);
float score3 = searcher.search(csq, 1).scoreDocs[0].score;
Assert.assertEquals(score1*score2, score3, 0);
searcher.close();
}
But this test fails in third assertion - score3 is 0.249. Can someone
explain why? How the score3 is computed in this case?
--
Regards
Dominika Puzio
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]