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:
Martijn van Groningen 2014-03-14 14:12:05 +07:00
parent bdfb59aa00
commit 73383e2014
6 changed files with 21 additions and 5 deletions

View File

@ -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);
}
}
}

View File

@ -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());

View File

@ -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());

View File

@ -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;
}
}
}

View File

@ -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());

View File

@ -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());