org.apache.solr.analytics.facet.PivotNode Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of solr-analytics Show documentation
Show all versions of solr-analytics Show documentation
Apache Solr Content Analytics Package
/*
* 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.analytics.facet;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import org.apache.solr.analytics.AnalyticsDriver;
import org.apache.solr.analytics.function.ExpressionCalculator;
import org.apache.solr.analytics.function.ReductionCollectionManager;
import org.apache.solr.analytics.function.ReductionCollectionManager.ReductionDataCollection;
import org.apache.solr.analytics.function.reduction.data.ReductionData;
import org.apache.solr.analytics.util.AnalyticsResponseHeadings;
import org.apache.solr.analytics.value.StringValueStream;
/**
* Representation of one layer of a Pivot Facet. A PivotFacet node is individually sortable,
* and is collected during the streaming phase of the {@link AnalyticsDriver}.
*/
public abstract class PivotNode extends SortableFacet implements Consumer {
private StringValueStream expression;
protected Map currentPivot;
public PivotNode(String name, StringValueStream expression) {
super(name);
this.expression = expression;
}
/**
* Determine which facet values match the current document. Add the {@link ReductionDataCollection}s of the relevant facet values
* to the targets of the streaming {@link ReductionCollectionManager} so that they are updated with the current document's data.
*/
public void addFacetValueCollectionTargets(Map pivot) {
currentPivot = pivot;
expression.streamStrings(this);
}
/**
* Import the shard data from a bit-stream for the given pivot, exported by the {@link #exportPivot} method
* in the each of the collection's shards.
*
* @param input The bit-stream to import the data from
* @param pivot the values for this pivot node and the pivot children (if they exist)
* @throws IOException if an exception occurs while reading from the {@link DataInput}
*/
public void importPivot(DataInput input, Map pivot) throws IOException {
int size = input.readInt();
currentPivot = pivot;
for (int i = 0; i < size; ++i) {
importPivotValue(input, input.readUTF());
}
}
/**
* Import the next pivot value's set of {@link ReductionData} and children's {@link ReductionData} if they exist.
*
* @param input the bit-stream to import the reduction data from
* @param pivotValue the next pivot value
* @throws IOException if an exception occurs while reading from the input
*/
protected abstract void importPivotValue(DataInput input, String pivotValue) throws IOException;
/**
* Export the shard data through a bit-stream for the given pivot,
* to be imported by the {@link #importPivot} method in the originating shard.
*
* @param output The bit-stream to output the data through
* @param pivot the values for this pivot node and the pivot children (if they exist)
* @throws IOException if an exception occurs while writing to the {@link DataOutput}
*/
public void exportPivot(DataOutput output, Map pivot) throws IOException {
output.writeInt(pivot.size());
for (String pivotValue : pivot.keySet()) {
output.writeUTF(pivotValue);
exportPivotValue(output, pivot.get(pivotValue));
}
}
/**
* Export the given pivot data, containing {@link ReductionData} and pivot children if they exist.
*
* @param output the bit-stream to output the reduction data to
* @param pivotData the next pivot value data
* @throws IOException if an exception occurs while reading from the input
*/
protected abstract void exportPivotValue(DataOutput output, T pivotData) throws IOException;
/**
* Create the response of the facet to be returned in the overall analytics response.
*
* @param pivot the pivot to create a response for
* @return the response of the facet
*/
public abstract Iterable
© 2015 - 2025 Weber Informatics LLC | Privacy Policy