diff --git a/core/src/main/java/org/apache/lucene/search/vectorhighlight/CustomFieldQuery.java b/core/src/main/java/org/apache/lucene/search/vectorhighlight/CustomFieldQuery.java index e455340e3a0..88b045d2a5e 100644 --- a/core/src/main/java/org/apache/lucene/search/vectorhighlight/CustomFieldQuery.java +++ b/core/src/main/java/org/apache/lucene/search/vectorhighlight/CustomFieldQuery.java @@ -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 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); } diff --git a/core/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java b/core/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java index c7a5fc241ab..33e8cb3784f 100644 --- a/core/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java +++ b/core/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java @@ -1400,7 +1400,6 @@ public class HighlighterSearchIT extends ESIntegTestCase { assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The quick brown 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");