org.apache.solr.search.facet.FacetFieldProcessorByArray Maven / Gradle / Ivy
Show all versions of solr-core Show documentation
/*
* 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 static org.apache.solr.search.facet.FacetContext.SKIP_FACET;
import java.io.IOException;
import java.util.Date;
import java.util.function.IntFunction;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefBuilder;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.search.facet.SlotAcc.SlotContext;
import org.apache.solr.search.facet.SlotAcc.SweepingCountSlotAcc;
/**
* Base class for DV/UIF accumulating counts into an array by ordinal. It's for {@link
* org.apache.lucene.index.SortedDocValues} and {@link org.apache.lucene.index.SortedSetDocValues}
* only. It can handle terms (strings), not numbers directly but those encoded as terms, and is
* multi-valued capable. By default, this class assumes subclasses can support sweeping collection
* unless subclasses initialize countAcc
directly in their constructors.
*
* @see SweepingCountSlotAcc
*/
abstract class FacetFieldProcessorByArray extends FacetFieldProcessor {
BytesRefBuilder prefixRef;
int startTermIndex;
int endTermIndex;
int nTerms;
int nDocs;
int maxSlots;
int allBucketsSlot = -1; // slot for the primary Accs (countAcc, collectAcc)
FacetFieldProcessorByArray(FacetContext fcontext, FacetField freq, SchemaField sf) {
super(fcontext, freq, sf);
}
protected abstract void findStartAndEndOrds() throws IOException;
protected abstract void collectDocs() throws IOException;
/** this BytesRef may be shared across calls and should be deep-cloned if necessary */
protected abstract BytesRef lookupOrd(int ord) throws IOException;
/**
* {@inheritDoc}
*
* This impl first initializes countAcc
as a {@link SweepingCountSlotAcc} if null.
*/
@Override
protected void createAccs(long docCount, int slotCount) throws IOException {
if (countAcc == null) {
countAcc = new SweepingCountSlotAcc(slotCount, this);
}
super.createAccs(docCount, slotCount);
}
/**
* {@inheritDoc}
*
*
This impl first initializes countAcc
as a {@link SweepingCountSlotAcc} if null.
*/
@Override
void createCollectAcc(int numDocs, int numSlots) throws IOException {
if (countAcc == null) {
countAcc = new SweepingCountSlotAcc(numSlots, this);
}
super.createCollectAcc(numDocs, numSlots);
registerSweepingAccIfSupportedByCollectAcc();
}
@Override
public void process() throws IOException {
super.process();
response = calcFacets();
}
private SimpleOrderedMap