mirror of https://github.com/apache/lucene.git
Fix Slop Issue in MultiFieldQueryParser (#12196)
In Lucene 5.4.0 62313b83ba9c69379e1f84dffc881a361713ce9 introduced some changes for immutability of queries. setBoost() function was replaced with new BoostQuery(), but BoostQuery is not handled in setSlop function. This commit adds the handling of BoostQuery in setSlop() function.
This commit is contained in:
parent
0651d25713
commit
96efb34d00
|
@ -162,6 +162,8 @@ Bug Fixes
|
|||
|
||||
* GITHUB#12158: KeywordField#newSetQuery should clone input BytesRef[] to avoid modifying provided array. (Greg Miller)
|
||||
|
||||
* GITHUB#12196: Fix MultiFieldQueryParser to handle both query boost and phrase slop at the same time. (Jasir KT)
|
||||
|
||||
Build
|
||||
---------------------
|
||||
|
||||
|
|
|
@ -124,6 +124,10 @@ public class MultiFieldQueryParser extends QueryParser {
|
|||
if (slop != mpq.getSlop()) {
|
||||
q = new MultiPhraseQuery.Builder(mpq).setSlop(slop).build();
|
||||
}
|
||||
} else if (q instanceof BoostQuery boostQuery) {
|
||||
Query subQuery = boostQuery.getQuery();
|
||||
subQuery = applySlop(subQuery, slop);
|
||||
q = new BoostQuery(subQuery, boostQuery.getBoost());
|
||||
}
|
||||
return q;
|
||||
}
|
||||
|
|
|
@ -156,6 +156,11 @@ public class TestMultiFieldQueryParser extends LuceneTestCase {
|
|||
q = mfqp.parse("one AND two AND foo:test");
|
||||
assertEquals("+((b:one)^5.0 (t:one)^10.0) +((b:two)^5.0 (t:two)^10.0) +foo:test", q.toString());
|
||||
|
||||
// Check boost with slop
|
||||
// See https://github.com/apache/lucene/issues/12195
|
||||
q = mfqp.parse("\"one two\"~2");
|
||||
assertEquals("(b:\"one two\"~2)^5.0 (t:\"one two\"~2)^10.0", q.toString());
|
||||
|
||||
q = mfqp.parse("one^3 AND two^4");
|
||||
assertEquals("+((b:one)^5.0 (t:one)^10.0)^3.0 +((b:two)^5.0 (t:two)^10.0)^4.0", q.toString());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue