From 73383e201431cff19a278925eef630a2db2d6f51 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Fri, 14 Mar 2014 14:12:05 +0700 Subject: [PATCH] The p/c queries must always be wrapped in a CustomQueryWrappingFilter in fquery parser. Also made assertions more descriptive when failing. --- .../elasticsearch/index/query/QueryFilterParser.java | 7 ++++++- .../search/child/ChildrenConstantScoreQuery.java | 2 +- .../index/search/child/ChildrenQuery.java | 2 +- .../index/search/child/CustomQueryWrappingFilter.java | 11 +++++++++++ .../index/search/child/ParentConstantScoreQuery.java | 2 +- .../elasticsearch/index/search/child/ParentQuery.java | 2 +- 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/query/QueryFilterParser.java b/src/main/java/org/elasticsearch/index/query/QueryFilterParser.java index bdc09dbee78..57671f78a6d 100644 --- a/src/main/java/org/elasticsearch/index/query/QueryFilterParser.java +++ b/src/main/java/org/elasticsearch/index/query/QueryFilterParser.java @@ -23,6 +23,7 @@ import org.apache.lucene.search.Filter; import org.apache.lucene.search.Query; import org.apache.lucene.search.QueryWrapperFilter; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.index.search.child.CustomQueryWrappingFilter; import java.io.IOException; @@ -48,6 +49,10 @@ public class QueryFilterParser implements FilterParser { if (query == null) { return null; } - return new QueryWrapperFilter(query); + if (CustomQueryWrappingFilter.shouldUseCustomQueryWrappingFilter(query)) { + return new CustomQueryWrappingFilter(query); + } else { + return new QueryWrapperFilter(query); + } } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQuery.java b/src/main/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQuery.java index 2cd72e6e659..be692663e3c 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQuery.java @@ -95,7 +95,7 @@ public class ChildrenConstantScoreQuery extends Query { if (rewrittenChildQuery == null) { childQuery = rewrittenChildQuery = searcher.rewrite(originalChildQuery); } else { - assert rewriteIndexReader == searcher.getIndexReader(); + assert rewriteIndexReader == searcher.getIndexReader() : "not equal, rewriteIndexReader=" + rewriteIndexReader + " searcher.getIndexReader()=" + searcher.getIndexReader(); childQuery = rewrittenChildQuery; } IndexSearcher indexSearcher = new IndexSearcher(searcher.getIndexReader()); diff --git a/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java b/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java index 45b35790c9d..c7549b9cc42 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java @@ -142,7 +142,7 @@ public class ChildrenQuery extends Query { if (rewrittenChildQuery == null) { childQuery = rewrittenChildQuery = searcher.rewrite(originalChildQuery); } else { - assert rewriteIndexReader == searcher.getIndexReader(); + assert rewriteIndexReader == searcher.getIndexReader() : "not equal, rewriteIndexReader=" + rewriteIndexReader + " searcher.getIndexReader()=" + searcher.getIndexReader(); childQuery = rewrittenChildQuery; } IndexSearcher indexSearcher = new IndexSearcher(searcher.getIndexReader()); diff --git a/src/main/java/org/elasticsearch/index/search/child/CustomQueryWrappingFilter.java b/src/main/java/org/elasticsearch/index/search/child/CustomQueryWrappingFilter.java index 6baba6f29d1..d9c1318c818 100644 --- a/src/main/java/org/elasticsearch/index/search/child/CustomQueryWrappingFilter.java +++ b/src/main/java/org/elasticsearch/index/search/child/CustomQueryWrappingFilter.java @@ -121,4 +121,15 @@ public class CustomQueryWrappingFilter extends NoCacheFilter implements Releasab public int hashCode() { return query.hashCode() ^ 0x823D64C9; } + + /** @return Whether {@link CustomQueryWrappingFilter} should be used. */ + public static boolean shouldUseCustomQueryWrappingFilter(Query query) { + if (query instanceof TopChildrenQuery || query instanceof ChildrenConstantScoreQuery + || query instanceof ChildrenQuery || query instanceof ParentConstantScoreQuery + || query instanceof ParentQuery) { + return true; + } else { + return false; + } + } } diff --git a/src/main/java/org/elasticsearch/index/search/child/ParentConstantScoreQuery.java b/src/main/java/org/elasticsearch/index/search/child/ParentConstantScoreQuery.java index 8d5c27b1fde..6e08418fcd6 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ParentConstantScoreQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/ParentConstantScoreQuery.java @@ -85,7 +85,7 @@ public class ParentConstantScoreQuery extends Query { if (rewrittenParentQuery != null) { parentQuery = rewrittenParentQuery; } else { - assert rewriteIndexReader == searcher.getIndexReader(); + assert rewriteIndexReader == searcher.getIndexReader() : "not equal, rewriteIndexReader=" + rewriteIndexReader + " searcher.getIndexReader()=" + searcher.getIndexReader(); parentQuery = rewrittenParentQuery = originalParentQuery.rewrite(searcher.getIndexReader()); } IndexSearcher indexSearcher = new IndexSearcher(searcher.getIndexReader()); diff --git a/src/main/java/org/elasticsearch/index/search/child/ParentQuery.java b/src/main/java/org/elasticsearch/index/search/child/ParentQuery.java index 53e80bbddae..00ccf5e7230 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ParentQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/ParentQuery.java @@ -129,7 +129,7 @@ public class ParentQuery extends Query { if (rewrittenParentQuery == null) { parentQuery = rewrittenParentQuery = searcher.rewrite(originalParentQuery); } else { - assert rewriteIndexReader == searcher.getIndexReader(); + assert rewriteIndexReader == searcher.getIndexReader() : "not equal, rewriteIndexReader=" + rewriteIndexReader + " searcher.getIndexReader()=" + searcher.getIndexReader(); parentQuery = rewrittenParentQuery; } IndexSearcher indexSearcher = new IndexSearcher(searcher.getIndexReader());