SOLR-1965: use native array access for facet.method=fcs

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@956292 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2010-06-19 20:45:21 +00:00
parent 2b8e4c4a77
commit b58675a60c
1 changed files with 60 additions and 11 deletions

View File

@ -7,6 +7,10 @@ import org.apache.lucene.search.FieldCache;
import org.apache.lucene.search.Filter;
import org.apache.lucene.util.PriorityQueue;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.packed.Direct16;
import org.apache.lucene.util.packed.Direct32;
import org.apache.lucene.util.packed.Direct8;
import org.apache.lucene.util.packed.PackedInts;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.FacetParams;
import org.apache.solr.common.util.NamedList;
@ -248,15 +252,58 @@ class PerSegmentSingleValuedFaceting {
DocIdSet idSet = baseSet.getDocIdSet(reader);
DocIdSetIterator iter = idSet.iterator();
if (startTermIndex==0 && endTermIndex==si.numOrd()) {
// specialized version when collecting counts for all terms
////
PackedInts.Reader ordReader = si.getDocToOrd();
int doc;
if (ordReader instanceof Direct32) {
int[] ords = ((Direct32)ordReader).getArray();
if (prefix==null) {
while ((doc = iter.nextDoc()) < DocIdSetIterator.NO_MORE_DOCS) {
counts[ords[doc]]++;
}
} else {
while ((doc = iter.nextDoc()) < DocIdSetIterator.NO_MORE_DOCS) {
int term = ords[doc];
int arrIdx = term-startTermIndex;
if (arrIdx>=0 && arrIdx<nTerms) counts[arrIdx]++;
}
}
} else if (ordReader instanceof Direct16) {
short[] ords = ((Direct16)ordReader).getArray();
if (prefix==null) {
while ((doc = iter.nextDoc()) < DocIdSetIterator.NO_MORE_DOCS) {
counts[ords[doc] & 0xffff]++;
}
} else {
while ((doc = iter.nextDoc()) < DocIdSetIterator.NO_MORE_DOCS) {
int term = ords[doc] & 0xffff;
int arrIdx = term-startTermIndex;
if (arrIdx>=0 && arrIdx<nTerms) counts[arrIdx]++;
}
}
} else if (ordReader instanceof Direct8) {
byte[] ords = ((Direct8)ordReader).getArray();
if (prefix==null) {
while ((doc = iter.nextDoc()) < DocIdSetIterator.NO_MORE_DOCS) {
counts[ords[doc] & 0xff]++;
}
} else {
while ((doc = iter.nextDoc()) < DocIdSetIterator.NO_MORE_DOCS) {
int term = ords[doc] & 0xff;
int arrIdx = term-startTermIndex;
if (arrIdx>=0 && arrIdx<nTerms) counts[arrIdx]++;
}
}
} else {
if (prefix==null) {
// specialized version when collecting counts for all terms
while ((doc = iter.nextDoc()) < DocIdSetIterator.NO_MORE_DOCS) {
counts[si.getOrd(doc)]++;
}
} else {
// version that adjusts term numbers because we aren't collecting the full range
int doc;
while ((doc = iter.nextDoc()) < DocIdSetIterator.NO_MORE_DOCS) {
int term = si.getOrd(doc);
int arrIdx = term-startTermIndex;
@ -264,6 +311,8 @@ class PerSegmentSingleValuedFaceting {
}
}
}
}
}
}