mirror of https://github.com/apache/lucene.git
LUCENE-2936: PhraseQuery score explanations were not correctly identifying matches vs non-matches
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1074357 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b43011aef5
commit
6d1353bc59
|
@ -355,6 +355,9 @@ Bug fixes
|
||||||
with more document deletions is requested before a reader with fewer
|
with more document deletions is requested before a reader with fewer
|
||||||
deletions, provided they share some segments. (yonik)
|
deletions, provided they share some segments. (yonik)
|
||||||
|
|
||||||
|
* LUCENE-2936: PhraseQuery score explanations were not correctly
|
||||||
|
identifying matches vs non-matches. (hossman)
|
||||||
|
|
||||||
======================= Lucene 3.x (not yet released) =======================
|
======================= Lucene 3.x (not yet released) =======================
|
||||||
|
|
||||||
Changes in backwards compatibility policy
|
Changes in backwards compatibility policy
|
||||||
|
|
|
@ -224,7 +224,7 @@ public class PhraseQuery extends Query {
|
||||||
public Explanation explain(AtomicReaderContext context, int doc)
|
public Explanation explain(AtomicReaderContext context, int doc)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|
||||||
Explanation result = new Explanation();
|
ComplexExplanation result = new ComplexExplanation();
|
||||||
result.setDescription("weight("+getQuery()+" in "+doc+"), product of:");
|
result.setDescription("weight("+getQuery()+" in "+doc+"), product of:");
|
||||||
|
|
||||||
StringBuilder docFreqs = new StringBuilder();
|
StringBuilder docFreqs = new StringBuilder();
|
||||||
|
@ -303,10 +303,7 @@ public class PhraseQuery extends Query {
|
||||||
|
|
||||||
// combine them
|
// combine them
|
||||||
result.setValue(queryExpl.getValue() * fieldExpl.getValue());
|
result.setValue(queryExpl.getValue() * fieldExpl.getValue());
|
||||||
|
result.setMatch(tfExplanation.isMatch());
|
||||||
if (queryExpl.getValue() == 1.0f)
|
|
||||||
return fieldExpl;
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,8 @@ public class CheckHits {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that all documents up to maxDoc which are *not* in the
|
* Tests that all documents up to maxDoc which are *not* in the
|
||||||
* expected result set, have an explanation which indicates no match
|
* expected result set, have an explanation which indicates that
|
||||||
* (ie: Explanation value of 0.0f)
|
* the document does not match
|
||||||
*/
|
*/
|
||||||
public static void checkNoMatchExplanations(Query q, String defaultFieldName,
|
public static void checkNoMatchExplanations(Query q, String defaultFieldName,
|
||||||
IndexSearcher searcher, int[] results)
|
IndexSearcher searcher, int[] results)
|
||||||
|
@ -59,9 +59,9 @@ public class CheckHits {
|
||||||
Explanation exp = searcher.explain(q, doc);
|
Explanation exp = searcher.explain(q, doc);
|
||||||
Assert.assertNotNull("Explanation of [["+d+"]] for #"+doc+" is null",
|
Assert.assertNotNull("Explanation of [["+d+"]] for #"+doc+" is null",
|
||||||
exp);
|
exp);
|
||||||
Assert.assertEquals("Explanation of [["+d+"]] for #"+doc+
|
Assert.assertFalse("Explanation of [["+d+"]] for #"+doc+
|
||||||
" doesn't indicate non-match: " + exp.toString(),
|
" doesn't indicate non-match: " + exp.toString(),
|
||||||
0.0f, exp.getValue(), 0.0f);
|
exp.isMatch());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -484,6 +484,9 @@ public class CheckHits {
|
||||||
|
|
||||||
Assert.assertNotNull("Explanation of [["+d+"]] for #"+doc+" is null", exp);
|
Assert.assertNotNull("Explanation of [["+d+"]] for #"+doc+" is null", exp);
|
||||||
verifyExplanation(d,doc,scorer.score(),deep,exp);
|
verifyExplanation(d,doc,scorer.score(),deep,exp);
|
||||||
|
Assert.assertTrue("Explanation of [["+d+"]] for #"+ doc +
|
||||||
|
" does not indicate match: " + exp.toString(),
|
||||||
|
exp.isMatch());
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void setNextReader(AtomicReaderContext context) {
|
public void setNextReader(AtomicReaderContext context) {
|
||||||
|
|
|
@ -52,7 +52,10 @@ public class TestExplanations extends LuceneTestCase {
|
||||||
protected Directory directory;
|
protected Directory directory;
|
||||||
|
|
||||||
public static final String KEY = "KEY";
|
public static final String KEY = "KEY";
|
||||||
|
// boost on this field is the same as the iterator for the doc
|
||||||
public static final String FIELD = "field";
|
public static final String FIELD = "field";
|
||||||
|
// same contents, but no field boost
|
||||||
|
public static final String ALTFIELD = "alt";
|
||||||
public static final QueryParser qp =
|
public static final QueryParser qp =
|
||||||
new QueryParser(TEST_VERSION_CURRENT, FIELD, new MockAnalyzer());
|
new QueryParser(TEST_VERSION_CURRENT, FIELD, new MockAnalyzer());
|
||||||
|
|
||||||
|
@ -72,7 +75,10 @@ public class TestExplanations extends LuceneTestCase {
|
||||||
for (int i = 0; i < docFields.length; i++) {
|
for (int i = 0; i < docFields.length; i++) {
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
doc.add(newField(KEY, ""+i, Field.Store.NO, Field.Index.NOT_ANALYZED));
|
doc.add(newField(KEY, ""+i, Field.Store.NO, Field.Index.NOT_ANALYZED));
|
||||||
doc.add(newField(FIELD, docFields[i], Field.Store.NO, Field.Index.ANALYZED));
|
Field f = newField(FIELD, docFields[i], Field.Store.NO, Field.Index.ANALYZED);
|
||||||
|
f.setBoost(i);
|
||||||
|
doc.add(f);
|
||||||
|
doc.add(newField(ALTFIELD, docFields[i], Field.Store.NO, Field.Index.ANALYZED));
|
||||||
writer.addDocument(doc);
|
writer.addDocument(doc);
|
||||||
}
|
}
|
||||||
reader = writer.getReader();
|
reader = writer.getReader();
|
||||||
|
|
|
@ -289,4 +289,62 @@ public class TestSimpleExplanations extends TestExplanations {
|
||||||
qtest(q, new int[] { 0,3 });
|
qtest(q, new int[] { 0,3 });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* BQ of TQ: using alt so some fields have zero boost and some don't */
|
||||||
|
|
||||||
|
public void testMultiFieldBQ1() throws Exception {
|
||||||
|
qtest("+w1 +alt:w2", new int[] { 0,1,2,3 });
|
||||||
|
}
|
||||||
|
public void testMultiFieldBQ2() throws Exception {
|
||||||
|
qtest("+yy +alt:w3", new int[] { 2,3 });
|
||||||
|
}
|
||||||
|
public void testMultiFieldBQ3() throws Exception {
|
||||||
|
qtest("yy +alt:w3", new int[] { 0,1,2,3 });
|
||||||
|
}
|
||||||
|
public void testMultiFieldBQ4() throws Exception {
|
||||||
|
qtest("w1 (-xx alt:w2)", new int[] { 0,1,2,3 });
|
||||||
|
}
|
||||||
|
public void testMultiFieldBQ5() throws Exception {
|
||||||
|
qtest("w1 (+alt:qq alt:w2)", new int[] { 0,1,2,3 });
|
||||||
|
}
|
||||||
|
public void testMultiFieldBQ6() throws Exception {
|
||||||
|
qtest("w1 -(-alt:qq alt:w5)", new int[] { 1,2,3 });
|
||||||
|
}
|
||||||
|
public void testMultiFieldBQ7() throws Exception {
|
||||||
|
qtest("+w1 +(alt:qq (alt:xx -alt:w2) (+alt:w3 +alt:w4))", new int[] { 0 });
|
||||||
|
}
|
||||||
|
public void testMultiFieldBQ8() throws Exception {
|
||||||
|
qtest("+alt:w1 (qq (alt:xx -w2) (+alt:w3 +w4))", new int[] { 0,1,2,3 });
|
||||||
|
}
|
||||||
|
public void testMultiFieldBQ9() throws Exception {
|
||||||
|
qtest("+w1 (alt:qq (-xx w2) -(+alt:w3 +w4))", new int[] { 0,1,2,3 });
|
||||||
|
}
|
||||||
|
public void testMultiFieldBQ10() throws Exception {
|
||||||
|
qtest("+w1 +(alt:qq (-xx alt:w2) -(+alt:w3 +w4))", new int[] { 1 });
|
||||||
|
}
|
||||||
|
|
||||||
|
/* BQ of PQ: using alt so some fields have zero boost and some don't */
|
||||||
|
|
||||||
|
public void testMultiFieldBQofPQ1() throws Exception {
|
||||||
|
qtest("\"w1 w2\" alt:\"w1 w2\"", new int[] { 0 });
|
||||||
|
}
|
||||||
|
public void testMultiFieldBQofPQ2() throws Exception {
|
||||||
|
qtest("\"w1 w3\" alt:\"w1 w3\"", new int[] { 1,3 });
|
||||||
|
}
|
||||||
|
public void testMultiFieldBQofPQ3() throws Exception {
|
||||||
|
qtest("\"w1 w2\"~1 alt:\"w1 w2\"~1", new int[] { 0,1,2 });
|
||||||
|
}
|
||||||
|
public void testMultiFieldBQofPQ4() throws Exception {
|
||||||
|
qtest("\"w2 w3\"~1 alt:\"w2 w3\"~1", new int[] { 0,1,2,3 });
|
||||||
|
}
|
||||||
|
public void testMultiFieldBQofPQ5() throws Exception {
|
||||||
|
qtest("\"w3 w2\"~1 alt:\"w3 w2\"~1", new int[] { 1,3 });
|
||||||
|
}
|
||||||
|
public void testMultiFieldBQofPQ6() throws Exception {
|
||||||
|
qtest("\"w3 w2\"~2 alt:\"w3 w2\"~2", new int[] { 0,1,3 });
|
||||||
|
}
|
||||||
|
public void testMultiFieldBQofPQ7() throws Exception {
|
||||||
|
qtest("\"w3 w2\"~3 alt:\"w3 w2\"~3", new int[] { 0,1,2,3 });
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue