Index: lucene/core/src/java/org/apache/lucene/index/MultiDocValues.java =================================================================== --- lucene/core/src/java/org/apache/lucene/index/MultiDocValues.java (revision 1449709) +++ lucene/core/src/java/org/apache/lucene/index/MultiDocValues.java (working copy) @@ -397,10 +397,12 @@ } /** implements MultiSortedDocValues over n subs, using an OrdinalMap */ - static class MultiSortedSetDocValues extends SortedSetDocValues { + // nocommit public + public static class MultiSortedSetDocValues extends SortedSetDocValues { final int docStarts[]; final SortedSetDocValues values[]; - final OrdinalMap mapping; + // nocommit public + public final OrdinalMap mapping; int currentSubIndex; MultiSortedSetDocValues(SortedSetDocValues values[], int docStarts[], OrdinalMap mapping) throws IOException { Index: lucene/facet/src/java/org/apache/lucene/facet/search/SortedSetDocValuesCollector.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/search/SortedSetDocValuesCollector.java (revision 0) +++ lucene/facet/src/java/org/apache/lucene/facet/search/SortedSetDocValuesCollector.java (working copy) @@ -0,0 +1,78 @@ +package org.apache.lucene.facet.search; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.IOException; + +import org.apache.lucene.index.AtomicReaderContext; +import org.apache.lucene.index.MultiDocValues.MultiSortedSetDocValues; +import org.apache.lucene.index.MultiDocValues; +import org.apache.lucene.index.SlowCompositeReaderWrapper; +import org.apache.lucene.index.SortedSetDocValues; +import org.apache.lucene.search.Collector; +import org.apache.lucene.search.Scorer; + +public class SortedSetDocValuesCollector extends Collector { + + final MultiDocValues.OrdinalMap ordinalMap; // for mapping per-segment + // ords to global ones + final String field; + final int[] counts; + + private SortedSetDocValues segValues; + private int subIndex = -1; + + public SortedSetDocValuesCollector(String field, SlowCompositeReaderWrapper reader) throws IOException { + SortedSetDocValues dv = reader.getSortedSetDocValues(field); + // nocommit dv isn't MultiSortedSetDV when index is optimized + ordinalMap = ((MultiSortedSetDocValues) dv).mapping; + this.field = field; + // nocommit must check if this overflows int! + counts = new int[(int) dv.getValueCount()]; + } + + @Override + public final boolean acceptsDocsOutOfOrder() { + return true; + } + + @Override + public final void collect(int doc) throws IOException { + // nocommit change to "accumulate in the end": it's faster + segValues.setDocument(doc); + // strange do-while to collect the missing count (first ord is NO_MORE_ORDS) + int term = (int) segValues.nextOrd(); + while (term > 0) { + counts[(int) ordinalMap.getGlobalOrd(subIndex, term)]++; + term = (int) segValues.nextOrd(); + } + } + + @Override + public final void setScorer(Scorer scorer) throws IOException { + } + + @Override + public final void setNextReader(AtomicReaderContext context) throws IOException { + subIndex++; + segValues = context.reader().getSortedSetDocValues(field); + if (segValues == null) { + segValues = SortedSetDocValues.EMPTY; + } + } +} Property changes on: lucene/facet/src/java/org/apache/lucene/facet/search/SortedSetDocValuesCollector.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property