lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominika Puzio <dominika.pu...@gmail.com>
Subject Question about CustomScoreQuery
Date Thu, 16 Feb 2012 20:32:40 GMT
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: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message