And/Or Filter: Possible failure when inner filter does not match any docs, closes #892.

This commit is contained in:
kimchy 2011-04-29 21:45:00 +03:00
parent 413cbf1713
commit fcdd2ba11c
4 changed files with 30 additions and 6 deletions

View File

@ -60,12 +60,21 @@ public class AndDocIdSet extends DocIdSet {
iterators = new DocIdSetIterator[sets.size()]; iterators = new DocIdSetIterator[sets.size()];
int j = 0; int j = 0;
for (DocIdSet set : sets) { for (DocIdSet set : sets) {
if (set != null) { if (set == null) {
lastReturn = DocIdSetIterator.NO_MORE_DOCS; // non matching
break;
} else {
DocIdSetIterator dcit = set.iterator(); DocIdSetIterator dcit = set.iterator();
if (dcit == null) {
lastReturn = DocIdSetIterator.NO_MORE_DOCS; // non matching
break;
}
iterators[j++] = dcit; iterators[j++] = dcit;
} }
} }
lastReturn = (iterators.length > 0 ? -1 : DocIdSetIterator.NO_MORE_DOCS); if (lastReturn != DocIdSetIterator.NO_MORE_DOCS) {
lastReturn = (iterators.length > 0 ? -1 : DocIdSetIterator.NO_MORE_DOCS);
}
} }
@Override @Override

View File

@ -75,12 +75,21 @@ public class AndDocSet extends DocSet {
iterators = new DocIdSetIterator[sets.size()]; iterators = new DocIdSetIterator[sets.size()];
int j = 0; int j = 0;
for (DocIdSet set : sets) { for (DocIdSet set : sets) {
if (set != null) { if (set == null) {
lastReturn = DocIdSetIterator.NO_MORE_DOCS; // non matching
break;
} else {
DocIdSetIterator dcit = set.iterator(); DocIdSetIterator dcit = set.iterator();
if (dcit == null) {
lastReturn = DocIdSetIterator.NO_MORE_DOCS; // non matching
break;
}
iterators[j++] = dcit; iterators[j++] = dcit;
} }
} }
lastReturn = (iterators.length > 0 ? -1 : DocIdSetIterator.NO_MORE_DOCS); if (lastReturn != DocIdSetIterator.NO_MORE_DOCS) {
lastReturn = (iterators.length > 0 ? -1 : DocIdSetIterator.NO_MORE_DOCS);
}
} }
@Override @Override

View File

@ -73,7 +73,10 @@ public class OrDocIdSet extends DocIdSet {
_heap = new Item[sets.size()]; _heap = new Item[sets.size()];
_size = 0; _size = 0;
for (DocIdSet set : sets) { for (DocIdSet set : sets) {
_heap[_size++] = new Item(set.iterator()); DocIdSetIterator iterator = set.iterator();
if (iterator != null) {
_heap[_size++] = new Item(iterator);
}
} }
if (_size == 0) _curDoc = DocIdSetIterator.NO_MORE_DOCS; if (_size == 0) _curDoc = DocIdSetIterator.NO_MORE_DOCS;
} }

View File

@ -88,7 +88,10 @@ public class OrDocSet extends DocSet {
_heap = new Item[sets.size()]; _heap = new Item[sets.size()];
_size = 0; _size = 0;
for (DocIdSet set : sets) { for (DocIdSet set : sets) {
_heap[_size++] = new Item(set.iterator()); DocIdSetIterator iterator = set.iterator();
if (iterator != null) {
_heap[_size++] = new Item(iterator);
}
} }
if (_size == 0) _curDoc = DocIdSetIterator.NO_MORE_DOCS; if (_size == 0) _curDoc = DocIdSetIterator.NO_MORE_DOCS;
} }