The p/c queries must always be wrapped in a CustomQueryWrappingFilter in fquery parser.
Also made assertions more descriptive when failing.
This commit is contained in:
parent
bdfb59aa00
commit
73383e2014
|
@ -23,6 +23,7 @@ import org.apache.lucene.search.Filter;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
import org.apache.lucene.search.QueryWrapperFilter;
|
import org.apache.lucene.search.QueryWrapperFilter;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
|
import org.elasticsearch.index.search.child.CustomQueryWrappingFilter;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -48,6 +49,10 @@ public class QueryFilterParser implements FilterParser {
|
||||||
if (query == null) {
|
if (query == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new QueryWrapperFilter(query);
|
if (CustomQueryWrappingFilter.shouldUseCustomQueryWrappingFilter(query)) {
|
||||||
|
return new CustomQueryWrappingFilter(query);
|
||||||
|
} else {
|
||||||
|
return new QueryWrapperFilter(query);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -95,7 +95,7 @@ public class ChildrenConstantScoreQuery extends Query {
|
||||||
if (rewrittenChildQuery == null) {
|
if (rewrittenChildQuery == null) {
|
||||||
childQuery = rewrittenChildQuery = searcher.rewrite(originalChildQuery);
|
childQuery = rewrittenChildQuery = searcher.rewrite(originalChildQuery);
|
||||||
} else {
|
} else {
|
||||||
assert rewriteIndexReader == searcher.getIndexReader();
|
assert rewriteIndexReader == searcher.getIndexReader() : "not equal, rewriteIndexReader=" + rewriteIndexReader + " searcher.getIndexReader()=" + searcher.getIndexReader();
|
||||||
childQuery = rewrittenChildQuery;
|
childQuery = rewrittenChildQuery;
|
||||||
}
|
}
|
||||||
IndexSearcher indexSearcher = new IndexSearcher(searcher.getIndexReader());
|
IndexSearcher indexSearcher = new IndexSearcher(searcher.getIndexReader());
|
||||||
|
|
|
@ -142,7 +142,7 @@ public class ChildrenQuery extends Query {
|
||||||
if (rewrittenChildQuery == null) {
|
if (rewrittenChildQuery == null) {
|
||||||
childQuery = rewrittenChildQuery = searcher.rewrite(originalChildQuery);
|
childQuery = rewrittenChildQuery = searcher.rewrite(originalChildQuery);
|
||||||
} else {
|
} else {
|
||||||
assert rewriteIndexReader == searcher.getIndexReader();
|
assert rewriteIndexReader == searcher.getIndexReader() : "not equal, rewriteIndexReader=" + rewriteIndexReader + " searcher.getIndexReader()=" + searcher.getIndexReader();
|
||||||
childQuery = rewrittenChildQuery;
|
childQuery = rewrittenChildQuery;
|
||||||
}
|
}
|
||||||
IndexSearcher indexSearcher = new IndexSearcher(searcher.getIndexReader());
|
IndexSearcher indexSearcher = new IndexSearcher(searcher.getIndexReader());
|
||||||
|
|
|
@ -121,4 +121,15 @@ public class CustomQueryWrappingFilter extends NoCacheFilter implements Releasab
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return query.hashCode() ^ 0x823D64C9;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class ParentConstantScoreQuery extends Query {
|
||||||
if (rewrittenParentQuery != null) {
|
if (rewrittenParentQuery != null) {
|
||||||
parentQuery = rewrittenParentQuery;
|
parentQuery = rewrittenParentQuery;
|
||||||
} else {
|
} else {
|
||||||
assert rewriteIndexReader == searcher.getIndexReader();
|
assert rewriteIndexReader == searcher.getIndexReader() : "not equal, rewriteIndexReader=" + rewriteIndexReader + " searcher.getIndexReader()=" + searcher.getIndexReader();
|
||||||
parentQuery = rewrittenParentQuery = originalParentQuery.rewrite(searcher.getIndexReader());
|
parentQuery = rewrittenParentQuery = originalParentQuery.rewrite(searcher.getIndexReader());
|
||||||
}
|
}
|
||||||
IndexSearcher indexSearcher = new IndexSearcher(searcher.getIndexReader());
|
IndexSearcher indexSearcher = new IndexSearcher(searcher.getIndexReader());
|
||||||
|
|
|
@ -129,7 +129,7 @@ public class ParentQuery extends Query {
|
||||||
if (rewrittenParentQuery == null) {
|
if (rewrittenParentQuery == null) {
|
||||||
parentQuery = rewrittenParentQuery = searcher.rewrite(originalParentQuery);
|
parentQuery = rewrittenParentQuery = searcher.rewrite(originalParentQuery);
|
||||||
} else {
|
} else {
|
||||||
assert rewriteIndexReader == searcher.getIndexReader();
|
assert rewriteIndexReader == searcher.getIndexReader() : "not equal, rewriteIndexReader=" + rewriteIndexReader + " searcher.getIndexReader()=" + searcher.getIndexReader();
|
||||||
parentQuery = rewrittenParentQuery;
|
parentQuery = rewrittenParentQuery;
|
||||||
}
|
}
|
||||||
IndexSearcher indexSearcher = new IndexSearcher(searcher.getIndexReader());
|
IndexSearcher indexSearcher = new IndexSearcher(searcher.getIndexReader());
|
||||||
|
|
Loading…
Reference in New Issue