Enable BoostingQuery with FVH highlighter (#19984)

* Enable BoostingQuery with FVH highlighter
* apply boost with negativeBoost
* flatten boosting query with its own boost and update boost query to a single layer
This commit is contained in:
chengpohi 2016-08-16 09:00:16 +08:00 committed by Nik Everett
parent a93af8651c
commit 2adc2a1971
2 changed files with 14 additions and 3 deletions

View File

@ -22,6 +22,8 @@ package org.apache.lucene.search.vectorhighlight;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.queries.BlendedTermQuery;
import org.apache.lucene.queries.BoostingQuery;
import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.ConstantScoreQuery;
import org.apache.lucene.search.MultiPhraseQuery;
import org.apache.lucene.search.PhraseQuery;
@ -56,7 +58,12 @@ public class CustomFieldQuery extends FieldQuery {
@Override
void flatten(Query sourceQuery, IndexReader reader, Collection<Query> flatQueries, float boost) throws IOException {
if (sourceQuery instanceof SpanTermQuery) {
if (sourceQuery instanceof BoostQuery) {
BoostQuery bq = (BoostQuery) sourceQuery;
sourceQuery = bq.getQuery();
boost *= bq.getBoost();
flatten(sourceQuery, reader, flatQueries, boost);
} else if (sourceQuery instanceof SpanTermQuery) {
super.flatten(new TermQuery(((SpanTermQuery) sourceQuery).getTerm()), reader, flatQueries, boost);
} else if (sourceQuery instanceof ConstantScoreQuery) {
flatten(((ConstantScoreQuery) sourceQuery).getQuery(), reader, flatQueries, boost);
@ -75,6 +82,12 @@ public class CustomFieldQuery extends FieldQuery {
} else if (sourceQuery instanceof ToParentBlockJoinQuery) {
ToParentBlockJoinQuery blockJoinQuery = (ToParentBlockJoinQuery) sourceQuery;
flatten(blockJoinQuery.getChildQuery(), reader, flatQueries, boost);
} else if (sourceQuery instanceof BoostingQuery) {
BoostingQuery boostingQuery = (BoostingQuery) sourceQuery;
//flatten positive query with query boost
flatten(boostingQuery.getMatch(), reader, flatQueries, boost);
//flatten negative query with negative boost
flatten(boostingQuery.getContext(), reader, flatQueries, boostingQuery.getBoost());
} else {
super.flatten(sourceQuery, reader, flatQueries, boost);
}

View File

@ -1400,7 +1400,6 @@ public class HighlighterSearchIT extends ESIntegTestCase {
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The quick <x>brown</x> fox jumps over the lazy dog"));
}
@AwaitsFix(bugUrl="Broken now that BoostingQuery does not extend BooleanQuery anymore")
public void testBoostingQueryTermVector() throws IOException {
assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping()));
ensureGreen();
@ -2643,7 +2642,6 @@ public class HighlighterSearchIT extends ESIntegTestCase {
}
}
@AwaitsFix(bugUrl="Broken now that BoostingQuery does not extend BooleanQuery anymore")
public void testFastVectorHighlighterPhraseBoost() throws Exception {
assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping()));
phraseBoostTestCase("fvh");