Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.
*/
package org.apache.solr.search.facet;
import java.io.Closeable;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.function.IntFunction;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.queries.function.FunctionValues;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.FixedBitSet;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.search.DocIterator;
import org.apache.solr.search.DocSet;
import org.apache.solr.search.SolrIndexSearcher;
/**
* Accumulates statistics separated by a slot number.
* There is a separate statistic per slot. The slot is usually an ordinal into a set of values, e.g. tracking a count
* frequency per term.
* Sometimes there doesn't need to be a slot distinction, in which case there is just one nominal slot.
*/
public abstract class SlotAcc implements Closeable {
String key; // todo...
protected final FacetContext fcontext;
protected LeafReaderContext currentReaderContext;
protected int currentDocBase;
public SlotAcc(FacetContext fcontext) {
this.fcontext = fcontext;
}
/**
* NOTE: this currently detects when it is being reused and calls resetIterators by comparing reader ords
* with previous calls to setNextReader. For this reason, current users must call setNextReader
* in segment order. Failure to do so will cause worse performance.
*/
public void setNextReader(LeafReaderContext readerContext) throws IOException {
LeafReaderContext lastReaderContext = currentReaderContext;
currentReaderContext = readerContext;
currentDocBase = currentReaderContext.docBase;
if (lastReaderContext == null || lastReaderContext.ord >= currentReaderContext.ord) {
// if we went backwards (or reused) a reader, we need to reset iterators that can be used only once.
resetIterators();
}
}
/**
* All subclasses must override this method to collect documents. This method is called by the
* default impl of {@link #collect(DocSet,int,IntFunction)} but it's also neccessary if this accumulator
* is used for sorting.
*
* @param doc Single Segment docId (relative to the current {@link LeafReaderContext} to collect
* @param slot The slot number to collect this document in
* @param slotContext A callback that can be used for Accumulators that would like additional info
* about the current slot -- the {@link IntFunction} is only garunteed to be valid for
* the current slot, and the {@link SlotContext} returned is only valid for the duration
* of the collect() call.
*/
public abstract void collect(int doc, int slot, IntFunction slotContext) throws IOException;
/**
* Bulk collection of all documents in a slot. The default implementation calls {@link #collect(int,int,IntFunction)}
*
* @param docs (global) Documents to collect
* @param slot The slot number to collect these documents in
* @param slotContext A callback that can be used for Accumulators that would like additional info
* about the current slot -- the {@link IntFunction} is only garunteed to be valid for
* the current slot, and the {@link SlotContext} returned is only valid for the duration
* of the collect() call.
*/
public int collect(DocSet docs, int slot, IntFunction slotContext) throws IOException {
int count = 0;
SolrIndexSearcher searcher = fcontext.searcher;
final List leaves = searcher.getIndexReader().leaves();
final Iterator ctxIt = leaves.iterator();
LeafReaderContext ctx = null;
int segBase = 0;
int segMax;
int adjustedMax = 0;
for (DocIterator docsIt = docs.iterator(); docsIt.hasNext();) {
final int doc = docsIt.nextDoc();
if (doc >= adjustedMax) {
do {
ctx = ctxIt.next();
if (ctx == null) {
// should be impossible
throw new RuntimeException("INTERNAL FACET ERROR");
}
segBase = ctx.docBase;
segMax = ctx.reader().maxDoc();
adjustedMax = segBase + segMax;
} while (doc >= adjustedMax);
assert doc >= ctx.docBase;
setNextReader(ctx);
}
count++;
collect(doc - segBase, slot, slotContext); // per-seg collectors
}
return count;
}
public abstract int compare(int slotA, int slotB);
public abstract Object getValue(int slotNum) throws IOException;
public void setValues(SimpleOrderedMap