lucene 4: Upgraded AndFilter, FilteredCollector, LimitFilter, MatchAllDocsFilter and MatchNoDocsFilter.

This commit is contained in:
Martijn van Groningen 2012-10-31 13:58:07 +01:00 committed by Shay Banon
parent e75c732bdd
commit 1a46179c4e
5 changed files with 17 additions and 9 deletions

View File

@ -20,9 +20,11 @@
package org.elasticsearch.common.lucene.search; package org.elasticsearch.common.lucene.search;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.Filter; import org.apache.lucene.search.Filter;
import org.apache.lucene.util.Bits;
import org.elasticsearch.common.lucene.docset.AndDocIdSet; import org.elasticsearch.common.lucene.docset.AndDocIdSet;
import org.elasticsearch.common.lucene.docset.AndDocSet; import org.elasticsearch.common.lucene.docset.AndDocSet;
import org.elasticsearch.common.lucene.docset.DocSet; import org.elasticsearch.common.lucene.docset.DocSet;
@ -46,14 +48,14 @@ public class AndFilter extends Filter {
} }
@Override @Override
public DocIdSet getDocIdSet(IndexReader reader) throws IOException { public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException {
if (filters.size() == 1) { if (filters.size() == 1) {
return filters.get(0).getDocIdSet(reader); return filters.get(0).getDocIdSet(context, acceptDocs);
} }
List sets = Lists.newArrayListWithExpectedSize(filters.size()); List sets = Lists.newArrayListWithExpectedSize(filters.size());
boolean allAreDocSet = true; boolean allAreDocSet = true;
for (Filter filter : filters) { for (Filter filter : filters) {
DocIdSet set = filter.getDocIdSet(reader); DocIdSet set = filter.getDocIdSet(context, acceptDocs);
if (set == null) { // none matching for this filter, we AND, so return EMPTY if (set == null) { // none matching for this filter, we AND, so return EMPTY
return DocSet.EMPTY_DOC_SET; return DocSet.EMPTY_DOC_SET;
} }

View File

@ -59,7 +59,7 @@ public class FilteredCollector extends Collector {
@Override @Override
public void setNextReader(AtomicReaderContext context) throws IOException { public void setNextReader(AtomicReaderContext context) throws IOException {
collector.setNextReader(context); collector.setNextReader(context);
docSet = DocSets.convert(context.reader(), filter.getDocIdSet(context)); docSet = DocSets.convert(context.reader(), filter.getDocIdSet(context, null));
} }
@Override @Override

View File

@ -19,8 +19,10 @@
package org.elasticsearch.common.lucene.search; package org.elasticsearch.common.lucene.search;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.util.Bits;
import org.elasticsearch.common.lucene.docset.GetDocSet; import org.elasticsearch.common.lucene.docset.GetDocSet;
import java.io.IOException; import java.io.IOException;
@ -39,11 +41,11 @@ public class LimitFilter extends NoCacheFilter {
} }
@Override @Override
public DocIdSet getDocIdSet(IndexReader reader) throws IOException { public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException {
if (counter > limit) { if (counter > limit) {
return null; return null;
} }
return new LimitDocSet(reader.maxDoc(), limit); return new LimitDocSet(context.reader().maxDoc(), limit);
} }
public class LimitDocSet extends GetDocSet { public class LimitDocSet extends GetDocSet {

View File

@ -19,9 +19,11 @@
package org.elasticsearch.common.lucene.search; package org.elasticsearch.common.lucene.search;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.Filter; import org.apache.lucene.search.Filter;
import org.apache.lucene.util.Bits;
import org.elasticsearch.common.lucene.docset.AllDocSet; import org.elasticsearch.common.lucene.docset.AllDocSet;
import java.io.IOException; import java.io.IOException;
@ -34,8 +36,8 @@ import java.io.IOException;
public class MatchAllDocsFilter extends Filter { public class MatchAllDocsFilter extends Filter {
@Override @Override
public DocIdSet getDocIdSet(IndexReader reader) throws IOException { public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException {
return new AllDocSet(reader.maxDoc()); return new AllDocSet(context.reader().maxDoc());
} }
@Override @Override

View File

@ -19,9 +19,11 @@
package org.elasticsearch.common.lucene.search; package org.elasticsearch.common.lucene.search;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.Filter; import org.apache.lucene.search.Filter;
import org.apache.lucene.util.Bits;
import java.io.IOException; import java.io.IOException;
@ -31,7 +33,7 @@ import java.io.IOException;
public class MatchNoDocsFilter extends Filter { public class MatchNoDocsFilter extends Filter {
@Override @Override
public DocIdSet getDocIdSet(IndexReader reader) throws IOException { public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException {
return null; return null;
} }