Skip to content

Commit

Permalink
fixup! use BooleanFilter instead of BooleanQuery to pre-filter in arr…
Browse files Browse the repository at this point in the history
…ay equals case
  • Loading branch information
mfussenegger committed Feb 9, 2015
1 parent e13e690 commit a96f9c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion sql/src/main/java/io/crate/lucene/LuceneQueryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ private Filter genericFunctionFilter(Function function) {
for (LuceneCollectorExpression expression : expressions) {
expression.startCollect(collectorContext);
}
return new Filter() {
Filter filter = new Filter() {
@Override
public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException {
for (LuceneCollectorExpression expression : expressions) {
Expand All @@ -919,6 +919,7 @@ public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws
);
}
};
return indexCache.filter().cache(filter);
}

private Query genericFunctionQuery(Function function) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.lucene.search.MatchNoDocsQuery;
import org.elasticsearch.common.lucene.search.XConstantScoreQuery;
import org.elasticsearch.index.cache.IndexCache;
import org.elasticsearch.search.internal.SearchContext;
import org.junit.Before;
Expand Down Expand Up @@ -103,7 +104,11 @@ public void testEqOnTwoArraysBecomesGenericFunctionQuery() throws Exception {
FilteredQuery filteredQuery = (FilteredQuery) query;

assertThat(filteredQuery.getFilter(), instanceOf(BooleanFilter.class));
assertThat(filteredQuery.getQuery(), instanceOf(FilteredQuery.class));
assertThat(filteredQuery.getQuery(), instanceOf(XConstantScoreQuery.class));

BooleanFilter filter = (BooleanFilter) filteredQuery.getFilter();
assertThat(filter.clauses().get(0).getFilter(), instanceOf(BooleanFilter.class)); // booleanFilter with terms filter
assertThat(filter.clauses().get(1).getFilter(), instanceOf(Filter.class)); // generic function filter
}

@Test
Expand Down

0 comments on commit a96f9c1

Please sign in to comment.