From 805437b8bca6cdd3f07e1aa848fa3b31a2a29fd3 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Fri, 22 Sep 2017 16:39:38 +0200 Subject: [PATCH] percolator: Also support query extraction for queries wrapped inside a ESToParentBlockJoinQuery --- .../elasticsearch/percolator/QueryAnalyzer.java | 10 ++++++++++ .../percolator/QueryAnalyzerTests.java | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/modules/percolator/src/main/java/org/elasticsearch/percolator/QueryAnalyzer.java b/modules/percolator/src/main/java/org/elasticsearch/percolator/QueryAnalyzer.java index 21b79cf2980..8c2a6d7a455 100644 --- a/modules/percolator/src/main/java/org/elasticsearch/percolator/QueryAnalyzer.java +++ b/modules/percolator/src/main/java/org/elasticsearch/percolator/QueryAnalyzer.java @@ -47,6 +47,7 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.NumericUtils; import org.elasticsearch.common.logging.LoggerMessageFormat; import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery; +import org.elasticsearch.index.search.ESToParentBlockJoinQuery; import java.util.ArrayList; import java.util.Arrays; @@ -88,6 +89,7 @@ final class QueryAnalyzer { map.put(FunctionScoreQuery.class, functionScoreQuery()); map.put(PointRangeQuery.class, pointRangeQuery()); map.put(IndexOrDocValuesQuery.class, indexOrDocValuesQuery()); + map.put(ESToParentBlockJoinQuery.class, toParentBlockJoinQuery()); queryProcessors = Collections.unmodifiableMap(map); } @@ -390,6 +392,14 @@ final class QueryAnalyzer { }; } + private static BiFunction, Result> toParentBlockJoinQuery() { + return (query, boosts) -> { + ESToParentBlockJoinQuery toParentBlockJoinQuery = (ESToParentBlockJoinQuery) query; + Result result = analyze(toParentBlockJoinQuery.getChildQuery(), boosts); + return new Result(false, result.extractions); + }; + } + private static Result handleDisjunction(List disjunctions, int minimumShouldMatch, boolean otherClauses, Map boosts) { boolean verified = minimumShouldMatch <= 1 && otherClauses == false; diff --git a/modules/percolator/src/test/java/org/elasticsearch/percolator/QueryAnalyzerTests.java b/modules/percolator/src/test/java/org/elasticsearch/percolator/QueryAnalyzerTests.java index ff70c664460..a6af5fb9dfe 100644 --- a/modules/percolator/src/test/java/org/elasticsearch/percolator/QueryAnalyzerTests.java +++ b/modules/percolator/src/test/java/org/elasticsearch/percolator/QueryAnalyzerTests.java @@ -44,6 +44,8 @@ import org.apache.lucene.search.SynonymQuery; import org.apache.lucene.search.TermInSetQuery; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TermRangeQuery; +import org.apache.lucene.search.join.QueryBitSetProducer; +import org.apache.lucene.search.join.ScoreMode; import org.apache.lucene.search.spans.SpanFirstQuery; import org.apache.lucene.search.spans.SpanNearQuery; import org.apache.lucene.search.spans.SpanNotQuery; @@ -54,6 +56,7 @@ import org.elasticsearch.common.lucene.search.function.CombineFunction; import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery; import org.elasticsearch.common.lucene.search.function.RandomScoreFunction; import org.elasticsearch.common.network.InetAddresses; +import org.elasticsearch.index.search.ESToParentBlockJoinQuery; import org.elasticsearch.percolator.QueryAnalyzer.QueryExtraction; import org.elasticsearch.percolator.QueryAnalyzer.Result; import org.elasticsearch.test.ESTestCase; @@ -788,6 +791,17 @@ public class QueryAnalyzerTests extends ESTestCase { assertDimension(ranges.get(0).range.upperPoint, bytes -> IntPoint.encodeDimension(20, bytes, 0)); } + public void testToParentBlockJoinQuery() { + TermQuery termQuery = new TermQuery(new Term("field", "value")); + QueryBitSetProducer queryBitSetProducer = new QueryBitSetProducer(new TermQuery(new Term("_type", "child"))); + ESToParentBlockJoinQuery query = new ESToParentBlockJoinQuery(termQuery, queryBitSetProducer, ScoreMode.None, "child"); + Result result = analyze(query, Collections.emptyMap()); + assertFalse(result.verified); + assertEquals(1, result.extractions.size()); + assertNull(result.extractions.toArray(new QueryExtraction[0])[0].range); + assertEquals(new Term("field", "value"), result.extractions.toArray(new QueryExtraction[0])[0].term); + } + public void testPointRangeQuerySelectShortestRange() { BooleanQuery.Builder boolQuery = new BooleanQuery.Builder(); boolQuery.add(LongPoint.newRangeQuery("_field1", 10, 20), BooleanClause.Occur.FILTER);