Hello,
Have a question about default PhraseQuery boost processing. The
Query.setBoost()
<http://lucene.apache.org/core/4_4_0/core/org/apache/lucene/search/Query.html#setBoost(float)>
says:
/
Sets the boost for this query clause to b. Documents matching this clause
will (in addition to the normal weightings) have their score multiplied by b
/
However, that's not true for /PhraseQuery/. Example:
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.Version;
import java.io.IOException;
public class Test {
public static void main(String[] args) throws IOException {
RAMDirectory dir = new RAMDirectory();
Version version = Version.LUCENE_44;
try (IndexWriter writer = new IndexWriter(dir, new
IndexWriterConfig(version, new StandardAnalyzer(version)))) {
Document document = new Document();
document.add(new TextField("data", "1 2 3", Field.Store.YES));
writer.addDocument(document);
}
IndexSearcher searcher = new
IndexSearcher(DirectoryReader.open(dir));
search(searcher, 1);
search(searcher, 5);
}
private static void search(IndexSearcher searcher, float boost) throws
IOException {
PhraseQuery query = new PhraseQuery();
query.add(new Term("data", "2"));
query.add(new Term("data", "3"));
query.setBoost(boost);
TopDocs hits = searcher.search(query, 1);
assert hits != null && hits.scoreDocs.length == 1;
ScoreDoc doc = hits.scoreDocs[0];
System.out.printf("Boost %g, score %g:%n%s%n", boost, doc.score,
searcher.explain(query, doc.doc));
}
}
*Output:*
/
Boost 1.00000, score 0.306853:
0.30685282 = (MATCH) weight(data:"2 3" in 0) [DefaultSimilarity], result of:
0.30685282 = fieldWeight in 0, product of:
1.0 = tf(freq=1.0), with freq of:
1.0 = phraseFreq=1.0
0.61370564 = idf(), sum of:
0.30685282 = idf(docFreq=1, maxDocs=1)
0.30685282 = idf(docFreq=1, maxDocs=1)
0.5 = fieldNorm(doc=0)
Boost 5.00000, score 0.306853:
0.30685282 = (MATCH) weight(data:"2 3"^5.0 in 0) [DefaultSimilarity], result
of:
0.30685282 = fieldWeight in 0, product of:
1.0 = tf(freq=1.0), with freq of:
1.0 = phraseFreq=1.0
0.61370564 = idf(), sum of:
0.30685282 = idf(docFreq=1, maxDocs=1)
0.30685282 = idf(docFreq=1, maxDocs=1)
0.5 = fieldNorm(doc=0)
/
I.e. resulting ScoreDoc.score is the same for boosted and non-boosted query.
I see that that contradicts to the /Query.setBoost()/ contract. Did I miss
something?
--
View this message in context:
http://lucene.472066.n3.nabble.com/PhraseQuery-boost-doesn-t-affect-ScoreDoc-score-tp4095791.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]