properly handle cases where filter returns null docIdSet with and/or/not filters
This commit is contained in:
parent
5cc943c7db
commit
8e027b3baf
|
@ -53,6 +53,9 @@ public class AndFilter extends Filter {
|
|||
boolean allAreDocSet = true;
|
||||
for (Filter filter : filters) {
|
||||
DocIdSet set = filter.getDocIdSet(reader);
|
||||
if (set == null) { // none matching for this filter, we AND, so return EMPTY
|
||||
return DocSet.EMPTY_DOC_SET;
|
||||
}
|
||||
if (!(set instanceof DocSet)) {
|
||||
allAreDocSet = false;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.common.lucene.search;
|
|||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.search.DocIdSet;
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.elasticsearch.common.lucene.docset.AllDocSet;
|
||||
import org.elasticsearch.common.lucene.docset.DocSet;
|
||||
import org.elasticsearch.common.lucene.docset.NotDocIdSet;
|
||||
import org.elasticsearch.common.lucene.docset.NotDocSet;
|
||||
|
@ -45,6 +46,9 @@ public class NotFilter extends Filter {
|
|||
|
||||
@Override public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
|
||||
DocIdSet set = filter.getDocIdSet(reader);
|
||||
if (set == null) {
|
||||
return new AllDocSet(reader.maxDoc());
|
||||
}
|
||||
if (set instanceof DocSet) {
|
||||
return new NotDocSet((DocSet) set, reader.maxDoc());
|
||||
}
|
||||
|
|
|
@ -53,11 +53,20 @@ public class OrFilter extends Filter {
|
|||
boolean allAreDocSet = true;
|
||||
for (Filter filter : filters) {
|
||||
DocIdSet set = filter.getDocIdSet(reader);
|
||||
if (set == null) { // none matching for this filter, continue
|
||||
continue;
|
||||
}
|
||||
if (!(set instanceof DocSet)) {
|
||||
allAreDocSet = false;
|
||||
}
|
||||
sets.add(set);
|
||||
}
|
||||
if (sets.size() == 0) {
|
||||
return DocSet.EMPTY_DOC_SET;
|
||||
}
|
||||
if (sets.size() == 1) {
|
||||
return (DocIdSet) sets.get(0);
|
||||
}
|
||||
if (allAreDocSet) {
|
||||
return new OrDocSet(sets);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue