mirror of https://github.com/apache/lucene.git
SOLR-13629: Cleanup whitespace in analytics contrib
This commit is contained in:
parent
a229e711ca
commit
ca4cd3c7d3
|
@ -69,6 +69,8 @@ Other Changes
|
|||
|
||||
* SOLR-10377: Add `debug.explain.structured` to Admin UI. (David Smiley, Munendra S N)
|
||||
|
||||
* SOLR-13629: Clean trailing whitespace from 'analytics' contrib (Neal Sidhwaney via Jason Gerlowski)
|
||||
|
||||
================== 8.2.0 ==================
|
||||
|
||||
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
||||
|
|
|
@ -31,10 +31,10 @@ import org.apache.solr.search.Filter;
|
|||
import org.apache.solr.search.SolrIndexSearcher;
|
||||
|
||||
public class AnalyticsDriver {
|
||||
|
||||
|
||||
/**
|
||||
* Drive the collection of reduction data. This includes overall data as well as faceted data.
|
||||
*
|
||||
*
|
||||
* @param manager of the request to drive
|
||||
* @param searcher the results of the query
|
||||
* @param filter that represents the overall query
|
||||
|
@ -45,9 +45,9 @@ public class AnalyticsDriver {
|
|||
StreamingInfo streamingInfo = manager.getStreamingFacetInfo();
|
||||
Iterable<StreamingFacet> streamingFacets = streamingInfo.streamingFacets;
|
||||
ReductionCollectionManager collectionManager = streamingInfo.streamingCollectionManager;
|
||||
|
||||
|
||||
Iterable<FacetValueQueryExecuter> facetExecuters = manager.getFacetExecuters(filter, queryRequest);
|
||||
|
||||
|
||||
// Streaming phase (Overall results & Value/Pivot Facets)
|
||||
// Loop through all documents and collect reduction data for streaming facets and overall results
|
||||
if (collectionManager.needsCollection()) {
|
||||
|
@ -72,7 +72,7 @@ public class AnalyticsDriver {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Executing phase (Query/Range Facets)
|
||||
// Send additional Solr Queries to compute facet values
|
||||
for (FacetValueQueryExecuter executer : facetExecuters) {
|
||||
|
|
|
@ -27,35 +27,35 @@ import org.apache.solr.analytics.value.AnalyticsValue;
|
|||
public class AnalyticsExpression {
|
||||
private final AnalyticsValue expression;
|
||||
private final String name;
|
||||
|
||||
|
||||
public AnalyticsExpression(String name, AnalyticsValue expression) {
|
||||
this.name = name;
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public AnalyticsValue getExpression() {
|
||||
return expression;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the current value of the expression.
|
||||
* This method can, and will, be called multiple times to return different values.
|
||||
* The value returned is based on the {@link ReductionDataCollection} given
|
||||
* to the {@link ReductionCollectionManager#setData} method.
|
||||
*
|
||||
*
|
||||
* @return the current value of the expression
|
||||
*/
|
||||
public Object toObject() {
|
||||
return expression.getObject();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* NOTE: Must be called after {@link #toObject()} is called, otherwise the value is not guaranteed to be correct.
|
||||
*
|
||||
*
|
||||
* @return whether the current value of the expression exists.
|
||||
*/
|
||||
public boolean exists() {
|
||||
|
|
|
@ -43,7 +43,7 @@ import org.apache.solr.search.Filter;
|
|||
/**
|
||||
* The manager for faceted analytics. This class manages one grouping of facets and expressions to compute
|
||||
* over those facets.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* This class will only manage generating faceted results, not overall results.
|
||||
*/
|
||||
|
@ -53,9 +53,9 @@ public class AnalyticsGroupingManager {
|
|||
|
||||
private final Collection<AnalyticsExpression> topLevelExpressions;
|
||||
private final ExpressionCalculator expressionCalculator;
|
||||
|
||||
|
||||
private final Map<String, AnalyticsFacet> facets;
|
||||
|
||||
|
||||
public AnalyticsGroupingManager(String name,
|
||||
ReductionCollectionManager reductionCollectionManager,
|
||||
Collection<AnalyticsExpression> topLevelExpressions) {
|
||||
|
@ -70,11 +70,11 @@ public class AnalyticsGroupingManager {
|
|||
|
||||
// This is outside of the method, since it is used in the lambda and cannot be a local non-final variable
|
||||
private boolean hasStreamingFacets;
|
||||
|
||||
|
||||
/**
|
||||
* Get the {@link StreamingFacet}s (e.g. {@link ValueFacet} and {@link PivotFacet}) contained within this grouping,
|
||||
* returning them through the given consumer.
|
||||
*
|
||||
*
|
||||
* @param cons where the streaming facets are passed to
|
||||
* @return whether the grouping contains streaming facets
|
||||
*/
|
||||
|
@ -93,12 +93,12 @@ public class AnalyticsGroupingManager {
|
|||
* Create the {@link FacetValueQueryExecuter}s for all {@link AbstractSolrQueryFacet}s
|
||||
* (e.g. {@link QueryFacet} and {@link RangeFacet}) contained within this grouping.
|
||||
* The executers are returned through the given consumer.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* One {@link FacetValueQueryExecuter} is created for each facet value to be returned for a facet.
|
||||
* Since every {@link AbstractSolrQueryFacet} has discrete and user-defined facet values,
|
||||
* unlike {@link StreamingFacet}s, a discrete number of {@link FacetValueQueryExecuter}s are created and returned.
|
||||
*
|
||||
*
|
||||
* @param filter representing the overall Solr Query of the request,
|
||||
* will be combined with the facet value queries
|
||||
* @param queryRequest from the overall search request
|
||||
|
@ -111,10 +111,10 @@ public class AnalyticsGroupingManager {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a facet to the grouping. All expressions in this grouping will be computed over the facet.
|
||||
*
|
||||
*
|
||||
* @param facet to compute expressions over
|
||||
*/
|
||||
public void addFacet(AnalyticsFacet facet) {
|
||||
|
@ -122,11 +122,11 @@ public class AnalyticsGroupingManager {
|
|||
facet.setReductionCollectionManager(reductionCollectionManager);
|
||||
facets.put(facet.getName(), facet);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Import the shard data for this grouping from a bit-stream,
|
||||
* exported by the {@link #exportShardData} method in the each of the collection's shards.
|
||||
*
|
||||
*
|
||||
* @param input The bit-stream to import the grouping data from
|
||||
* @throws IOException if an exception occurs while reading from the {@link DataInput}
|
||||
*/
|
||||
|
@ -134,17 +134,17 @@ public class AnalyticsGroupingManager {
|
|||
// This allows mergeData() to import from the same input everytime it is called
|
||||
// while the facets are importing.
|
||||
reductionCollectionManager.setShardInput(input);
|
||||
|
||||
|
||||
int sz = input.readInt();
|
||||
for (int i = 0; i < sz; ++i) {
|
||||
facets.get(input.readUTF()).importShardData(input);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Export the shard data for this grouping through a bit-stream,
|
||||
* to be imported by the {@link #importShardData} method in the originating shard.
|
||||
*
|
||||
*
|
||||
* @param output The bit-stream to output the grouping data through
|
||||
* @throws IOException if an exception occurs while writing to the {@link DataOutput}
|
||||
*/
|
||||
|
@ -152,18 +152,18 @@ public class AnalyticsGroupingManager {
|
|||
// This allows exportData() to export to the same output everytime it is called
|
||||
// while the facets are exporting.
|
||||
reductionCollectionManager.setShardOutput(output);
|
||||
|
||||
|
||||
output.writeInt(facets.size());
|
||||
for (Entry<String,AnalyticsFacet> facet : facets.entrySet()) {
|
||||
output.writeUTF(facet.getKey());
|
||||
facet.getValue().exportShardData(output);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the {@link ReductionCollectionManager} that manages the collection of reduction data for the expressions
|
||||
* contained within this grouping.
|
||||
*
|
||||
* contained within this grouping.
|
||||
*
|
||||
* @return the grouping's reduction manager
|
||||
*/
|
||||
public ReductionCollectionManager getReductionManager() {
|
||||
|
@ -172,18 +172,18 @@ public class AnalyticsGroupingManager {
|
|||
|
||||
/**
|
||||
* Create the response for this grouping, a mapping from each of it's facets' names to the facet's response.
|
||||
*
|
||||
*
|
||||
* @return the named list representation of the response
|
||||
*/
|
||||
public Map<String,Object> createResponse() {
|
||||
Map<String,Object> response = new HashMap<>();
|
||||
|
||||
|
||||
// Add the value facet buckets to the output
|
||||
facets.forEach( (name, facet) -> response.put(name, facet.createResponse()) );
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the response for this grouping, but in the old style of response.
|
||||
* This response has a bucket for the following if they are contained in the grouping:
|
||||
|
@ -192,13 +192,13 @@ public class AnalyticsGroupingManager {
|
|||
* <p>
|
||||
* Since groupings in the old notation must also return overall results, the overall results are
|
||||
* passed in and the values are used to populate the grouping response.
|
||||
*
|
||||
*
|
||||
* @param overallResults of the expressions to add to the grouping response
|
||||
* @return the named list representation of the response
|
||||
*/
|
||||
public NamedList<Object> createOldResponse(Map<String,Object> overallResults) {
|
||||
NamedList<Object> response = new NamedList<>();
|
||||
|
||||
|
||||
topLevelExpressions.forEach( expression -> response.add(expression.getName(), overallResults.get(name + expression.getName())));
|
||||
|
||||
NamedList<Object> fieldFacetResults = new NamedList<>();
|
||||
|
@ -230,7 +230,7 @@ public class AnalyticsGroupingManager {
|
|||
|
||||
/**
|
||||
* Get the name of the grouping.
|
||||
*
|
||||
*
|
||||
* @return the grouping name
|
||||
*/
|
||||
public String getName() {
|
||||
|
|
|
@ -42,25 +42,25 @@ import org.apache.solr.search.Filter;
|
|||
public class AnalyticsRequestManager {
|
||||
private final ReductionCollectionManager ungroupedReductionManager;
|
||||
private ReductionDataCollection ungroupedData;
|
||||
|
||||
|
||||
private final Map<String, AnalyticsGroupingManager> groupingManagers;
|
||||
|
||||
|
||||
private final Collection<AnalyticsExpression> ungroupedExpressions;
|
||||
private final ExpressionCalculator ungroupedExpressionCalculator;
|
||||
|
||||
|
||||
/**
|
||||
* If the request is distributed, the manager for shard requests.
|
||||
*/
|
||||
public String analyticsRequest;
|
||||
public AnalyticsShardRequestManager shardStream;
|
||||
public boolean sendShards;
|
||||
|
||||
public boolean sendShards;
|
||||
|
||||
/**
|
||||
* Create an manager with the given ungrouped expressions. This is straightforward in the new
|
||||
* style of request, however in the old olap-style requests all groupings' expressions are expected
|
||||
* to be ungrouped as well.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param ungroupedReductionManager to manage the reduction collection for all ungrouped expressions
|
||||
* @param ungroupedExpressions to compute overall results for
|
||||
*/
|
||||
|
@ -69,85 +69,85 @@ public class AnalyticsRequestManager {
|
|||
this.ungroupedReductionManager = ungroupedReductionManager;
|
||||
this.ungroupedData = ungroupedReductionManager.newDataCollection();
|
||||
this.ungroupedReductionManager.addLastingCollectTarget(ungroupedData);
|
||||
|
||||
|
||||
this.ungroupedExpressions = ungroupedExpressions;
|
||||
this.ungroupedExpressionCalculator = new ExpressionCalculator(ungroupedExpressions);
|
||||
this.groupingManagers = new HashMap<>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the collection manager for ungrouped expressions, including grouped expressions if
|
||||
* the old request notation is used.
|
||||
*
|
||||
*
|
||||
* @return the collection manager for the ungrouped expressions
|
||||
*/
|
||||
public ReductionCollectionManager getUngroupedCollectionManager() {
|
||||
return ungroupedReductionManager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the collection manager for all ungrouped expressions, including grouped expressions if
|
||||
* the old request notation is used.
|
||||
*
|
||||
*
|
||||
* @return the collection manager for the ungrouped expressions
|
||||
*/
|
||||
public ReductionDataCollection getUngroupedData() {
|
||||
return ungroupedData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return all ungrouped expressions, including grouped expressions if
|
||||
* the old request notation is used.
|
||||
*
|
||||
*
|
||||
* @return an {@link Iterable} of the ungrouped expressions
|
||||
*/
|
||||
public Iterable<AnalyticsExpression> getUngroupedExpressions() {
|
||||
return ungroupedExpressions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate the results of all ungrouped expressions, including grouped expressions if
|
||||
* the old request notation is used.
|
||||
*
|
||||
*
|
||||
* @param response the response to add the ungrouped results to.
|
||||
*/
|
||||
public void addUngroupedResults(Map<String,Object> response) {
|
||||
ungroupedReductionManager.setData(ungroupedData);
|
||||
ungroupedExpressionCalculator.addResults(response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate the results of all ungrouped expressions, including grouped expressions if
|
||||
* the old request notation is used.
|
||||
*
|
||||
*
|
||||
* @return the map containing the ungrouped results
|
||||
*/
|
||||
public Map<String,Object> getUngroupedResults() {
|
||||
ungroupedReductionManager.setData(ungroupedData);
|
||||
return ungroupedExpressionCalculator.getResults();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a grouping to the request.
|
||||
*
|
||||
*
|
||||
* @param groupingManager that manages the grouping
|
||||
*/
|
||||
public void addGrouping(AnalyticsGroupingManager groupingManager) {
|
||||
groupingManagers.put(groupingManager.getName(), groupingManager);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Import the shard data for this request from a bit-stream,
|
||||
* exported by the {@link #exportShardData} method in the each of the collection's shards.
|
||||
* <p>
|
||||
* First the overall data is imported, then the grouping data is imported.
|
||||
*
|
||||
*
|
||||
* @param input The bit-stream to import the shard data from
|
||||
* @throws IOException if an exception occurs while reading from the {@link DataInput}
|
||||
*/
|
||||
public synchronized void importShardData(DataInput input) throws IOException {
|
||||
ungroupedReductionManager.setShardInput(input);
|
||||
|
||||
|
||||
// The ungroupedData will not exist for the first shard imported
|
||||
if (ungroupedData == null) {
|
||||
ungroupedData = ungroupedReductionManager.newDataCollectionIO();
|
||||
|
@ -155,29 +155,29 @@ public class AnalyticsRequestManager {
|
|||
ungroupedReductionManager.prepareReductionDataIO(ungroupedData);
|
||||
}
|
||||
ungroupedReductionManager.mergeData();
|
||||
|
||||
|
||||
int size = input.readInt();
|
||||
while (--size >= 0) {
|
||||
String groupingName = input.readUTF();
|
||||
groupingManagers.get(groupingName).importShardData(input);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Export the shard data for this request through a bit-stream,
|
||||
* to be imported by the {@link #importShardData} method in the originating shard.
|
||||
* <p>
|
||||
* First the overall data is exported, then the grouping data is exported.
|
||||
*
|
||||
*
|
||||
* @param output The bit-stream to output the shard data through
|
||||
* @throws IOException if an exception occurs while writing to the {@link DataOutput}
|
||||
*/
|
||||
public void exportShardData(DataOutput output) throws IOException {
|
||||
ungroupedReductionManager.setShardOutput(output);
|
||||
|
||||
|
||||
ungroupedReductionManager.prepareReductionDataIO(ungroupedData);
|
||||
ungroupedReductionManager.exportData();
|
||||
|
||||
|
||||
output.writeInt(groupingManagers.size());
|
||||
for (String groupingName : groupingManagers.keySet()) {
|
||||
output.writeUTF(groupingName);
|
||||
|
@ -187,9 +187,9 @@ public class AnalyticsRequestManager {
|
|||
|
||||
/**
|
||||
* Consolidate the information of all {@link StreamingFacet}s contained within the request, since
|
||||
* they need to be collected along with the overall results during the streaming phase of the
|
||||
* they need to be collected along with the overall results during the streaming phase of the
|
||||
* {@link AnalyticsDriver}.
|
||||
*
|
||||
*
|
||||
* @return the info for all {@link StreamingFacet}s
|
||||
*/
|
||||
public StreamingInfo getStreamingFacetInfo() {
|
||||
|
@ -197,18 +197,18 @@ public class AnalyticsRequestManager {
|
|||
ArrayList<ReductionCollectionManager> groupingCollectors = new ArrayList<>();
|
||||
groupingManagers.values().forEach( grouping -> {
|
||||
// If a grouping has streaming facets, then that groupings expressions
|
||||
// must be collected during the streaming phase.
|
||||
// must be collected during the streaming phase.
|
||||
if (grouping.getStreamingFacets( facet -> streamingInfo.streamingFacets.add(facet) )) {
|
||||
groupingCollectors.add(grouping.getReductionManager());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Create an streaming collection manager to manage the collection of all ungrouped expressions and
|
||||
// grouped expressions that are calculated over streaming facets.
|
||||
streamingInfo.streamingCollectionManager = ungroupedReductionManager.merge(groupingCollectors);
|
||||
return streamingInfo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Class to encapsulate all necessary data for collecting {@link StreamingFacet}s.
|
||||
*/
|
||||
|
@ -222,7 +222,7 @@ public class AnalyticsRequestManager {
|
|||
|
||||
/**
|
||||
* Create the {@link FacetValueQueryExecuter}s for all {@link AbstractSolrQueryFacet}s contained in the request.
|
||||
*
|
||||
*
|
||||
* @param filter representing the overall search query
|
||||
* @param queryRequest of the overall search query
|
||||
* @return an {@link Iterable} of executers
|
||||
|
@ -234,11 +234,11 @@ public class AnalyticsRequestManager {
|
|||
});
|
||||
return facetExecutors;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the response for a request given in the old olap-style format.
|
||||
* The old response returned overall expressions within groupings.
|
||||
*
|
||||
*
|
||||
* @return a {@link NamedList} representation of the response
|
||||
*/
|
||||
public NamedList<Object> createOldResponse() {
|
||||
|
@ -247,17 +247,17 @@ public class AnalyticsRequestManager {
|
|||
groupingManagers.forEach( (name, groupingManager) -> {
|
||||
analyticsResponse.add(name, groupingManager.createOldResponse(ungroupedResults));
|
||||
});
|
||||
|
||||
|
||||
return analyticsResponse;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the response for a request.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* NOTE: Analytics requests specified in the old olap-style format
|
||||
* have their responses generated by {@link #createOldResponse()}.
|
||||
*
|
||||
*
|
||||
* @return a {@link Map} representation of the response
|
||||
*/
|
||||
public Map<String,Object> createResponse() {
|
||||
|
@ -270,7 +270,7 @@ public class AnalyticsRequestManager {
|
|||
groupingManagers.forEach( (name, groupingManager) -> {
|
||||
groupingsResponse.put(name, groupingManager.createResponse());
|
||||
});
|
||||
|
||||
|
||||
if (groupingsResponse.size() > 0) {
|
||||
analyticsResponse.put(AnalyticsResponseHeadings.GROUPINGS, groupingsResponse);
|
||||
}
|
||||
|
|
|
@ -63,43 +63,43 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
* Class to manage the parsing of new-style analytics requests.
|
||||
*/
|
||||
public class AnalyticsRequestParser {
|
||||
|
||||
|
||||
private static ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
|
||||
public static void init() {
|
||||
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, true);
|
||||
}
|
||||
|
||||
|
||||
public static final String analyticsParamName = "analytics";
|
||||
|
||||
private static Predicate<String> sortAscending = acceptNames("ascending", "asc", "a");
|
||||
private static Predicate<String> sortDescending = acceptNames("descending", "desc", "d");
|
||||
|
||||
|
||||
private static Predicate<String> acceptNames(String... names) {
|
||||
return Pattern.compile("^(?:" + Arrays.stream(names).reduce((a,b) -> a + "|" + b).orElse("") + ")$", Pattern.CASE_INSENSITIVE).asPredicate();
|
||||
}
|
||||
|
||||
|
||||
// Defaults
|
||||
public static final String DEFAULT_SORT_DIRECTION = "ascending";
|
||||
public static final int DEFAULT_OFFSET = 0;
|
||||
public static final int DEFAULT_LIMIT = -1;
|
||||
public static final boolean DEFAULT_HARDEND = false;
|
||||
|
||||
|
||||
@JsonInclude(Include.NON_EMPTY)
|
||||
public static class AnalyticsRequest {
|
||||
public Map<String, String> functions;
|
||||
public Map<String, String> expressions;
|
||||
|
||||
|
||||
public Map<String, AnalyticsGroupingRequest> groupings;
|
||||
}
|
||||
|
||||
|
||||
public static class AnalyticsGroupingRequest {
|
||||
public Map<String, String> expressions;
|
||||
|
||||
|
||||
public Map<String, AnalyticsFacetRequest> facets;
|
||||
}
|
||||
|
||||
|
||||
@JsonTypeInfo(
|
||||
use = JsonTypeInfo.Id.NAME,
|
||||
include = JsonTypeInfo.As.PROPERTY,
|
||||
|
@ -113,7 +113,7 @@ public class AnalyticsRequestParser {
|
|||
)
|
||||
@JsonInclude(Include.NON_EMPTY)
|
||||
public static interface AnalyticsFacetRequest { }
|
||||
|
||||
|
||||
@JsonTypeName("value")
|
||||
public static class AnalyticsValueFacetRequest implements AnalyticsFacetRequest {
|
||||
public String expression;
|
||||
|
@ -124,7 +124,7 @@ public class AnalyticsRequestParser {
|
|||
public static class AnalyticsPivotFacetRequest implements AnalyticsFacetRequest {
|
||||
public List<AnalyticsPivotRequest> pivots;
|
||||
}
|
||||
|
||||
|
||||
public static class AnalyticsPivotRequest {
|
||||
public String name;
|
||||
public String expression;
|
||||
|
@ -175,11 +175,11 @@ public class AnalyticsRequestParser {
|
|||
public static class AnalyticsQueryFacetRequest implements AnalyticsFacetRequest {
|
||||
public Map<String, String> queries;
|
||||
}
|
||||
|
||||
|
||||
/* ***************
|
||||
* Request & Groupings
|
||||
* Request & Groupings
|
||||
* ***************/
|
||||
|
||||
|
||||
public static AnalyticsRequestManager parse(AnalyticsRequest request, ExpressionFactory expressionFactory, boolean isDistribRequest) throws SolrException {
|
||||
AnalyticsRequestManager manager = constructRequest(request, expressionFactory, isDistribRequest);
|
||||
if (isDistribRequest) {
|
||||
|
@ -191,7 +191,7 @@ public class AnalyticsRequestParser {
|
|||
}
|
||||
return manager;
|
||||
}
|
||||
|
||||
|
||||
public static AnalyticsRequestManager parse(String rawRequest, ExpressionFactory expressionFactory, boolean isDistribRequest) throws SolrException {
|
||||
JsonParser parser;
|
||||
try {
|
||||
|
@ -214,15 +214,15 @@ public class AnalyticsRequestParser {
|
|||
}
|
||||
return manager;
|
||||
}
|
||||
|
||||
|
||||
private static AnalyticsRequestManager constructRequest(AnalyticsRequest request, ExpressionFactory expressionFactory, boolean isDistribRequest) throws SolrException {
|
||||
expressionFactory.startRequest();
|
||||
|
||||
|
||||
// Functions
|
||||
if (request.functions != null) {
|
||||
request.functions.forEach( (funcSig, retSig) -> expressionFactory.addUserDefinedVariableFunction(funcSig, retSig));
|
||||
}
|
||||
|
||||
|
||||
// Expressions
|
||||
Map<String,AnalyticsExpression> topLevelExpressions;
|
||||
if (request.expressions != null) {
|
||||
|
@ -231,7 +231,7 @@ public class AnalyticsRequestParser {
|
|||
topLevelExpressions = new HashMap<>();
|
||||
}
|
||||
AnalyticsRequestManager manager = new AnalyticsRequestManager(expressionFactory.createReductionManager(isDistribRequest), topLevelExpressions.values());
|
||||
|
||||
|
||||
// Groupings
|
||||
if (request.groupings != null) {
|
||||
request.groupings.forEach( (name, grouping) -> {
|
||||
|
@ -240,20 +240,20 @@ public class AnalyticsRequestParser {
|
|||
}
|
||||
return manager;
|
||||
}
|
||||
|
||||
|
||||
private static AnalyticsGroupingManager constructGrouping(String name, AnalyticsGroupingRequest grouping, ExpressionFactory expressionFactory, boolean isDistribRequest) throws SolrException {
|
||||
expressionFactory.startGrouping();
|
||||
|
||||
|
||||
// Expressions
|
||||
if (grouping.expressions == null || grouping.expressions.size() == 0) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"Groupings must contain at least one expression, '" + name + "' has none.");
|
||||
}
|
||||
|
||||
|
||||
Map<String,AnalyticsExpression> expressions = constructExpressions(grouping.expressions, expressionFactory);
|
||||
AnalyticsGroupingManager manager = new AnalyticsGroupingManager(name,
|
||||
expressionFactory.createGroupingReductionManager(isDistribRequest),
|
||||
AnalyticsGroupingManager manager = new AnalyticsGroupingManager(name,
|
||||
expressionFactory.createGroupingReductionManager(isDistribRequest),
|
||||
expressions.values());
|
||||
|
||||
|
||||
if (grouping.facets == null) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"Groupings must contain at least one facet, '" + name + "' has none.");
|
||||
}
|
||||
|
@ -269,17 +269,17 @@ public class AnalyticsRequestParser {
|
|||
manager.addFacet(constructQueryFacet(facetName, (AnalyticsQueryFacetRequest) facet));
|
||||
} else {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The facet type, '" + facet.getClass().toString() + "' in "
|
||||
+ "grouping '" + name + "' is not a valid type of facet");
|
||||
+ "grouping '" + name + "' is not a valid type of facet");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return manager;
|
||||
}
|
||||
|
||||
|
||||
/* ***************
|
||||
* Expression & Functions
|
||||
* Expression & Functions
|
||||
* ***************/
|
||||
|
||||
|
||||
private static Map<String, AnalyticsExpression> constructExpressions(Map<String, String> rawExpressions, ExpressionFactory expressionFactory) throws SolrException {
|
||||
Map<String, AnalyticsExpression> expressions = new HashMap<>();
|
||||
rawExpressions.forEach( (name, expression) -> {
|
||||
|
@ -296,20 +296,20 @@ public class AnalyticsRequestParser {
|
|||
});
|
||||
return expressions;
|
||||
}
|
||||
|
||||
|
||||
/* ***************
|
||||
* FACETS
|
||||
* FACETS
|
||||
* ***************/
|
||||
|
||||
|
||||
/*
|
||||
* Value Facets
|
||||
*/
|
||||
|
||||
|
||||
private static ValueFacet constructValueFacet(String name, AnalyticsValueFacetRequest facetRequest, ExpressionFactory expressionFactory, Map<String, AnalyticsExpression> expressions) throws SolrException {
|
||||
if (facetRequest.expression == null) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST, "Value Facets must contain a mapping expression to facet over, '" + name + "' has none.");
|
||||
}
|
||||
|
||||
|
||||
// The second parameter must be a mapping expression
|
||||
AnalyticsValueStream expr = expressionFactory.createExpression(facetRequest.expression);
|
||||
if (!expr.getExpressionType().isUnreduced()) {
|
||||
|
@ -320,9 +320,9 @@ public class AnalyticsRequestParser {
|
|||
throw new SolrException(ErrorCode.BAD_REQUEST, "Value Facet expressions must be castable to string expressions, "
|
||||
+ "the following expression in value facet '" + name + "' is not: " + facetRequest.expression);
|
||||
}
|
||||
|
||||
|
||||
ValueFacet facet = new ValueFacet(name, (StringValueStream)expr);
|
||||
|
||||
|
||||
// Check if the value facet is sorted
|
||||
if (facetRequest.sort != null) {
|
||||
facet.setSort(constructSort(facetRequest.sort, expressions));
|
||||
|
@ -333,23 +333,23 @@ public class AnalyticsRequestParser {
|
|||
/*
|
||||
* Pivot Facets
|
||||
*/
|
||||
|
||||
|
||||
private static PivotFacet constructPivotFacet(String name, AnalyticsPivotFacetRequest facetRequest, ExpressionFactory expressionFactory, Map<String, AnalyticsExpression> expressions) throws SolrException {
|
||||
PivotNode<?> topPivot = null;
|
||||
|
||||
|
||||
// Pivots
|
||||
if (facetRequest.pivots == null || facetRequest.pivots.size() == 0) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST, "Pivot Facets must contain at least one pivot to facet over, '" + name + "' has none.");
|
||||
}
|
||||
|
||||
|
||||
ListIterator<AnalyticsPivotRequest> iter = facetRequest.pivots.listIterator(facetRequest.pivots.size());
|
||||
while (iter.hasPrevious()) {
|
||||
topPivot = constructPivot(iter.previous(), topPivot, expressionFactory, expressions);
|
||||
}
|
||||
|
||||
|
||||
return new PivotFacet(name, topPivot);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private static PivotNode<?> constructPivot(AnalyticsPivotRequest pivotRequest,
|
||||
PivotNode<?> childPivot,
|
||||
|
@ -361,7 +361,7 @@ public class AnalyticsRequestParser {
|
|||
if (pivotRequest.expression == null) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST, "Pivots must have an expression to facet over, '" + pivotRequest.name + "' does not.");
|
||||
}
|
||||
|
||||
|
||||
// The second parameter must be a mapping expression
|
||||
AnalyticsValueStream expr = expressionFactory.createExpression(pivotRequest.expression);
|
||||
if (!expr.getExpressionType().isUnreduced()) {
|
||||
|
@ -372,21 +372,21 @@ public class AnalyticsRequestParser {
|
|||
throw new SolrException(ErrorCode.BAD_REQUEST, "Pivot expressions must be castable to string expressions, "
|
||||
+ "the following expression in pivot '" + pivotRequest.name + "' is not: '" + pivotRequest.expression);
|
||||
}
|
||||
|
||||
|
||||
PivotNode<?> pivot;
|
||||
if (childPivot == null) {
|
||||
pivot = new PivotNode.PivotLeaf(pivotRequest.name, (StringValueStream)expr);
|
||||
} else {
|
||||
pivot = new PivotNode.PivotBranch(pivotRequest.name, (StringValueStream)expr, childPivot);
|
||||
}
|
||||
|
||||
|
||||
// Check if the pivot is sorted
|
||||
if (pivotRequest.sort != null) {
|
||||
pivot.setSort(constructSort(pivotRequest.sort, expressions));
|
||||
}
|
||||
return pivot;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Range Facets
|
||||
*/
|
||||
|
@ -454,20 +454,20 @@ public class AnalyticsRequestParser {
|
|||
/*
|
||||
* Query Facets
|
||||
*/
|
||||
|
||||
|
||||
private static QueryFacet constructQueryFacet(String name, AnalyticsQueryFacetRequest facetRequest) throws SolrException {
|
||||
if (facetRequest.queries == null || facetRequest.queries.size() == 0) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST, "Query Facets must be contain at least 1 query to facet over, '" + name + "' does not.");
|
||||
}
|
||||
|
||||
|
||||
// The first param must be the facet name
|
||||
return new QueryFacet(name, facetRequest.queries);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Facet Sorting
|
||||
*/
|
||||
|
||||
|
||||
private static FacetSortSpecification constructSort(AnalyticsSortRequest sortRequest, Map<String, AnalyticsExpression> expressions) throws SolrException {
|
||||
if (sortRequest.criteria == null || sortRequest.criteria.size() == 0) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST, "Sorts must be given at least 1 criteria.");
|
||||
|
@ -501,7 +501,7 @@ public class AnalyticsRequestParser {
|
|||
}
|
||||
return DelegatingComparator.joinComparators(comparators);
|
||||
}
|
||||
|
||||
|
||||
private static FacetResultsComparator constructExpressionSortCriteria(AnalyticsExpressionSortRequest criterion, Map<String, AnalyticsExpression> expressions) {
|
||||
if (criterion.expression == null || criterion.expression.length() == 0) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"Expression Sorts must contain an expression parameter, none given.");
|
||||
|
@ -516,7 +516,7 @@ public class AnalyticsRequestParser {
|
|||
}
|
||||
return ((ComparableValue)expression.getExpression()).getObjectComparator(expression.getName());
|
||||
}
|
||||
|
||||
|
||||
private static FacetResultsComparator constructFacetValueSortCriteria(AnalyticsFacetValueSortRequest criterion) {
|
||||
return new FacetValueComparator();
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ import org.apache.solr.schema.TrieLongField;
|
|||
|
||||
/**
|
||||
* A factory to parse and create expressions, and capture information about those expressions along the way.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* In order to use, first call {@link #startRequest()} and create all ungrouped expressions,
|
||||
* then call {@link #createReductionManager} to get the ungrouped reduction manager.
|
||||
|
@ -95,40 +95,40 @@ public class ExpressionFactory {
|
|||
private HashMap<String, VariableFunctionInfo> systemVariableFunctions;
|
||||
private HashMap<String, VariableFunctionInfo> variableFunctions;
|
||||
private HashSet<String> variableFunctionNameHistory;
|
||||
|
||||
|
||||
private HashMap<String, CreatorFunction> expressionCreators;
|
||||
private final ConstantFunction constantCreator;
|
||||
|
||||
|
||||
private LinkedHashMap<String, ReductionFunction> reductionFunctions;
|
||||
private LinkedHashMap<String, ReductionDataCollector<?>> collectors;
|
||||
private LinkedHashMap<String, AnalyticsField> fields;
|
||||
private HashMap<String, AnalyticsValueStream> expressions;
|
||||
|
||||
|
||||
private IndexSchema schema;
|
||||
|
||||
|
||||
private Map<String, ReductionDataCollector<?>> groupedCollectors;
|
||||
private Map<String, AnalyticsField> groupedFields;
|
||||
private boolean isGrouped;
|
||||
|
||||
public ExpressionFactory(IndexSchema schema) {
|
||||
this.schema = schema;
|
||||
|
||||
|
||||
expressionCreators = new HashMap<>();
|
||||
systemVariableFunctions = new HashMap<>();
|
||||
|
||||
|
||||
constantCreator = ConstantValue.creatorFunction;
|
||||
addSystemFunctions();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the index schema used by this factory.
|
||||
*
|
||||
*
|
||||
* @return the index schema
|
||||
*/
|
||||
public IndexSchema getSchema() {
|
||||
return schema;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepare the factory to start building the request.
|
||||
*/
|
||||
|
@ -141,10 +141,10 @@ public class ExpressionFactory {
|
|||
variableFunctions = new HashMap<>();
|
||||
variableFunctions.putAll(systemVariableFunctions);
|
||||
variableFunctionNameHistory = new HashSet<>();
|
||||
|
||||
|
||||
isGrouped = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepare the factory to start building the next grouping.
|
||||
* <br>
|
||||
|
@ -153,14 +153,14 @@ public class ExpressionFactory {
|
|||
public void startGrouping() {
|
||||
groupedCollectors = new HashMap<>();
|
||||
groupedFields = new HashMap<>();
|
||||
|
||||
|
||||
isGrouped = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a system function to the expression factory.
|
||||
* This will be treated as a native function and not a variable function.
|
||||
*
|
||||
*
|
||||
* @param functionName the unique name for the function
|
||||
* @param functionCreator the creator function to generate an expression
|
||||
* @return this factory, to easily chain function adds
|
||||
|
@ -176,7 +176,7 @@ public class ExpressionFactory {
|
|||
|
||||
/**
|
||||
* Add a variable function that will be treated like a system function.
|
||||
*
|
||||
*
|
||||
* @param functionName the function's name
|
||||
* @param functionParams the comma separated and ordered parameters of the function (e.g. {@code "a,b"} )
|
||||
* @param returnSignature the return signature of the variable function (e.g. {@code div(sum(a,b),count(b))} )
|
||||
|
@ -184,7 +184,7 @@ public class ExpressionFactory {
|
|||
* @throws SolrException if the name of the function is not unique or the syntax of either signature is incorrect
|
||||
*/
|
||||
public ExpressionFactory addSystemVariableFunction(final String functionName, final String functionParams, final String returnSignature) throws SolrException {
|
||||
return addVariableFunction(functionName,
|
||||
return addVariableFunction(functionName,
|
||||
Arrays.stream(functionParams.split(",")).map(param -> param.trim()).toArray(size -> new String[size]),
|
||||
returnSignature,
|
||||
systemVariableFunctions);
|
||||
|
@ -192,7 +192,7 @@ public class ExpressionFactory {
|
|||
|
||||
/**
|
||||
* Add a variable function that was defined in an analytics request.
|
||||
*
|
||||
*
|
||||
* @param functionSignature the function signature of the variable function (e.g. {@code func(a,b)} )
|
||||
* @param returnSignature the return signature of the variable function (e.g. {@code div(sum(a,b),count(b))} )
|
||||
* @return this factory, to easily chain function adds
|
||||
|
@ -201,10 +201,10 @@ public class ExpressionFactory {
|
|||
public ExpressionFactory addUserDefinedVariableFunction(final String functionSignature, final String returnSignature) throws SolrException {
|
||||
return addVariableFunction(functionSignature, returnSignature, variableFunctions);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a variable function to the given map of variable functions.
|
||||
*
|
||||
* Add a variable function to the given map of variable functions.
|
||||
*
|
||||
* @param functionSignature the function signature of the variable function (e.g. {@code func(a,b)} )
|
||||
* @param returnSignature the return signature of the variable function (e.g. {@code div(sum(a,b),count(b))} )
|
||||
* @param variableFunctions the map of variable functions to add the new function to
|
||||
|
@ -217,10 +217,10 @@ public class ExpressionFactory {
|
|||
addVariableFunction(getFunctionName(functionSignature), getParams(functionSignature, null, null), returnSignature, variableFunctions);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a variable function to the given map of variable functions.
|
||||
*
|
||||
* Add a variable function to the given map of variable functions.
|
||||
*
|
||||
* @param functionName the function's name
|
||||
* @param functionParams the parameters of the function (this is ordered)
|
||||
* @param returnSignature the return signature of the variable function (e.g. {@code div(sum(a,b),count(b))} )
|
||||
|
@ -245,7 +245,7 @@ public class ExpressionFactory {
|
|||
/**
|
||||
* Create a reduction manager to manage the collection of all expressions that have been created since
|
||||
* {@link #startRequest()} was called.
|
||||
*
|
||||
*
|
||||
* @param isCloudCollection whether the request is a distributed request
|
||||
* @return a reduction manager
|
||||
*/
|
||||
|
@ -262,7 +262,7 @@ public class ExpressionFactory {
|
|||
/**
|
||||
* Create a reduction manager to manage the collection of all expressions that have been created since
|
||||
* {@link #startGrouping()} was called.
|
||||
*
|
||||
*
|
||||
* @param isCloudCollection whether the request is a distributed request
|
||||
* @return a reduction manager
|
||||
*/
|
||||
|
@ -275,10 +275,10 @@ public class ExpressionFactory {
|
|||
return new ReductionCollectionManager(collectorsArr, groupedFields.values());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse and build an expression from the given expression string.
|
||||
*
|
||||
*
|
||||
* @param expressionStr string that represents the desired expression
|
||||
* @return the object representation of the expression
|
||||
* @throws SolrException if an error occurs while constructing the expression
|
||||
|
@ -289,7 +289,7 @@ public class ExpressionFactory {
|
|||
|
||||
/**
|
||||
* Create an expression from the given expression string, with the given variable function information.
|
||||
*
|
||||
*
|
||||
* @param expressionStr string that represents the desired expression
|
||||
* @param varFuncParams the current set of variable function parameters and their values. If this expression is not a variable function
|
||||
* return signature, the map should be empty.
|
||||
|
@ -304,7 +304,7 @@ public class ExpressionFactory {
|
|||
String varFuncVarParamName, String[] varFuncVarParamValues) throws SolrException {
|
||||
AnalyticsValueStream expression;
|
||||
expressionStr = expressionStr.trim();
|
||||
|
||||
|
||||
boolean isField = false;
|
||||
try {
|
||||
// Try to make a constant value
|
||||
|
@ -363,10 +363,10 @@ public class ExpressionFactory {
|
|||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a function expression from the given expression string, with the given variable function information.
|
||||
*
|
||||
*
|
||||
* @param expressionStr string that represents the desired expression
|
||||
* @param varFuncParams the current set of variable function parameters and their values. If this expression is not a variable function
|
||||
* return signature, the map should be empty.
|
||||
|
@ -384,9 +384,9 @@ public class ExpressionFactory {
|
|||
|
||||
final String[] params = getParams(expressionStr, varFuncVarParamName, varFuncVarParamValues);
|
||||
AnalyticsValueStream[] paramStreams = new AnalyticsValueStream[params.length];
|
||||
|
||||
|
||||
boolean allParamsConstant = true;
|
||||
|
||||
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
// First check if the parameter is a variable function variable otherwise create the expression
|
||||
if (varFuncParams.containsKey(params[i])) {
|
||||
|
@ -394,22 +394,22 @@ public class ExpressionFactory {
|
|||
} else {
|
||||
paramStreams[i] = createExpression(params[i], varFuncParams, varFuncVarParamName, varFuncVarParamValues);
|
||||
}
|
||||
|
||||
|
||||
// Then update whether all of the params are constant
|
||||
allParamsConstant &= paramStreams[i].getExpressionType().equals(ExpressionType.CONST);
|
||||
}
|
||||
|
||||
|
||||
// Check to see if the function name is a variable function name, if so apply the variables to the return signature
|
||||
if (variableFunctions.containsKey(name)) {
|
||||
if (variableFunctionNameHistory.contains(name)) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The following variable function is self referencing : " + name);
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The following variable function is self referencing : " + name);
|
||||
}
|
||||
variableFunctionNameHistory.add(name);
|
||||
VariableFunctionInfo newVarFunc = variableFunctions.get(name);
|
||||
Map<String, AnalyticsValueStream> newVarFuncParams = new HashMap<>();
|
||||
|
||||
|
||||
boolean varLenEnd = false;
|
||||
|
||||
|
||||
if (paramStreams.length < newVarFunc.params.length) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The variable function '" + name + "' requires at least " + newVarFunc.params.length + " parameters."
|
||||
+ " Only " + paramStreams.length + " arguments given in the following invocation : " + expressionStr);
|
||||
|
@ -449,10 +449,10 @@ public class ExpressionFactory {
|
|||
} else {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The following function does not exist: " + name);
|
||||
}
|
||||
|
||||
|
||||
// If the all params are constant, then try to convert the expression to a constant value.
|
||||
expression = expression.convertToConstant();
|
||||
|
||||
|
||||
return expression;
|
||||
}
|
||||
|
||||
|
@ -460,7 +460,7 @@ public class ExpressionFactory {
|
|||
* Create an {@link AnalyticsField} out of the given {@link SchemaField}.
|
||||
* <p>
|
||||
* Currently only fields with doc-values enabled are supported.
|
||||
*
|
||||
*
|
||||
* @param field the field to convert for analytics
|
||||
* @return an analytics representation of the field
|
||||
* @throws SolrException if the field is not supported by the analytics framework
|
||||
|
@ -556,9 +556,9 @@ public class ExpressionFactory {
|
|||
|
||||
/**
|
||||
* Get the name of the top function used in the given expression.
|
||||
*
|
||||
*
|
||||
* @param expression the expression to find the function name of
|
||||
* @return the name of the function
|
||||
* @return the name of the function
|
||||
* @throws SolrException if the expression has incorrect syntax
|
||||
*/
|
||||
private static String getFunctionName(String expression) throws SolrException {
|
||||
|
@ -569,10 +569,10 @@ public class ExpressionFactory {
|
|||
String name = m.group(1);
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the params of a function.
|
||||
*
|
||||
*
|
||||
* @param function the function to parse
|
||||
* @return an array of param strings
|
||||
* @throws SolrException if the function has incorrect syntax
|
||||
|
@ -597,7 +597,7 @@ public class ExpressionFactory {
|
|||
* <li> {@code func('This is " the \\ escaping \' example')} will be treated as {@code func(This is " the \ escaping ' example)}
|
||||
* </ul>
|
||||
* In string constants the \ character is used to escape quotes, so it can never be used alone. in order to write a \ you must write \\
|
||||
*
|
||||
*
|
||||
* @param expression the function expression to parse
|
||||
* @param varLengthParamName the name of the variable length parameter that is used in the expression, pass null if none is used.
|
||||
* @param varLengthParamValues the values of the variable length parameter that are used in the expression, pass null if none are used.
|
||||
|
@ -610,16 +610,16 @@ public class ExpressionFactory {
|
|||
return new String[0];
|
||||
}
|
||||
String paramsStr = m.group(1);
|
||||
|
||||
|
||||
ArrayList<String> paramsList = new ArrayList<String>();
|
||||
StringBuilder param = new StringBuilder();
|
||||
|
||||
|
||||
// Variables to help while filling out the values of for-each lambda functions.
|
||||
boolean inForEach = false;
|
||||
int forEachStart = -1;
|
||||
int forEachIter = -1;
|
||||
int forEachLevel = -1;
|
||||
|
||||
|
||||
// The current level of nested parenthesis, 0 means the iteration is in no nested parentheses
|
||||
int parenCount = 0;
|
||||
// If the iteration is currently in a single-quote string constant
|
||||
|
@ -630,13 +630,13 @@ public class ExpressionFactory {
|
|||
boolean quoteOn = false;
|
||||
// Is the next character escaped.
|
||||
boolean escaped = false;
|
||||
|
||||
|
||||
char[] chars = paramsStr.toCharArray();
|
||||
|
||||
|
||||
// Iterate through every character, building the params one at a time
|
||||
for (int i = 0; i < chars.length; ++i) {
|
||||
char c = chars[i];
|
||||
|
||||
|
||||
if (c == ' ' && !quoteOn) {
|
||||
// Ignore white space that is not in string constants
|
||||
continue;
|
||||
|
@ -655,12 +655,12 @@ public class ExpressionFactory {
|
|||
} else {
|
||||
paramsList.add(paramStr);
|
||||
}
|
||||
|
||||
|
||||
param.setLength(0);
|
||||
continue;
|
||||
} else if (c == ',' && !quoteOn && inForEach) {
|
||||
// separate the for each parameters, so they can be replaced with the result of the for each
|
||||
if (param.charAt(param.length()-1) == variableForEachParam &&
|
||||
if (param.charAt(param.length()-1) == variableForEachParam &&
|
||||
(param.charAt(param.length()-2) == '(' || param.charAt(param.length()-2) == ',')) {
|
||||
param.setLength(param.length()-1);
|
||||
param.append(varLengthParamValues[forEachIter++]);
|
||||
|
@ -699,7 +699,7 @@ public class ExpressionFactory {
|
|||
throw new SolrException(ErrorCode.BAD_REQUEST,"The following expression has extra end parens: " + param.toString());
|
||||
}
|
||||
if (inForEach) {
|
||||
if (param.charAt(param.length()-1) == variableForEachParam &&
|
||||
if (param.charAt(param.length()-1) == variableForEachParam &&
|
||||
(param.charAt(param.length()-2) == '(' || param.charAt(param.length()-2) == ',')) {
|
||||
param.setLength(param.length()-1);
|
||||
param.append(varLengthParamValues[forEachIter++]);
|
||||
|
@ -774,7 +774,7 @@ public class ExpressionFactory {
|
|||
}
|
||||
return paramsList.toArray(new String[paramsList.size()]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add the natively supported functionality.
|
||||
*/
|
||||
|
@ -811,7 +811,7 @@ public class ExpressionFactory {
|
|||
expressionCreators.put(StringCastFunction.name, StringCastFunction.creatorFunction);
|
||||
expressionCreators.put(SubtractFunction.name, SubtractFunction.creatorFunction);
|
||||
expressionCreators.put(TopFunction.name, TopFunction.creatorFunction);
|
||||
|
||||
|
||||
// Reduction Functions
|
||||
expressionCreators.put(CountFunction.name, CountFunction.creatorFunction);
|
||||
expressionCreators.put(DocCountFunction.name, DocCountFunction.creatorFunction);
|
||||
|
@ -824,7 +824,7 @@ public class ExpressionFactory {
|
|||
expressionCreators.put(PercentileFunction.name, PercentileFunction.creatorFunction);
|
||||
expressionCreators.put(SumFunction.name, SumFunction.creatorFunction);
|
||||
expressionCreators.put(UniqueFunction.name, UniqueFunction.creatorFunction);
|
||||
|
||||
|
||||
// Variables
|
||||
addSystemVariableFunction(WeightedMeanVariableFunction.name, WeightedMeanVariableFunction.params, WeightedMeanVariableFunction.function);
|
||||
addSystemVariableFunction(SumOfSquaresVariableFunction.name, SumOfSquaresVariableFunction.params, SumOfSquaresVariableFunction.function);
|
||||
|
|
|
@ -31,41 +31,41 @@ import org.apache.solr.search.SolrIndexSearcher;
|
|||
|
||||
/**
|
||||
* Solr Query Facets are AnalyticsFacets that are calculated after the document streaming phase has occurred in the {@link AnalyticsDriver}
|
||||
* (during which StreamingFacets and overall expressions are calculated). {@link AbstractSolrQueryFacet}s should not be confused with {@link QueryFacet}s,
|
||||
* (during which StreamingFacets and overall expressions are calculated). {@link AbstractSolrQueryFacet}s should not be confused with {@link QueryFacet}s,
|
||||
* which are a specific sub-type.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* The filtering for these facets is done through issuing additional Solr queries, and collecting on the resulting documents.
|
||||
* Unlike streaming facets, which have an unspecified amount of facet values (facet buckets), the amount of facet values is determined by the user and
|
||||
* a Solr query is issued for each requested facet value.
|
||||
*/
|
||||
public abstract class AbstractSolrQueryFacet extends AnalyticsFacet {
|
||||
|
||||
|
||||
protected AbstractSolrQueryFacet(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set of {@link FacetValueQueryExecuter}s, one for each facet value, through the given consumer.
|
||||
*
|
||||
*
|
||||
* Each of these executors will be executed after the streaming phase in the {@link AnalyticsDriver}.
|
||||
*
|
||||
*
|
||||
* @param filter the overall filter representing the documents being used for the analytics request
|
||||
* @param queryRequest the queryRequest
|
||||
* @param queryRequest the queryRequest
|
||||
* @param consumer the consumer of each facet value's executer
|
||||
*/
|
||||
public abstract void createFacetValueExecuters(final Filter filter, SolrQueryRequest queryRequest, Consumer<FacetValueQueryExecuter> consumer);
|
||||
|
||||
|
||||
/**
|
||||
* This executer is in charge of issuing the Solr query for a facet value and collecting results as the query is processed.
|
||||
*/
|
||||
public class FacetValueQueryExecuter extends SimpleCollector {
|
||||
private final ReductionDataCollection collection;
|
||||
private final Query query;
|
||||
|
||||
|
||||
/**
|
||||
* Create an executer to collect the given reduction data from the given Solr query.
|
||||
*
|
||||
*
|
||||
* @param collection The reduction data to collect while querying
|
||||
* @param query The query used to filter for the facet value
|
||||
*/
|
||||
|
@ -92,7 +92,7 @@ public abstract class AbstractSolrQueryFacet extends AnalyticsFacet {
|
|||
|
||||
/**
|
||||
* Start the collection for this facet value.
|
||||
*
|
||||
*
|
||||
* @param searcher the solr searcher
|
||||
* @throws IOException if an exception occurs during the querying
|
||||
*/
|
||||
|
|
|
@ -38,28 +38,28 @@ public abstract class AnalyticsFacet {
|
|||
protected final Map<String,ReductionDataCollection> reductionData;
|
||||
protected ReductionCollectionManager collectionManager;
|
||||
protected ExpressionCalculator expressionCalculator;
|
||||
|
||||
|
||||
protected final String name;
|
||||
|
||||
|
||||
public AnalyticsFacet(String name) {
|
||||
this.reductionData = new LinkedHashMap<>();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the {@link ReductionCollectionManager} that manages the collection of the expressions
|
||||
* calculated with this facet.
|
||||
*
|
||||
*
|
||||
* @param collectionManager The manager for relevant expressions
|
||||
*/
|
||||
public void setReductionCollectionManager(ReductionCollectionManager collectionManager) {
|
||||
this.collectionManager = collectionManager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the {@link ExpressionCalculator} that calculates the collection of the expressions
|
||||
* requested for this facet.
|
||||
*
|
||||
*
|
||||
* @param expressionCalculator The calculator for relevant expressions
|
||||
*/
|
||||
public void setExpressionCalculator(ExpressionCalculator expressionCalculator) {
|
||||
|
@ -67,9 +67,9 @@ public abstract class AnalyticsFacet {
|
|||
}
|
||||
|
||||
/**
|
||||
* Import the shard data from a bit-stream, exported by the {@link #exportShardData} method
|
||||
* Import the shard data from a bit-stream, exported by the {@link #exportShardData} method
|
||||
* in the each of the collection's shards.
|
||||
*
|
||||
*
|
||||
* @param input The bit-stream to import the data from
|
||||
* @throws IOException if an exception occurs while reading from the {@link DataInput}
|
||||
*/
|
||||
|
@ -81,7 +81,7 @@ public abstract class AnalyticsFacet {
|
|||
}
|
||||
/**
|
||||
* Import the next facet value's set of {@link ReductionData}.
|
||||
*
|
||||
*
|
||||
* @param input the bit-stream to import the reduction data from
|
||||
* @param facetValue the next facet value
|
||||
* @throws IOException if an exception occurs while reading from the input
|
||||
|
@ -93,14 +93,14 @@ public abstract class AnalyticsFacet {
|
|||
} else {
|
||||
collectionManager.prepareReductionDataIO(dataCollection);
|
||||
}
|
||||
|
||||
|
||||
collectionManager.mergeData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Export the shard data through a bit-stream, to be imported by the {@link #importShardData} method
|
||||
* Export the shard data through a bit-stream, to be imported by the {@link #importShardData} method
|
||||
* in the originating shard.
|
||||
*
|
||||
*
|
||||
* @param output The bit-stream to output the data through
|
||||
* @throws IOException if an exception occurs while writing to the {@link DataOutput}
|
||||
*/
|
||||
|
@ -112,21 +112,21 @@ public abstract class AnalyticsFacet {
|
|||
}
|
||||
/**
|
||||
* Export the next facet value's set of {@link ReductionData}.
|
||||
*
|
||||
*
|
||||
* @param output the bit-stream to output the reduction data to
|
||||
* @param facetValue the next facet value
|
||||
* @throws IOException if an exception occurs while reading from the input
|
||||
*/
|
||||
protected void exportFacetValue(DataOutput output, String facetValue) throws IOException {
|
||||
output.writeUTF(facetValue);
|
||||
|
||||
|
||||
collectionManager.prepareReductionDataIO(reductionData.get(facetValue));
|
||||
collectionManager.exportData();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the old olap-style response of the facet to be returned in the overall analytics response.
|
||||
*
|
||||
*
|
||||
* @return the response of the facet
|
||||
*/
|
||||
public NamedList<Object> createOldResponse() {
|
||||
|
@ -137,10 +137,10 @@ public abstract class AnalyticsFacet {
|
|||
});
|
||||
return nl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the response of the facet to be returned in the overall analytics response.
|
||||
*
|
||||
*
|
||||
* @return the response of the facet
|
||||
*/
|
||||
public Iterable<Map<String,Object>> createResponse() {
|
||||
|
@ -154,10 +154,10 @@ public abstract class AnalyticsFacet {
|
|||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the Facet. This is unique for the grouping.
|
||||
*
|
||||
*
|
||||
* @return The name of the Facet
|
||||
*/
|
||||
public String getName() {
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.apache.solr.analytics.function.ReductionCollectionManager;
|
|||
import org.apache.solr.common.util.NamedList;
|
||||
|
||||
/**
|
||||
* A facet that takes in multiple ValueFacet expressions and does analytics calculations over each dimension given.
|
||||
* A facet that takes in multiple ValueFacet expressions and does analytics calculations over each dimension given.
|
||||
*/
|
||||
public class PivotFacet extends AnalyticsFacet implements StreamingFacet {
|
||||
private final PivotHead<?> pivotHead;
|
||||
|
@ -37,7 +37,7 @@ public class PivotFacet extends AnalyticsFacet implements StreamingFacet {
|
|||
super(name);
|
||||
this.pivotHead = new PivotHead(topPivot);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setReductionCollectionManager(ReductionCollectionManager collectionManager) {
|
||||
pivotHead.setReductionCollectionManager(collectionManager);
|
||||
|
@ -62,12 +62,12 @@ public class PivotFacet extends AnalyticsFacet implements StreamingFacet {
|
|||
public void exportShardData(DataOutput output) throws IOException {
|
||||
pivotHead.exportShardData(output);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NamedList<Object> createOldResponse() {
|
||||
return new NamedList<>();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Iterable<Map<String,Object>> createResponse() {
|
||||
return pivotHead.createResponse();
|
||||
|
@ -75,22 +75,22 @@ public class PivotFacet extends AnalyticsFacet implements StreamingFacet {
|
|||
}
|
||||
/**
|
||||
* Typed Pivot class that stores the overall Pivot data and head of the Pivot node chain.
|
||||
*
|
||||
*
|
||||
* This class exists so that the {@link PivotFacet} class doesn't have to be typed ( {@code <T>} ).
|
||||
*/
|
||||
class PivotHead<T> implements StreamingFacet {
|
||||
private final PivotNode<T> topPivot;
|
||||
private final Map<String, T> pivotValues;
|
||||
|
||||
|
||||
public PivotHead(PivotNode<T> topPivot) {
|
||||
this.topPivot = topPivot;
|
||||
this.pivotValues = new HashMap<>();
|
||||
}
|
||||
|
||||
|
||||
public void setReductionCollectionManager(ReductionCollectionManager collectionManager) {
|
||||
topPivot.setReductionCollectionManager(collectionManager);
|
||||
}
|
||||
|
||||
|
||||
public void setExpressionCalculator(ExpressionCalculator expressionCalculator) {
|
||||
topPivot.setExpressionCalculator(expressionCalculator);
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ class PivotHead<T> implements StreamingFacet {
|
|||
public void exportShardData(DataOutput output) throws IOException {
|
||||
topPivot.exportPivot(output, pivotValues);
|
||||
}
|
||||
|
||||
|
||||
public Iterable<Map<String,Object>> createResponse() {
|
||||
return topPivot.getPivotedResponse(pivotValues);
|
||||
}
|
||||
|
|
|
@ -55,11 +55,11 @@ public abstract class PivotNode<T> extends SortableFacet implements Consumer<Str
|
|||
currentPivot = pivot;
|
||||
expression.streamStrings(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Import the shard data from a bit-stream for the given pivot, exported by the {@link #exportPivot} method
|
||||
* 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}
|
||||
|
@ -73,7 +73,7 @@ public abstract class PivotNode<T> extends SortableFacet implements Consumer<Str
|
|||
}
|
||||
/**
|
||||
* 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
|
||||
|
@ -81,9 +81,9 @@ public abstract class PivotNode<T> extends SortableFacet implements Consumer<Str
|
|||
protected abstract void importPivotValue(DataInput input, String pivotValue) throws IOException;
|
||||
|
||||
/**
|
||||
* Export the shard data through a bit-stream for the given pivot,
|
||||
* 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}
|
||||
|
@ -97,21 +97,21 @@ public abstract class PivotNode<T> extends SortableFacet implements Consumer<Str
|
|||
}
|
||||
/**
|
||||
* 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<Map<String,Object>> getPivotedResponse(Map<String,T> pivot);
|
||||
|
||||
|
||||
/**
|
||||
* A pivot node that has no pivot children.
|
||||
*/
|
||||
|
@ -120,7 +120,7 @@ public abstract class PivotNode<T> extends SortableFacet implements Consumer<Str
|
|||
public PivotLeaf(String name, StringValueStream expression) {
|
||||
super(name, expression);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void accept(String pivotValue) {
|
||||
ReductionDataCollection collection = currentPivot.get(pivotValue);
|
||||
|
@ -170,7 +170,7 @@ public abstract class PivotNode<T> extends SortableFacet implements Consumer<Str
|
|||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A pivot node that has pivot children.
|
||||
*/
|
||||
|
@ -180,7 +180,7 @@ public abstract class PivotNode<T> extends SortableFacet implements Consumer<Str
|
|||
super(name, expression);
|
||||
this.childPivot = childPivot;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setReductionCollectionManager(ReductionCollectionManager collectionManager) {
|
||||
super.setReductionCollectionManager(collectionManager);
|
||||
|
@ -192,7 +192,7 @@ public abstract class PivotNode<T> extends SortableFacet implements Consumer<Str
|
|||
super.setExpressionCalculator(expressionCalculator);
|
||||
childPivot.setExpressionCalculator(expressionCalculator);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void accept(String pivotValue) {
|
||||
PivotDataPair<T> pivotData = currentPivot.get(pivotValue);
|
||||
|
@ -226,7 +226,7 @@ public abstract class PivotNode<T> extends SortableFacet implements Consumer<Str
|
|||
protected void exportPivotValue(DataOutput output, PivotDataPair<T> pivotData) throws IOException {
|
||||
collectionManager.prepareReductionDataIO(pivotData.pivotReduction);
|
||||
collectionManager.exportData();
|
||||
|
||||
|
||||
childPivot.exportPivot(output, pivotData.childPivots);
|
||||
}
|
||||
|
||||
|
@ -251,7 +251,7 @@ public abstract class PivotNode<T> extends SortableFacet implements Consumer<Str
|
|||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Contains pivot data for {@link PivotNode.PivotBranch} classes.
|
||||
*/
|
||||
|
|
|
@ -34,12 +34,12 @@ import org.apache.solr.search.QParser;
|
|||
*/
|
||||
public class QueryFacet extends AbstractSolrQueryFacet {
|
||||
private final Map<String,String> queries;
|
||||
|
||||
|
||||
public QueryFacet(String name, Map<String, String> queries) {
|
||||
super(name);
|
||||
this.queries = queries;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void createFacetValueExecuters(final Filter filter, SolrQueryRequest queryRequest, Consumer<FacetValueQueryExecuter> consumer) {
|
||||
queries.forEach( (queryName, query) -> {
|
||||
|
|
|
@ -43,7 +43,7 @@ public class RangeFacet extends AbstractSolrQueryFacet {
|
|||
protected boolean hardEnd = false;
|
||||
protected EnumSet<FacetRangeInclude> include;
|
||||
protected EnumSet<FacetRangeOther> others;
|
||||
|
||||
|
||||
public RangeFacet(String name, SchemaField field, String start, String end, List<String> gaps) {
|
||||
super(name);
|
||||
this.field = field;
|
||||
|
@ -59,8 +59,8 @@ public class RangeFacet extends AbstractSolrQueryFacet {
|
|||
// Computes the end points of the ranges in the rangeFacet
|
||||
final FacetRangeGenerator<? extends Comparable<?>> rec = FacetRangeGenerator.create(this);
|
||||
final SchemaField sf = field;
|
||||
|
||||
// Create a rangeFacetAccumulator for each range and
|
||||
|
||||
// Create a rangeFacetAccumulator for each range and
|
||||
// collect the documents for that range.
|
||||
for (FacetRange range : rec.getRanges()) {
|
||||
Query q = sf.getType().getRangeQuery(null, sf, range.lower, range.upper, range.includeLower,range.includeUpper);
|
||||
|
@ -70,7 +70,7 @@ public class RangeFacet extends AbstractSolrQueryFacet {
|
|||
.add(q, Occur.MUST)
|
||||
.add(filter, Occur.FILTER)
|
||||
.build();
|
||||
|
||||
|
||||
ReductionDataCollection dataCol = collectionManager.newDataCollection();
|
||||
reductionData.put(range.toString(), dataCol);
|
||||
consumer.accept(new FacetValueQueryExecuter(dataCol, rangeQuery));
|
||||
|
@ -112,7 +112,7 @@ public class RangeFacet extends AbstractSolrQueryFacet {
|
|||
public void setOthers(EnumSet<FacetRangeOther> others) {
|
||||
this.others = others;
|
||||
}
|
||||
|
||||
|
||||
public SchemaField getField() {
|
||||
return field;
|
||||
}
|
||||
|
|
|
@ -35,11 +35,11 @@ import com.google.common.collect.Iterables;
|
|||
*/
|
||||
public abstract class SortableFacet extends AnalyticsFacet {
|
||||
protected FacetSortSpecification sort = null;
|
||||
|
||||
|
||||
protected SortableFacet(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NamedList<Object> createOldResponse() {
|
||||
final NamedList<Object> results = new NamedList<>();
|
||||
|
@ -49,7 +49,7 @@ public abstract class SortableFacet extends AnalyticsFacet {
|
|||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Iterable<Map<String,Object>> createResponse() {
|
||||
final LinkedList<Map<String,Object>> results = new LinkedList<>();
|
||||
|
@ -62,20 +62,20 @@ public abstract class SortableFacet extends AnalyticsFacet {
|
|||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
private Iterable<FacetBucket> getBuckets() {
|
||||
final List<FacetBucket> facetResults = new ArrayList<>();
|
||||
reductionData.forEach((facetVal, dataCol) -> {
|
||||
collectionManager.setData(dataCol);
|
||||
facetResults.add(new FacetBucket(facetVal,expressionCalculator.getResults()));
|
||||
});
|
||||
|
||||
|
||||
return applyOptions(facetResults);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the sorting options to the given facet results.
|
||||
*
|
||||
*
|
||||
* @param facetResults to apply sorting options to
|
||||
* @return the sorted results
|
||||
*/
|
||||
|
@ -87,7 +87,7 @@ public abstract class SortableFacet extends AnalyticsFacet {
|
|||
}
|
||||
Comparator comp = sort.getComparator();
|
||||
Collections.sort(facetResults, comp);
|
||||
|
||||
|
||||
Iterable<FacetBucket> facetResultsIter = facetResults;
|
||||
// apply the limit
|
||||
if (sort.getLimit() > 0) {
|
||||
|
@ -100,7 +100,7 @@ public abstract class SortableFacet extends AnalyticsFacet {
|
|||
}
|
||||
return facetResultsIter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Specifies how to sort the buckets of a sortable facet.
|
||||
*/
|
||||
|
@ -108,7 +108,7 @@ public abstract class SortableFacet extends AnalyticsFacet {
|
|||
private FacetResultsComparator comparator;
|
||||
protected int limit;
|
||||
protected int offset;
|
||||
|
||||
|
||||
public FacetSortSpecification(FacetResultsComparator comparator, int limit, int offset) {
|
||||
this.comparator = comparator;
|
||||
this.limit = limit;
|
||||
|
@ -121,7 +121,7 @@ public abstract class SortableFacet extends AnalyticsFacet {
|
|||
|
||||
/**
|
||||
* Get the maximum number of buckets to be returned.
|
||||
*
|
||||
*
|
||||
* @return the limit
|
||||
*/
|
||||
public int getLimit() {
|
||||
|
@ -129,16 +129,16 @@ public abstract class SortableFacet extends AnalyticsFacet {
|
|||
}
|
||||
/**
|
||||
* Set the maximum number of buckets to be returned.
|
||||
*
|
||||
*
|
||||
* @param limit the maximum number of buckets
|
||||
*/
|
||||
public void setLimit(int limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the first bucket to return, has to be used with the {@code limit} option.
|
||||
*
|
||||
*
|
||||
* @return the bucket offset
|
||||
*/
|
||||
public int getOffset() {
|
||||
|
@ -153,24 +153,24 @@ public abstract class SortableFacet extends AnalyticsFacet {
|
|||
public void setSort(SortableFacet.FacetSortSpecification sort) {
|
||||
this.sort = sort;
|
||||
}
|
||||
|
||||
|
||||
public static class FacetBucket {
|
||||
private final String facetValue;
|
||||
private final Map<String,Object> expressionResults;
|
||||
|
||||
|
||||
public FacetBucket(String facetValue, Map<String,Object> expressionResults) {
|
||||
this.facetValue = facetValue;
|
||||
this.expressionResults = expressionResults;
|
||||
}
|
||||
|
||||
|
||||
public Object getResult(String expression) {
|
||||
return expressionResults.get(expression);
|
||||
}
|
||||
|
||||
|
||||
public Map<String,Object> getResults() {
|
||||
return expressionResults;
|
||||
}
|
||||
|
||||
|
||||
public String getFacetValue() {
|
||||
return facetValue;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public class ValueFacet extends SortableFacet implements StreamingFacet, Consume
|
|||
public void addFacetValueCollectionTargets() {
|
||||
expression.streamStrings(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void accept(String t) {
|
||||
ReductionDataCollection collection = reductionData.get(t);
|
||||
|
@ -48,10 +48,10 @@ public class ValueFacet extends SortableFacet implements StreamingFacet, Consume
|
|||
collectionManager.addCollectTarget(collection);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the expression used to create the facet values.
|
||||
*
|
||||
*
|
||||
* @return a string mapping expression
|
||||
*/
|
||||
public StringValueStream getExpression() {
|
||||
|
|
|
@ -27,17 +27,17 @@ import org.apache.solr.common.SolrException.ErrorCode;
|
|||
*/
|
||||
public class DelegatingComparator extends FacetResultsComparator {
|
||||
private final Iterable<FacetResultsComparator> comparators;
|
||||
|
||||
|
||||
/**
|
||||
* Create a delegating results comparator. This comparator will in succession use the given comparators, continuing if the values are equal.
|
||||
* Two buckets are considered equal if and only if all comparators find them equal
|
||||
*
|
||||
*
|
||||
* @param comparators the comparators to use in succession
|
||||
*/
|
||||
private DelegatingComparator(Iterable<FacetResultsComparator> comparators) {
|
||||
this.comparators = comparators;
|
||||
}
|
||||
|
||||
|
||||
public static FacetResultsComparator joinComparators(Collection<FacetResultsComparator> comparators) throws SolrException {
|
||||
if (comparators.size() == 0) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"A sort must have at least 1 comparator criteria.");
|
||||
|
|
|
@ -23,16 +23,16 @@ import org.apache.solr.analytics.facet.SortableFacet.FacetBucket;
|
|||
*/
|
||||
public class ExpressionComparator<T extends Comparable<T>> extends FacetResultsComparator {
|
||||
private final String expression;
|
||||
|
||||
|
||||
/**
|
||||
* Create an entry comparator comparing the given expression.
|
||||
*
|
||||
*
|
||||
* @param expression the name of the expression results to compare
|
||||
*/
|
||||
public ExpressionComparator(String expression) {
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public int compare(FacetBucket b1, FacetBucket b2) {
|
||||
T t1 = (T)b1.getResult(expression);
|
||||
|
|
|
@ -25,26 +25,26 @@ import org.apache.solr.analytics.facet.SortableFacet.FacetBucket;
|
|||
*/
|
||||
public abstract class FacetResultsComparator implements Comparator<FacetBucket> {
|
||||
protected int resultMult;
|
||||
|
||||
|
||||
/**
|
||||
* Create a results comparator assuming an ascending ordering.
|
||||
*/
|
||||
public FacetResultsComparator() {
|
||||
setDirection(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the order direction for comparison.
|
||||
*
|
||||
*
|
||||
* @param ascending whether to compare using an ascending ordering
|
||||
*/
|
||||
public void setDirection(boolean ascending) {
|
||||
this.resultMult = ascending ? 1 : -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compare one facet bucket to another.
|
||||
*
|
||||
*
|
||||
* @param b1 the first bucket to compare
|
||||
* @param b2 the second bucket to compare
|
||||
*/
|
||||
|
|
|
@ -22,14 +22,14 @@ import org.apache.solr.analytics.facet.SortableFacet.FacetBucket;
|
|||
* A results comparator that compares the name of facet value buckets, which is the string value of the facet value.
|
||||
*/
|
||||
public class FacetValueComparator extends FacetResultsComparator {
|
||||
|
||||
|
||||
/**
|
||||
* Create a facet value comparator.
|
||||
*/
|
||||
public FacetValueComparator() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compare(FacetBucket b1, FacetBucket b2) {
|
||||
return b1.getFacetValue().compareTo(b2.getFacetValue()) * resultMult;
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Comparators used to sort the buckets of an analytics facet.
|
||||
*/
|
||||
package org.apache.solr.analytics.facet.compare;
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Facets supported by the analytics component.
|
||||
*/
|
||||
package org.apache.solr.analytics.facet;
|
||||
|
|
|
@ -37,11 +37,11 @@ public class ExpressionCalculator {
|
|||
/**
|
||||
* Calculate results for the list of {@link AnalyticsExpression}s.
|
||||
* <p>
|
||||
* NOTE: This method can, and is, called multiple times to generate different responses.
|
||||
* NOTE: This method can, and is, called multiple times to generate different responses.
|
||||
* <br>
|
||||
* The results are determined by which {@link ReductionDataCollection} is passed to the {@link ReductionCollectionManager#setData}
|
||||
* method of the {@link ReductionCollectionManager} managing the reduction for the list of {@link AnalyticsExpression}s.
|
||||
*
|
||||
*
|
||||
* @return a {@link NamedList} containing the results
|
||||
*/
|
||||
public Map<String,Object> getResults() {
|
||||
|
@ -58,11 +58,11 @@ public class ExpressionCalculator {
|
|||
/**
|
||||
* Calculate results for the list of {@link AnalyticsExpression}s and add them to the given response.
|
||||
* <p>
|
||||
* NOTE: This method can, and is, called multiple times to generate different responses.
|
||||
* NOTE: This method can, and is, called multiple times to generate different responses.
|
||||
* <br>
|
||||
* The results are determined by which {@link ReductionDataCollection} is passed to the {@link ReductionCollectionManager#setData}
|
||||
* method of the {@link ReductionCollectionManager} managing the reduction for the list of {@link AnalyticsExpression}s.
|
||||
*
|
||||
*
|
||||
* @param response the response to add the results map to.
|
||||
*/
|
||||
public void addResults(Map<String,Object> response) {
|
||||
|
|
|
@ -23,20 +23,20 @@ import org.apache.solr.analytics.function.reduction.data.ReductionDataCollector;
|
|||
* The {@link ReductionCollectionManager} used for distributed requests.
|
||||
*/
|
||||
public class MergingReductionCollectionManager extends ReductionCollectionManager {
|
||||
|
||||
|
||||
public MergingReductionCollectionManager() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public MergingReductionCollectionManager(final ReductionDataCollector<?>[] reductionDataCollectors, final Iterable<AnalyticsField> fields) {
|
||||
super(reductionDataCollectors, fields);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected ReductionCollectionManager createNewManager(final ReductionDataCollector<?>[] reductionDataCollectors, final Iterable<AnalyticsField> fields) {
|
||||
return new MergingReductionCollectionManager(reductionDataCollectors,fields);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setData(ReductionDataCollection dataCollection) {
|
||||
for (int i = 0; i < reductionDataCollectors.length; i++) {
|
||||
|
|
|
@ -46,44 +46,44 @@ public class ReductionCollectionManager {
|
|||
|
||||
private final List<ReductionDataReader<?>> readers;
|
||||
private final List<ReductionDataWriter<?>> writers;
|
||||
|
||||
|
||||
private final Iterable<AnalyticsField> fields;
|
||||
|
||||
|
||||
public ReductionCollectionManager() {
|
||||
this(new ReductionDataCollector<?>[0], new ArrayList<>(0));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a Manager to oversee the given {@link ReductionDataCollector}s.
|
||||
*
|
||||
*
|
||||
* @param reductionDataCollectors array of collectors that are collecting over the same set of data
|
||||
* @param fields all fields used by the given collectors
|
||||
*/
|
||||
public ReductionCollectionManager(final ReductionDataCollector<?>[] reductionDataCollectors, final Iterable<AnalyticsField> fields) {
|
||||
this.reductionDataCollectors = reductionDataCollectors;
|
||||
Arrays.sort(reductionDataCollectors, (a,b) -> a.getExpressionStr().compareTo(b.getExpressionStr()));
|
||||
|
||||
|
||||
reservations = new LinkedList<>();
|
||||
for (int i = 0; i < reductionDataCollectors.length; i++) {
|
||||
reductionDataCollectors[i].submitReservations(reservation -> reservations.add(reservation));
|
||||
}
|
||||
|
||||
|
||||
this.fields = fields;
|
||||
|
||||
|
||||
this.readers = new ArrayList<>();
|
||||
this.writers = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return whether or not the manager needs collection done, which is false if no collectors are
|
||||
* Return whether or not the manager needs collection done, which is false if no collectors are
|
||||
* being managed and true if at least one is.
|
||||
*
|
||||
*
|
||||
* @return true if at least one collector is being managed
|
||||
*/
|
||||
public boolean needsCollection() {
|
||||
return reductionDataCollectors.length > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Merge this collection manager with others.
|
||||
*
|
||||
|
@ -93,12 +93,12 @@ public class ReductionCollectionManager {
|
|||
public ReductionCollectionManager merge(Iterable<ReductionCollectionManager> reductionManagers) {
|
||||
HashMap<String,ReductionDataCollector<?>> mergedCollectors = new HashMap<>();
|
||||
HashMap<String,AnalyticsField> mergedFields = new HashMap<>();
|
||||
|
||||
|
||||
for (ReductionDataCollector<?> collector : reductionDataCollectors) {
|
||||
mergedCollectors.put(collector.getExpressionStr(), collector);
|
||||
}
|
||||
fields.forEach( field -> mergedFields.put(field.getExpressionStr(), field) );
|
||||
|
||||
|
||||
reductionManagers.forEach( manager -> {
|
||||
for (ReductionDataCollector<?> collector : manager.reductionDataCollectors) {
|
||||
mergedCollectors.put(collector.getExpressionStr(), collector);
|
||||
|
@ -109,10 +109,10 @@ public class ReductionCollectionManager {
|
|||
mergedCollectors.values().toArray(collectors);
|
||||
return createNewManager(collectors, mergedFields.values());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an {@link ReductionCollectionManager} to manage the given collectors and fields.
|
||||
*
|
||||
*
|
||||
* @param reductionDataCollectors Reduction collectors
|
||||
* @param fields fields used by the reductions
|
||||
* @return a collection manager
|
||||
|
@ -120,19 +120,19 @@ public class ReductionCollectionManager {
|
|||
protected ReductionCollectionManager createNewManager(final ReductionDataCollector<?>[] reductionDataCollectors, final Iterable<AnalyticsField> fields) {
|
||||
return new ReductionCollectionManager(reductionDataCollectors,fields);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the {@link AnalyticsField}s used in the managed expressions.
|
||||
*
|
||||
*
|
||||
* @return the fields used
|
||||
*/
|
||||
public Iterable<AnalyticsField> getUsedFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the context of the readers of the used {@link AnalyticsField}s.
|
||||
*
|
||||
*
|
||||
* @param context the reader context
|
||||
* @throws IOException if an error occurs while setting the fields' context
|
||||
*/
|
||||
|
@ -141,10 +141,10 @@ public class ReductionCollectionManager {
|
|||
field.doSetNextReader(context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Collect the values from the used {@link AnalyticsField}s.
|
||||
*
|
||||
*
|
||||
* @param doc the document to collect values for
|
||||
* @throws IOException if an error occurs during field collection
|
||||
*/
|
||||
|
@ -153,11 +153,11 @@ public class ReductionCollectionManager {
|
|||
field.collect(doc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a {@link ReductionDataCollection} to target while collecting documents.
|
||||
* This target is valid until the lasting targets are cleared.
|
||||
*
|
||||
*
|
||||
* @param target data collection to add document data too
|
||||
*/
|
||||
public void addLastingCollectTarget(ReductionDataCollection target) {
|
||||
|
@ -173,11 +173,11 @@ public class ReductionCollectionManager {
|
|||
reductionDataCollectors[i].clearLastingCollectTargets();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a new {@link ReductionDataCollection} to target while collecting the next document.
|
||||
* This target is only valid for the next {@link #apply()} call.
|
||||
*
|
||||
*
|
||||
* @return the new data collection being targeted
|
||||
*/
|
||||
public ReductionDataCollection newDataCollectionTarget() {
|
||||
|
@ -191,7 +191,7 @@ public class ReductionCollectionManager {
|
|||
/**
|
||||
* Add a {@link ReductionDataCollection} to target while collecting the next document.
|
||||
* This target is only valid for the next {@link #apply()} call.
|
||||
*
|
||||
*
|
||||
* @param target data collection to add document data too
|
||||
*/
|
||||
public void addCollectTarget(ReductionDataCollection target) {
|
||||
|
@ -199,7 +199,7 @@ public class ReductionCollectionManager {
|
|||
reductionDataCollectors[i].addCollectTarget(target.dataArr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply the values of the collected fields through the expressions' logic to the managed data collectors.
|
||||
* This is called after {@link #collect(int)} has been called and the collection targets have been added.
|
||||
|
@ -209,13 +209,13 @@ public class ReductionCollectionManager {
|
|||
reductionDataCollectors[i].collectAndApply();;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finalize the reductions with the collected data stored in the parameter.
|
||||
* Once the data is finalized, the {@link ReductionFunction}s that use these
|
||||
* {@link ReductionDataCollector}s act like regular {@link AnalyticsValue} classes that
|
||||
* Once the data is finalized, the {@link ReductionFunction}s that use these
|
||||
* {@link ReductionDataCollector}s act like regular {@link AnalyticsValue} classes that
|
||||
* can be accessed through their {@code get<value-type>} methods.
|
||||
*
|
||||
*
|
||||
* @param dataCollection the collection of reduction data to compute results for
|
||||
*/
|
||||
public void setData(ReductionDataCollection dataCollection) {
|
||||
|
@ -223,10 +223,10 @@ public class ReductionCollectionManager {
|
|||
reductionDataCollectors[i].setData(dataCollection.dataArr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new data collection holding data for all managed data collectors.
|
||||
*
|
||||
*
|
||||
* @return a new data collection
|
||||
*/
|
||||
public ReductionDataCollection newDataCollection() {
|
||||
|
@ -237,10 +237,10 @@ public class ReductionCollectionManager {
|
|||
}
|
||||
return newCol;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the stream of shard data to merge with.
|
||||
*
|
||||
*
|
||||
* @param input the stream of shard data
|
||||
*/
|
||||
public void setShardInput(DataInput input) {
|
||||
|
@ -251,7 +251,7 @@ public class ReductionCollectionManager {
|
|||
* Merge the data from the given shard input stream into the set IO data collectors.
|
||||
* Should always be called after {@link #setShardInput(DataInput)} and either {@link #prepareReductionDataIO(ReductionDataCollection)}
|
||||
* or {@link #newDataCollectionIO()} have been called.
|
||||
*
|
||||
*
|
||||
* @throws IOException if an error occurs while reading the shard data
|
||||
*/
|
||||
public void mergeData() throws IOException {
|
||||
|
@ -259,10 +259,10 @@ public class ReductionCollectionManager {
|
|||
reader.read();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the stream to export shard data to.
|
||||
*
|
||||
*
|
||||
* @param output the stream of shard data
|
||||
*/
|
||||
public void setShardOutput(DataOutput output) {
|
||||
|
@ -272,7 +272,7 @@ public class ReductionCollectionManager {
|
|||
/**
|
||||
* Export the data from the set IO data collectors to the given shard output stream.
|
||||
* Should always be called after {@link #setShardOutput(DataOutput)} and {@link #prepareReductionDataIO(ReductionDataCollection)}.
|
||||
*
|
||||
*
|
||||
* @throws IOException if an error occurs while writing the shard data
|
||||
*/
|
||||
public void exportData() throws IOException {
|
||||
|
@ -280,10 +280,10 @@ public class ReductionCollectionManager {
|
|||
writer.write();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the given data collection to be used for either merging or exporting
|
||||
*
|
||||
*
|
||||
* @param col collection to export from or merge to
|
||||
*/
|
||||
public void prepareReductionDataIO(ReductionDataCollection col) {
|
||||
|
@ -291,11 +291,11 @@ public class ReductionCollectionManager {
|
|||
reductionDataCollectors[i].dataIO(col.dataArr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new {@link ReductionDataCollection} to merge to or export from.
|
||||
* Mainly used for creating facet value collectors when merging shard data.
|
||||
*
|
||||
*
|
||||
* @return the new data collection created
|
||||
*/
|
||||
public ReductionDataCollection newDataCollectionIO() {
|
||||
|
@ -306,10 +306,10 @@ public class ReductionCollectionManager {
|
|||
}
|
||||
return newCol;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Holds the collection of {@link ReductionData} that will be updated together.
|
||||
*
|
||||
*
|
||||
* For example each grouping will have a separate {@link ReductionDataCollection}, and
|
||||
* ungrouped expressions will have their own as well.
|
||||
*/
|
||||
|
|
|
@ -29,7 +29,7 @@ public interface ReductionFunction extends AnalyticsValue {
|
|||
/**
|
||||
* Syncs the data collectors with shared versions across the entire Analytics Request
|
||||
* so that as little data as possible is sent across shards.
|
||||
*
|
||||
*
|
||||
* @param sync a function that takes in a {@link ReductionDataCollector} and returns a shared version
|
||||
*/
|
||||
void synchronizeDataCollectors(UnaryOperator<ReductionDataCollector<?>> sync);
|
||||
|
|
|
@ -22,19 +22,19 @@ import org.apache.lucene.index.LeafReaderContext;
|
|||
import org.apache.solr.analytics.value.AnalyticsValueStream;
|
||||
|
||||
/**
|
||||
* An analytics wrapper for Solr Fields.
|
||||
*
|
||||
* An analytics wrapper for Solr Fields.
|
||||
*
|
||||
* Currently only fields with Doc Values enabled can be used in Analytics queries.
|
||||
*/
|
||||
public abstract class AnalyticsField implements AnalyticsValueStream {
|
||||
protected static final int initialArrayLength = 20;
|
||||
|
||||
|
||||
protected final String fieldName;
|
||||
|
||||
|
||||
protected AnalyticsField(String fieldName) {
|
||||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getExpressionStr() {
|
||||
return fieldName;
|
||||
|
@ -44,28 +44,28 @@ public abstract class AnalyticsField implements AnalyticsValueStream {
|
|||
public String getName() {
|
||||
return fieldName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ExpressionType getExpressionType() {
|
||||
return ExpressionType.FIELD;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AnalyticsValueStream convertToConstant() {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the segment reader context
|
||||
*
|
||||
*
|
||||
* @param context segment context
|
||||
* @throws IOException if an error occurs while loading the leaf reader
|
||||
*/
|
||||
public abstract void doSetNextReader(LeafReaderContext context) throws IOException;
|
||||
|
||||
|
||||
/**
|
||||
* Collect the value(s) of the wrapped field for the given document, and store the value.
|
||||
*
|
||||
*
|
||||
* @param doc ID of the document to collect
|
||||
* @throws IOException if an error occurs while reading the document.
|
||||
*/
|
||||
|
|
|
@ -40,7 +40,7 @@ public class BooleanField extends AnalyticsField implements CastingBooleanValue
|
|||
public BooleanField(String fieldName) {
|
||||
super(fieldName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doSetNextReader(LeafReaderContext context) throws IOException {
|
||||
docValues = DocValues.getSorted(context.reader(), fieldName);
|
||||
|
@ -84,7 +84,7 @@ public class BooleanField extends AnalyticsField implements CastingBooleanValue
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void streamBooleans(BooleanConsumer cons) {
|
||||
if (exists) {
|
||||
|
|
|
@ -35,7 +35,7 @@ public class BooleanMultiField extends AnalyticsField implements CastingBooleanV
|
|||
private SortedSetDocValues docValues;
|
||||
private int count;
|
||||
private boolean[] values;
|
||||
|
||||
|
||||
private int trueOrd;
|
||||
|
||||
public BooleanMultiField(String fieldName) {
|
||||
|
@ -43,7 +43,7 @@ public class BooleanMultiField extends AnalyticsField implements CastingBooleanV
|
|||
count = 0;
|
||||
values = new boolean[initialArrayLength];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doSetNextReader(LeafReaderContext context) throws IOException {
|
||||
docValues = DocValues.getSortedSet(context.reader(), fieldName);
|
||||
|
@ -75,7 +75,7 @@ public class BooleanMultiField extends AnalyticsField implements CastingBooleanV
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void resizeValues() {
|
||||
boolean[] newValues = new boolean[values.length*2];
|
||||
for (int i = 0; i < count; ++i) {
|
||||
|
@ -83,7 +83,7 @@ public class BooleanMultiField extends AnalyticsField implements CastingBooleanV
|
|||
}
|
||||
values = newValues;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void streamBooleans(BooleanConsumer cons) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.apache.solr.schema.TrieDateField;
|
|||
* An analytics wrapper for a single-valued {@link TrieDateField} or {@link DatePointField} with DocValues enabled.
|
||||
*/
|
||||
public class DateField extends AnalyticsField implements CastingDateValue {
|
||||
private NumericDocValues docValues;
|
||||
private NumericDocValues docValues;
|
||||
private long value;
|
||||
private boolean exists;
|
||||
|
||||
|
@ -75,7 +75,7 @@ public class DateField extends AnalyticsField implements CastingDateValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void streamLongs(LongConsumer cons) {
|
||||
if (exists) {
|
||||
|
|
|
@ -31,7 +31,7 @@ public class DateMultiPointField extends LongMultiPointField implements CastingD
|
|||
public DateMultiPointField(String fieldName) {
|
||||
super(fieldName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void streamDates(Consumer<Date> cons) {
|
||||
streamLongs(value -> cons.accept(new Date(value)));
|
||||
|
|
|
@ -33,7 +33,7 @@ public class DateMultiTrieField extends LongMultiTrieField implements CastingDat
|
|||
public DateMultiTrieField(String fieldName) {
|
||||
super(fieldName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void streamDates(Consumer<Date> cons) {
|
||||
streamLongs(value -> cons.accept(new Date(value)));
|
||||
|
|
|
@ -39,7 +39,7 @@ public class DoubleField extends AnalyticsField implements CastingDoubleValue {
|
|||
public DoubleField(String fieldName) {
|
||||
super(fieldName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doSetNextReader(LeafReaderContext context) throws IOException {
|
||||
docValues = DocValues.getNumeric(context.reader(), fieldName);
|
||||
|
@ -69,7 +69,7 @@ public class DoubleField extends AnalyticsField implements CastingDoubleValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void streamDoubles(DoubleConsumer cons) {
|
||||
if (exists) {
|
||||
|
|
|
@ -40,7 +40,7 @@ public class DoubleMultiPointField extends AnalyticsField implements CastingDoub
|
|||
count = 0;
|
||||
values = new double[initialArrayLength];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doSetNextReader(LeafReaderContext context) throws IOException {
|
||||
docValues = DocValues.getSortedNumeric(context.reader(), fieldName);
|
||||
|
@ -57,13 +57,13 @@ public class DoubleMultiPointField extends AnalyticsField implements CastingDoub
|
|||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void resizeEmptyValues(int count) {
|
||||
if (count > values.length) {
|
||||
values = new double[count];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void streamDoubles(DoubleConsumer cons) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
|
|
|
@ -43,7 +43,7 @@ public class DoubleMultiTrieField extends AnalyticsField implements CastingDoubl
|
|||
count = 0;
|
||||
values = new double[initialArrayLength];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doSetNextReader(LeafReaderContext context) throws IOException {
|
||||
docValues = DocValues.getSortedSet(context.reader(), fieldName);
|
||||
|
@ -61,7 +61,7 @@ public class DoubleMultiTrieField extends AnalyticsField implements CastingDoubl
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void resizeValues() {
|
||||
double[] newValues = new double[values.length*2];
|
||||
for (int i = 0; i < count; ++i) {
|
||||
|
@ -69,7 +69,7 @@ public class DoubleMultiTrieField extends AnalyticsField implements CastingDoubl
|
|||
}
|
||||
values = newValues;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void streamDoubles(DoubleConsumer cons) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
|
|
|
@ -40,7 +40,7 @@ public class FloatField extends AnalyticsField implements CastingFloatValue {
|
|||
public FloatField(String fieldName) {
|
||||
super(fieldName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doSetNextReader(LeafReaderContext context) throws IOException {
|
||||
docValues = DocValues.getNumeric(context.reader(), fieldName);
|
||||
|
@ -74,7 +74,7 @@ public class FloatField extends AnalyticsField implements CastingFloatValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void streamFloats(FloatConsumer cons) {
|
||||
if (exists) {
|
||||
|
|
|
@ -41,12 +41,12 @@ public class FloatMultiPointField extends AnalyticsField implements CastingFloat
|
|||
count = 0;
|
||||
values = new float[initialArrayLength];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doSetNextReader(LeafReaderContext context) throws IOException {
|
||||
docValues = DocValues.getSortedNumeric(context.reader(), fieldName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void collect(int doc) throws IOException {
|
||||
if (docValues.advanceExact(doc)) {
|
||||
|
@ -59,13 +59,13 @@ public class FloatMultiPointField extends AnalyticsField implements CastingFloat
|
|||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void resizeEmptyValues(int count) {
|
||||
if (count > values.length) {
|
||||
values = new float[count];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void streamFloats(FloatConsumer cons) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
|
|
|
@ -44,12 +44,12 @@ public class FloatMultiTrieField extends AnalyticsField implements CastingFloatV
|
|||
count = 0;
|
||||
values = new float[initialArrayLength];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doSetNextReader(LeafReaderContext context) throws IOException {
|
||||
docValues = DocValues.getSortedSet(context.reader(), fieldName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void collect(int doc) throws IOException {
|
||||
count = 0;
|
||||
|
@ -63,7 +63,7 @@ public class FloatMultiTrieField extends AnalyticsField implements CastingFloatV
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void resizeValues() {
|
||||
float[] newValues = new float[values.length*2];
|
||||
for (int i = 0; i < count; ++i) {
|
||||
|
@ -71,7 +71,7 @@ public class FloatMultiTrieField extends AnalyticsField implements CastingFloatV
|
|||
}
|
||||
values = newValues;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void streamFloats(FloatConsumer cons) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
|
|
|
@ -38,11 +38,11 @@ public class IntField extends AnalyticsField implements CastingIntValue {
|
|||
private NumericDocValues docValues;
|
||||
private int value;
|
||||
private boolean exists;
|
||||
|
||||
|
||||
public IntField(String fieldName) {
|
||||
super(fieldName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doSetNextReader(LeafReaderContext context) throws IOException {
|
||||
docValues = DocValues.getNumeric(context.reader(), fieldName);
|
||||
|
@ -84,7 +84,7 @@ public class IntField extends AnalyticsField implements CastingIntValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void streamInts(IntConsumer cons) {
|
||||
if (exists) {
|
||||
|
|
|
@ -42,12 +42,12 @@ public class IntMultiPointField extends AnalyticsField implements CastingIntValu
|
|||
count = 0;
|
||||
values = new int[initialArrayLength];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doSetNextReader(LeafReaderContext context) throws IOException {
|
||||
docValues = DocValues.getSortedNumeric(context.reader(), fieldName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void collect(int doc) throws IOException {
|
||||
if (docValues.advanceExact(doc)) {
|
||||
|
@ -60,13 +60,13 @@ public class IntMultiPointField extends AnalyticsField implements CastingIntValu
|
|||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void resizeEmptyValues(int count) {
|
||||
if (count > values.length) {
|
||||
values = new int[count];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void streamInts(IntConsumer cons) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
|
|
|
@ -45,12 +45,12 @@ public class IntMultiTrieField extends AnalyticsField implements CastingIntValue
|
|||
count = 0;
|
||||
values = new int[initialArrayLength];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doSetNextReader(LeafReaderContext context) throws IOException {
|
||||
docValues = DocValues.getSortedSet(context.reader(), fieldName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void collect(int doc) throws IOException {
|
||||
count = 0;
|
||||
|
@ -64,7 +64,7 @@ public class IntMultiTrieField extends AnalyticsField implements CastingIntValue
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void resizeValues() {
|
||||
int[] newValues = new int[values.length*2];
|
||||
for (int i = 0; i < count; ++i) {
|
||||
|
@ -72,7 +72,7 @@ public class IntMultiTrieField extends AnalyticsField implements CastingIntValue
|
|||
}
|
||||
values = newValues;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void streamInts(IntConsumer cons) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
|
|
|
@ -40,12 +40,12 @@ public class LongMultiPointField extends AnalyticsField implements CastingLongVa
|
|||
count = 0;
|
||||
values = new long[initialArrayLength];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doSetNextReader(LeafReaderContext context) throws IOException {
|
||||
docValues = DocValues.getSortedNumeric(context.reader(), fieldName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void collect(int doc) throws IOException {
|
||||
if (docValues.advanceExact(doc)) {
|
||||
|
@ -58,13 +58,13 @@ public class LongMultiPointField extends AnalyticsField implements CastingLongVa
|
|||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void resizeEmptyValues(int count) {
|
||||
if (count > values.length) {
|
||||
values = new long[count];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void streamLongs(LongConsumer cons) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
|
|
|
@ -43,7 +43,7 @@ public class LongMultiTrieField extends AnalyticsField implements CastingLongVal
|
|||
count = 0;
|
||||
values = new long[initialArrayLength];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doSetNextReader(LeafReaderContext context) throws IOException {
|
||||
docValues = DocValues.getSortedSet(context.reader(), fieldName);
|
||||
|
@ -61,7 +61,7 @@ public class LongMultiTrieField extends AnalyticsField implements CastingLongVal
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void resizeValues() {
|
||||
long[] newValues = new long[values.length*2];
|
||||
for (int i = 0; i < count; ++i) {
|
||||
|
@ -69,7 +69,7 @@ public class LongMultiTrieField extends AnalyticsField implements CastingLongVal
|
|||
}
|
||||
values = newValues;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void streamLongs(LongConsumer cons) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
|
|
|
@ -37,7 +37,7 @@ public class StringMultiField extends AnalyticsField implements CastingStringVal
|
|||
super(fieldName);
|
||||
values = new ArrayList<>(initialArrayLength);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doSetNextReader(LeafReaderContext context) throws IOException {
|
||||
docValues = DocValues.getSortedSet(context.reader(), fieldName);
|
||||
|
@ -52,7 +52,7 @@ public class StringMultiField extends AnalyticsField implements CastingStringVal
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void streamStrings(Consumer<String> cons) {
|
||||
values.forEach(value -> cons.accept(value));
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Fields to use for analytics expressions.
|
||||
*/
|
||||
package org.apache.solr.analytics.function.field;
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.apache.solr.analytics.value.DoubleValueStream;
|
|||
* Uses:
|
||||
* <ul>
|
||||
* <li>If a single numeric ValueStream is passed in, a {@link DoubleValue} representing the sum of the values for each document is returned.
|
||||
* <li>If a numeric ValueStream and a numeric Value are passed in, a {@link DoubleValueStream} representing the sum of
|
||||
* <li>If a numeric ValueStream and a numeric Value are passed in, a {@link DoubleValueStream} representing the sum of
|
||||
* the Value and each of the values of the ValueStream for a document is returned.
|
||||
* (Or the other way, since the Value and ValueStream can be used in either order)
|
||||
* <li>If multiple numeric Values are passed in, a {@link DoubleValue} representing the sum of all values is returned.
|
||||
|
@ -40,13 +40,13 @@ public class AddFunction {
|
|||
public static final CreatorFunction creatorFunction = (params -> {
|
||||
if (params.length == 0) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires parameters.");
|
||||
}
|
||||
}
|
||||
else if (params.length == 1) {
|
||||
if (params[0] instanceof DoubleValueStream) {
|
||||
return LambdaFunction.createDoubleLambdaFunction(name, (a,b) -> a+b, (DoubleValueStream)params[0]);
|
||||
}
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires numeric parameters. Incorrect param: "+params[0].getExpressionStr());
|
||||
}
|
||||
}
|
||||
else if (params.length == 2) {
|
||||
AnalyticsValueStream param1 = params[0];
|
||||
AnalyticsValueStream param2 = params[1];
|
||||
|
|
|
@ -157,7 +157,7 @@ public class BottomFunction {
|
|||
return LambdaFunction.createStringLambdaFunction(name, (a,b) -> (a.compareTo(b)<0)? a:b, castedParams, false);
|
||||
}
|
||||
}
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a comparable parameter. " +
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a comparable parameter. " +
|
||||
"Incorrect parameter: "+params[0].getExpressionStr());
|
||||
});
|
||||
}
|
|
@ -39,15 +39,15 @@ import org.apache.solr.common.SolrException.ErrorCode;
|
|||
* Uses:
|
||||
* <ul>
|
||||
* <li>If a two comparable {@link AnalyticsValue}s are passed in, a {@link BooleanValue} representing the comparison of the two values for each document is returned.
|
||||
* <li>If a comparable {@link AnalyticsValue} and a comparable {@link AnalyticsValueStream} are passed in,
|
||||
* <li>If a comparable {@link AnalyticsValue} and a comparable {@link AnalyticsValueStream} are passed in,
|
||||
* a {@link BooleanValueStream} representing the comparison of the Value and each of the values of the ValueStream for the document is returned.
|
||||
* </ul>
|
||||
*/
|
||||
public class ComparisonFunction {
|
||||
|
||||
|
||||
/**
|
||||
* Create a comparison mapping function, comparing two analytics value (streams) of the same type.
|
||||
*
|
||||
*
|
||||
* @param name name of the function
|
||||
* @param comp function to find the result of a comparison
|
||||
* @param params the parameters to compare
|
||||
|
@ -84,7 +84,7 @@ public class ComparisonFunction {
|
|||
}
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires that at least 1 parameter be single-valued.");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A comparison function that tests whether the first parameter is greater than the second parameter
|
||||
*/
|
||||
|
@ -137,7 +137,7 @@ public class ComparisonFunction {
|
|||
public static interface CompResultFunction {
|
||||
public boolean apply(int compResult);
|
||||
}
|
||||
|
||||
|
||||
private static CompResultFunction reverse(CompResultFunction original) {
|
||||
return val -> original.apply(val*-1);
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ class CompareDoubleValueFunction extends AbstractBooleanValue {
|
|||
private final String name;
|
||||
private final String funcStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public CompareDoubleValueFunction(String name, DoubleValue exprA, DoubleValue exprB, CompResultFunction comp) {
|
||||
this.name = name;
|
||||
this.exprA = exprA;
|
||||
|
@ -198,7 +198,7 @@ class CompareDoubleStreamFunction extends AbstractBooleanValueStream {
|
|||
private final String name;
|
||||
private final String funcStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public CompareDoubleStreamFunction(String name, DoubleValue baseExpr, DoubleValueStream compExpr, CompResultFunction comp) throws SolrException {
|
||||
this.name = name;
|
||||
this.baseExpr = baseExpr;
|
||||
|
@ -239,7 +239,7 @@ class CompareDateValueFunction extends AbstractBooleanValue {
|
|||
private final String name;
|
||||
private final String funcStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public CompareDateValueFunction(String name, DateValue exprA, DateValue exprB, CompResultFunction comp) {
|
||||
this.name = name;
|
||||
this.exprA = exprA;
|
||||
|
@ -285,7 +285,7 @@ class CompareDateStreamFunction extends AbstractBooleanValueStream {
|
|||
private final String name;
|
||||
private final String funcStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public CompareDateStreamFunction(String name, DateValue baseExpr, DateValueStream compExpr, CompResultFunction comp) throws SolrException {
|
||||
this.name = name;
|
||||
this.baseExpr = baseExpr;
|
||||
|
|
|
@ -36,12 +36,12 @@ import org.apache.solr.analytics.value.constant.ConstantValue;
|
|||
* <ul>
|
||||
* <li>If a single {@link StringValueStream} is passed in, a {@link StringValue} representing the concatenation of the values for each document is returned.
|
||||
* No ordering is guaranteed while concatenating.
|
||||
* <li>If a {@link StringValue} and a {@link StringValueStream} are passed in, a {@link StringValueStream} representing the concatenation of
|
||||
* <li>If a {@link StringValue} and a {@link StringValueStream} are passed in, a {@link StringValueStream} representing the concatenation of
|
||||
* the Value and each of the values of the ValueStream for a document is returned.
|
||||
* (Or the other way, since the Value and ValueStream can be used in either order)
|
||||
* <li>If any number (more than 0) of {@link StringValue}s are passed in, a {@link StringValue} representing the concatenation of all values is returned.
|
||||
* If any values don't exist, the overall concatenation value will still exist with an empty string used for any missing values. If none of the parameter
|
||||
* values exist, then the overall concatenation value will not exist.
|
||||
* values exist, then the overall concatenation value will not exist.
|
||||
* </ul>
|
||||
*/
|
||||
public class ConcatFunction {
|
||||
|
@ -49,7 +49,7 @@ public class ConcatFunction {
|
|||
public static final CreatorFunction creatorFunction = (params -> {
|
||||
return createConcatFunction(name, name, (a,b) -> a + b, params);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* A concatenation mapping function, combining the string values of the given parameters with a given separating string.
|
||||
* <br>
|
||||
|
@ -77,7 +77,7 @@ public class ConcatFunction {
|
|||
return createConcatFunction(name, uniqueName, (a,b) -> a + sep + b, Arrays.copyOfRange(params, 1, params.length));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private static StringValueStream createConcatFunction(String functionName, String uniqueName, TwoStringInStringOutLambda lambda, AnalyticsValueStream[] params) {
|
||||
if (params.length == 0) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST, "The "+functionName+" function requires parameters.");
|
||||
|
|
|
@ -73,7 +73,7 @@ class DateMathValueFunction extends AbstractDateValue {
|
|||
public static final String name = DateMathFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DateMathValueFunction(DateValue dateParam, ConstantStringValue mathParam) throws SolrException {
|
||||
this.dateParam = dateParam;
|
||||
this.mathParam = "NOW" + mathParam.getString();
|
||||
|
@ -82,7 +82,7 @@ class DateMathValueFunction extends AbstractDateValue {
|
|||
}
|
||||
|
||||
private boolean exists = false;
|
||||
|
||||
|
||||
@Override
|
||||
public long getLong() {
|
||||
Date date = getDate();
|
||||
|
@ -126,7 +126,7 @@ class DateMathStreamFunction extends AbstractDateValueStream {
|
|||
public static final String name = DateMathFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DateMathStreamFunction(DateValueStream dateParam, ConstantStringValue mathParam) throws SolrException {
|
||||
this.dateParam = dateParam;
|
||||
this.mathParam = "NOW" + mathParam.getString();
|
||||
|
|
|
@ -57,7 +57,7 @@ public class DateParseFunction {
|
|||
return new StringStreamToDateParseFunction((StringValueStream)params[0]);
|
||||
}
|
||||
else {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a string or long parameter. " +
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a string or long parameter. " +
|
||||
"Incorrect parameter: "+params[0].getExpressionStr());
|
||||
}
|
||||
});
|
||||
|
@ -67,7 +67,7 @@ class LongToDateParseFunction extends AbstractDateValue {
|
|||
public static final String name = DateParseFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public LongToDateParseFunction(LongValue param) throws SolrException {
|
||||
this.param = param;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
@ -101,7 +101,7 @@ class LongStreamToDateParseFunction extends AbstractDateValueStream {
|
|||
public static final String name = DateParseFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public LongStreamToDateParseFunction(LongValueStream param) throws SolrException {
|
||||
this.param = param;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
@ -131,7 +131,7 @@ class StringToDateParseFunction extends AbstractDateValue {
|
|||
public static final String name = DateParseFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public StringToDateParseFunction(StringValue param) throws SolrException {
|
||||
this.param = param;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
@ -176,7 +176,7 @@ class StringStreamToDateParseFunction extends AbstractDateValueStream {
|
|||
public static final String name = DateParseFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public StringStreamToDateParseFunction(StringValueStream param) throws SolrException {
|
||||
this.param = param;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
|
|
@ -39,15 +39,15 @@ import org.apache.solr.common.SolrException;
|
|||
import org.apache.solr.common.SolrException.ErrorCode;
|
||||
|
||||
/**
|
||||
* An abstract decimal numeric converting mapping function. For example "round()" would convert a float to an int and a double to a long.
|
||||
* An abstract decimal numeric converting mapping function. For example "round()" would convert a float to an int and a double to a long.
|
||||
* <p>
|
||||
* Takes a numeric Double or Float ValueStream or Value and returns a Long or Int ValueStream or Value, respectively.
|
||||
*/
|
||||
public class DecimalNumericConversionFunction {
|
||||
|
||||
|
||||
/**
|
||||
* Create a numeric conversion mapping function.
|
||||
*
|
||||
*
|
||||
* @param name the name of the function
|
||||
* @param fconv the method to convert floats to ints
|
||||
* @param dconv the method to convert doubles to longs
|
||||
|
@ -76,7 +76,7 @@ public class DecimalNumericConversionFunction {
|
|||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a numeric parameter.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A numeric mapping function that returns the floor of the input.
|
||||
*/
|
||||
|
@ -86,7 +86,7 @@ public class DecimalNumericConversionFunction {
|
|||
return DecimalNumericConversionFunction.createDecimalConversionFunction(name, val -> (int)Math.floor(val), val -> (long)Math.floor(val), params);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A numeric mapping function that returns the ceiling of the input.
|
||||
*/
|
||||
|
@ -96,7 +96,7 @@ public class DecimalNumericConversionFunction {
|
|||
return DecimalNumericConversionFunction.createDecimalConversionFunction(name, val -> (int)Math.ceil(val), val -> (long)Math.ceil(val), params);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A numeric mapping function that returns the rounded input.
|
||||
*/
|
||||
|
@ -111,7 +111,7 @@ public class DecimalNumericConversionFunction {
|
|||
public static interface ConvertFloatFunction {
|
||||
public int convert(float value);
|
||||
}
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public static interface ConvertDoubleFunction {
|
||||
public long convert(double value);
|
||||
|
@ -126,7 +126,7 @@ class ConvertFloatValueFunction extends AbstractIntValue {
|
|||
private final ConvertFloatFunction conv;
|
||||
private final String funcStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public ConvertFloatValueFunction(String name, FloatValue param, ConvertFloatFunction conv) {
|
||||
this.name = name;
|
||||
this.param = param;
|
||||
|
@ -166,7 +166,7 @@ class ConvertFloatStreamFunction extends AbstractIntValueStream {
|
|||
private final ConvertFloatFunction conv;
|
||||
private final String funcStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public ConvertFloatStreamFunction(String name, FloatValueStream param, ConvertFloatFunction conv) {
|
||||
this.name = name;
|
||||
this.param = param;
|
||||
|
@ -202,7 +202,7 @@ class ConvertDoubleValueFunction extends AbstractLongValue {
|
|||
private final ConvertDoubleFunction conv;
|
||||
private final String funcStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public ConvertDoubleValueFunction(String name, DoubleValue param, ConvertDoubleFunction conv) {
|
||||
this.name = name;
|
||||
this.param = param;
|
||||
|
@ -242,7 +242,7 @@ class ConvertDoubleStreamFunction extends AbstractLongValueStream {
|
|||
private final ConvertDoubleFunction conv;
|
||||
private final String funcStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public ConvertDoubleStreamFunction(String name, DoubleValueStream param, ConvertDoubleFunction conv) {
|
||||
this.name = name;
|
||||
this.param = param;
|
||||
|
|
|
@ -29,8 +29,8 @@ import org.apache.solr.common.SolrException.ErrorCode;
|
|||
* Uses:
|
||||
* <ul>
|
||||
* <li>If two numeric Values are passed in, a {@link DoubleValue} representing the divison of the two values is returned.
|
||||
* <li>If a numeric ValueStream and a numeric Value are passed in, a {@link DoubleValueStream} representing the division of
|
||||
* the Value and each of the values of the ValueStream for a document is returned.
|
||||
* <li>If a numeric ValueStream and a numeric Value are passed in, a {@link DoubleValueStream} representing the division of
|
||||
* the Value and each of the values of the ValueStream for a document is returned.
|
||||
* (Or the other way, since the Value and ValueStream can be used in either order)
|
||||
* </ul>
|
||||
*/
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.apache.solr.common.SolrException.ErrorCode;
|
|||
* Uses:
|
||||
* <ul>
|
||||
* <li>If two Values are passed in, a {@link BooleanValue} representing the equality of the two values for each document is returned.
|
||||
* <li>If an {@link AnalyticsValue} and an {@link AnalyticsValueStream} are passed in,
|
||||
* <li>If an {@link AnalyticsValue} and an {@link AnalyticsValueStream} are passed in,
|
||||
* a {@link BooleanValueStream} representing the equality of the Value and each of the values of the ValueStream for the document is returned.
|
||||
* </ul>
|
||||
*/
|
||||
|
@ -44,10 +44,10 @@ public class EqualFunction {
|
|||
if (params.length != 2) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 2 paramaters, " + params.length + " found.");
|
||||
}
|
||||
|
||||
|
||||
AnalyticsValueStream paramA = params[0];
|
||||
AnalyticsValueStream paramB = params[1];
|
||||
|
||||
|
||||
// Booleans aren't really comparable, so just enable the equal function
|
||||
if (paramA instanceof BooleanValueStream && paramB instanceof BooleanValueStream) {
|
||||
if (paramA instanceof BooleanValue) {
|
||||
|
@ -83,7 +83,7 @@ class BooleanValueEqualFunction extends AbstractBooleanValue {
|
|||
public static final String name = EqualFunction.name;
|
||||
private final String funcStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public BooleanValueEqualFunction(BooleanValue exprA, BooleanValue exprB) {
|
||||
this.exprA = exprA;
|
||||
this.exprB = exprB;
|
||||
|
@ -126,7 +126,7 @@ class BooleanStreamEqualFunction extends AbstractBooleanValueStream {
|
|||
public static final String name = EqualFunction.name;
|
||||
private final String funcStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public BooleanStreamEqualFunction(BooleanValue baseExpr, BooleanValueStream compExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.compExpr = compExpr;
|
||||
|
@ -164,7 +164,7 @@ class ValueEqualFunction extends AbstractBooleanValue {
|
|||
public static final String name = EqualFunction.name;
|
||||
private final String funcStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public ValueEqualFunction(AnalyticsValue exprA, AnalyticsValue exprB) {
|
||||
this.exprA = exprA;
|
||||
this.exprB = exprB;
|
||||
|
@ -207,7 +207,7 @@ class StreamEqualFunction extends AbstractBooleanValueStream {
|
|||
public static final String name = EqualFunction.name;
|
||||
private final String funcStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public StreamEqualFunction(AnalyticsValue baseExpr, AnalyticsValueStream compExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.compExpr = compExpr;
|
||||
|
|
|
@ -35,7 +35,7 @@ public class ExistsFunction {
|
|||
public static final CreatorFunction creatorFunction = (params -> {
|
||||
if (params.length != 1) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 1 parameter.");
|
||||
}
|
||||
}
|
||||
AnalyticsValueStream param = params[0];
|
||||
if (param instanceof AnalyticsValue) {
|
||||
return new ValueExistsFunction((AnalyticsValue)param);
|
||||
|
@ -51,13 +51,13 @@ class ValueStreamExistsFunction extends AbstractBooleanValue {
|
|||
public static final String name = ExistsFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public ValueStreamExistsFunction(AnalyticsValueStream param) throws SolrException {
|
||||
this.param = param;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,param);
|
||||
}
|
||||
|
||||
|
||||
private boolean exists;
|
||||
@Override
|
||||
public boolean getBoolean() {
|
||||
|
@ -91,13 +91,13 @@ class ValueExistsFunction extends AbstractBooleanValue {
|
|||
public static final String name = ExistsFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public ValueExistsFunction(AnalyticsValue param) throws SolrException {
|
||||
this.param = param;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,param);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean getBoolean() {
|
||||
param.getObject();
|
||||
|
|
|
@ -60,7 +60,7 @@ import org.apache.solr.common.SolrException;
|
|||
import org.apache.solr.common.SolrException.ErrorCode;
|
||||
|
||||
/**
|
||||
* A mapping function to fill all non-existing values with a given value.
|
||||
* A mapping function to fill all non-existing values with a given value.
|
||||
* <p>
|
||||
* Uses:
|
||||
* <ul>
|
||||
|
@ -135,7 +135,7 @@ class StreamFillMissingFunction extends AbstractAnalyticsValueStream implements
|
|||
public static final String name = FillMissingFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public StreamFillMissingFunction(AnalyticsValueStream baseExpr, AnalyticsValueStream fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.fillExpr = fillExpr;
|
||||
|
@ -160,7 +160,7 @@ class StreamFillMissingFunction extends AbstractAnalyticsValueStream implements
|
|||
exists = true;
|
||||
cons.accept(value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -180,14 +180,14 @@ class ValueFillMissingFunction extends AbstractAnalyticsValue {
|
|||
public static final String name = FillMissingFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public ValueFillMissingFunction(AnalyticsValue baseExpr, AnalyticsValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.fillExpr = fillExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -224,7 +224,7 @@ class BooleanStreamFillMissingFunction extends AbstractBooleanValueStream implem
|
|||
public static final String name = FillMissingFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public BooleanStreamFillMissingFunction(BooleanValueStream baseExpr, BooleanValueStream fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.fillExpr = fillExpr;
|
||||
|
@ -249,7 +249,7 @@ class BooleanStreamFillMissingFunction extends AbstractBooleanValueStream implem
|
|||
exists = true;
|
||||
cons.accept(value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -269,14 +269,14 @@ class BooleanFillMissingFunction extends AbstractBooleanValue {
|
|||
public static final String name = FillMissingFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public BooleanFillMissingFunction(BooleanValue baseExpr, BooleanValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.fillExpr = fillExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -293,7 +293,7 @@ class BooleanFillMissingFunction extends AbstractBooleanValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -313,7 +313,7 @@ class IntStreamFillMissingFunction extends AbstractIntValueStream implements Int
|
|||
public static final String name = FillMissingFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public IntStreamFillMissingFunction(IntValueStream baseExpr, IntValueStream fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.fillExpr = fillExpr;
|
||||
|
@ -338,7 +338,7 @@ class IntStreamFillMissingFunction extends AbstractIntValueStream implements Int
|
|||
exists = true;
|
||||
cons.accept(value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -358,14 +358,14 @@ class IntFillMissingFunction extends AbstractIntValue {
|
|||
public static final String name = FillMissingFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public IntFillMissingFunction(IntValue baseExpr, IntValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.fillExpr = fillExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -382,7 +382,7 @@ class IntFillMissingFunction extends AbstractIntValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -402,7 +402,7 @@ class LongStreamFillMissingFunction extends AbstractLongValueStream implements L
|
|||
public static final String name = FillMissingFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public LongStreamFillMissingFunction(LongValueStream baseExpr, LongValueStream fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.fillExpr = fillExpr;
|
||||
|
@ -427,7 +427,7 @@ class LongStreamFillMissingFunction extends AbstractLongValueStream implements L
|
|||
exists = true;
|
||||
cons.accept(value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -447,14 +447,14 @@ class LongFillMissingFunction extends AbstractLongValue {
|
|||
public static final String name = FillMissingFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public LongFillMissingFunction(LongValue baseExpr, LongValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.fillExpr = fillExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -471,7 +471,7 @@ class LongFillMissingFunction extends AbstractLongValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -491,7 +491,7 @@ class FloatStreamFillMissingFunction extends AbstractFloatValueStream implements
|
|||
public static final String name = FillMissingFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public FloatStreamFillMissingFunction(FloatValueStream baseExpr, FloatValueStream fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.fillExpr = fillExpr;
|
||||
|
@ -516,7 +516,7 @@ class FloatStreamFillMissingFunction extends AbstractFloatValueStream implements
|
|||
exists = true;
|
||||
cons.accept(value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -536,14 +536,14 @@ class FloatFillMissingFunction extends AbstractFloatValue {
|
|||
public static final String name = FillMissingFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public FloatFillMissingFunction(FloatValue baseExpr, FloatValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.fillExpr = fillExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -560,7 +560,7 @@ class FloatFillMissingFunction extends AbstractFloatValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -580,7 +580,7 @@ class DoubleStreamFillMissingFunction extends AbstractDoubleValueStream implemen
|
|||
public static final String name = FillMissingFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DoubleStreamFillMissingFunction(DoubleValueStream baseExpr, DoubleValueStream fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.fillExpr = fillExpr;
|
||||
|
@ -605,7 +605,7 @@ class DoubleStreamFillMissingFunction extends AbstractDoubleValueStream implemen
|
|||
exists = true;
|
||||
cons.accept(value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -625,14 +625,14 @@ class DoubleFillMissingFunction extends AbstractDoubleValue {
|
|||
public static final String name = FillMissingFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DoubleFillMissingFunction(DoubleValue baseExpr, DoubleValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.fillExpr = fillExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -649,7 +649,7 @@ class DoubleFillMissingFunction extends AbstractDoubleValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -669,7 +669,7 @@ class DateStreamFillMissingFunction extends AbstractDateValueStream implements L
|
|||
public static final String name = FillMissingFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DateStreamFillMissingFunction(DateValueStream baseExpr, DateValueStream fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.fillExpr = fillExpr;
|
||||
|
@ -694,7 +694,7 @@ class DateStreamFillMissingFunction extends AbstractDateValueStream implements L
|
|||
exists = true;
|
||||
cons.accept(value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -714,14 +714,14 @@ class DateFillMissingFunction extends AbstractDateValue {
|
|||
public static final String name = FillMissingFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DateFillMissingFunction(DateValue baseExpr, DateValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.fillExpr = fillExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -758,7 +758,7 @@ class StringStreamFillMissingFunction extends AbstractStringValueStream implemen
|
|||
public static final String name = FillMissingFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public StringStreamFillMissingFunction(StringValueStream baseExpr, StringValueStream fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.fillExpr = fillExpr;
|
||||
|
@ -783,7 +783,7 @@ class StringStreamFillMissingFunction extends AbstractStringValueStream implemen
|
|||
exists = true;
|
||||
cons.accept(value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -803,14 +803,14 @@ class StringFillMissingFunction extends AbstractStringValue {
|
|||
public static final String name = FillMissingFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public StringFillMissingFunction(StringValue baseExpr, StringValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.fillExpr = fillExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,fillExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,fillExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -827,7 +827,7 @@ class StringFillMissingFunction extends AbstractStringValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
|
|
@ -60,7 +60,7 @@ import org.apache.solr.common.SolrException;
|
|||
import org.apache.solr.common.SolrException.ErrorCode;
|
||||
|
||||
/**
|
||||
* A mapping function to filter a Value or ValueStream. For each document, the value exists if the second parameter
|
||||
* A mapping function to filter a Value or ValueStream. For each document, the value exists if the second parameter
|
||||
* is true and it doesn't exist otherwise.
|
||||
* <p>
|
||||
* The first parameter can be any type of analytics expression. (Required)
|
||||
|
@ -135,7 +135,7 @@ class StreamFilterFunction extends AbstractAnalyticsValueStream {
|
|||
public static final String name = FilterFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public StreamFilterFunction(AnalyticsValueStream baseExpr, BooleanValue filterExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.filterExpr = filterExpr;
|
||||
|
@ -149,7 +149,7 @@ class StreamFilterFunction extends AbstractAnalyticsValueStream {
|
|||
baseExpr.streamObjects(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -169,14 +169,14 @@ class ValueFilterFunction extends AbstractAnalyticsValue {
|
|||
public static final String name = FilterFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public ValueFilterFunction(AnalyticsValue baseExpr, BooleanValue filterExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.filterExpr = filterExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -189,7 +189,7 @@ class ValueFilterFunction extends AbstractAnalyticsValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -209,7 +209,7 @@ class BooleanStreamFilterFunction extends AbstractBooleanValueStream {
|
|||
public static final String name = FilterFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public BooleanStreamFilterFunction(BooleanValueStream baseExpr, BooleanValue filterExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.filterExpr = filterExpr;
|
||||
|
@ -223,7 +223,7 @@ class BooleanStreamFilterFunction extends AbstractBooleanValueStream {
|
|||
baseExpr.streamBooleans(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -243,14 +243,14 @@ class BooleanFilterFunction extends AbstractBooleanValue {
|
|||
public static final String name = FilterFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public BooleanFilterFunction(BooleanValue baseExpr, BooleanValue filterExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.filterExpr = filterExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -263,7 +263,7 @@ class BooleanFilterFunction extends AbstractBooleanValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -283,7 +283,7 @@ class IntStreamFilterFunction extends AbstractIntValueStream {
|
|||
public static final String name = FilterFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public IntStreamFilterFunction(IntValueStream baseExpr, BooleanValue filterExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.filterExpr = filterExpr;
|
||||
|
@ -297,7 +297,7 @@ class IntStreamFilterFunction extends AbstractIntValueStream {
|
|||
baseExpr.streamInts(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -317,14 +317,14 @@ class IntFilterFunction extends AbstractIntValue {
|
|||
public static final String name = FilterFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public IntFilterFunction(IntValue baseExpr, BooleanValue filterExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.filterExpr = filterExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -337,7 +337,7 @@ class IntFilterFunction extends AbstractIntValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -357,7 +357,7 @@ class LongStreamFilterFunction extends AbstractLongValueStream {
|
|||
public static final String name = FilterFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public LongStreamFilterFunction(LongValueStream baseExpr, BooleanValue filterExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.filterExpr = filterExpr;
|
||||
|
@ -371,7 +371,7 @@ class LongStreamFilterFunction extends AbstractLongValueStream {
|
|||
baseExpr.streamLongs(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -391,14 +391,14 @@ class LongFilterFunction extends AbstractLongValue {
|
|||
public static final String name = FilterFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public LongFilterFunction(LongValue baseExpr, BooleanValue filterExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.filterExpr = filterExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -411,7 +411,7 @@ class LongFilterFunction extends AbstractLongValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -431,7 +431,7 @@ class FloatStreamFilterFunction extends AbstractFloatValueStream {
|
|||
public static final String name = FilterFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public FloatStreamFilterFunction(FloatValueStream baseExpr, BooleanValue filterExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.filterExpr = filterExpr;
|
||||
|
@ -445,7 +445,7 @@ class FloatStreamFilterFunction extends AbstractFloatValueStream {
|
|||
baseExpr.streamFloats(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -465,14 +465,14 @@ class FloatFilterFunction extends AbstractFloatValue {
|
|||
public static final String name = FilterFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public FloatFilterFunction(FloatValue baseExpr, BooleanValue filterExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.filterExpr = filterExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -485,7 +485,7 @@ class FloatFilterFunction extends AbstractFloatValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -505,7 +505,7 @@ class DoubleStreamFilterFunction extends AbstractDoubleValueStream {
|
|||
public static final String name = FilterFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DoubleStreamFilterFunction(DoubleValueStream baseExpr, BooleanValue filterExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.filterExpr = filterExpr;
|
||||
|
@ -519,7 +519,7 @@ class DoubleStreamFilterFunction extends AbstractDoubleValueStream {
|
|||
baseExpr.streamDoubles(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -539,14 +539,14 @@ class DoubleFilterFunction extends AbstractDoubleValue {
|
|||
public static final String name = FilterFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DoubleFilterFunction(DoubleValue baseExpr, BooleanValue filterExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.filterExpr = filterExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -559,7 +559,7 @@ class DoubleFilterFunction extends AbstractDoubleValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -579,7 +579,7 @@ class DateStreamFilterFunction extends AbstractDateValueStream {
|
|||
public static final String name = FilterFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DateStreamFilterFunction(DateValueStream baseExpr, BooleanValue filterExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.filterExpr = filterExpr;
|
||||
|
@ -593,7 +593,7 @@ class DateStreamFilterFunction extends AbstractDateValueStream {
|
|||
baseExpr.streamLongs(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -613,14 +613,14 @@ class DateFilterFunction extends AbstractDateValue {
|
|||
public static final String name = FilterFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DateFilterFunction(DateValue baseExpr, BooleanValue filterExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.filterExpr = filterExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -633,7 +633,7 @@ class DateFilterFunction extends AbstractDateValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -653,7 +653,7 @@ class StringStreamFilterFunction extends AbstractStringValueStream {
|
|||
public static final String name = FilterFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public StringStreamFilterFunction(StringValueStream baseExpr, BooleanValue filterExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.filterExpr = filterExpr;
|
||||
|
@ -667,7 +667,7 @@ class StringStreamFilterFunction extends AbstractStringValueStream {
|
|||
baseExpr.streamStrings(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -687,14 +687,14 @@ class StringFilterFunction extends AbstractStringValue {
|
|||
public static final String name = FilterFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public StringFilterFunction(StringValue baseExpr, BooleanValue filterExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.filterExpr = filterExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,filterExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,filterExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -707,7 +707,7 @@ class StringFilterFunction extends AbstractStringValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
|
|
@ -60,10 +60,10 @@ import org.apache.solr.common.SolrException;
|
|||
import org.apache.solr.common.SolrException.ErrorCode;
|
||||
|
||||
/**
|
||||
* An if-else mapping function.
|
||||
* An if-else mapping function.
|
||||
* <p>
|
||||
* Three arguments are required. The first, the conditional parameter, must be a {@link BooleanValue} and
|
||||
* the later two, the if and else parameters, can be any type of {@link AnalyticsValueStream}.
|
||||
* the later two, the if and else parameters, can be any type of {@link AnalyticsValueStream}.
|
||||
* For each document, if the conditional value is true then the if-value is used otherwise the else-value is used.
|
||||
* <p>
|
||||
* The resulting Value or ValueStream will be typed with the closest super-type of the two non-conditional parameters.
|
||||
|
@ -83,10 +83,10 @@ public class IfFunction extends AbstractAnalyticsValueStream {
|
|||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 3 paramaters, " + params.length + " found.");
|
||||
}
|
||||
if (!(params[0] instanceof BooleanValue)) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires single-valued numeric parameters. " +
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires single-valued numeric parameters. " +
|
||||
"Incorrect parameter: "+params[0].getExpressionStr());
|
||||
}
|
||||
|
||||
|
||||
BooleanValue castedIf = (BooleanValue) params[0];
|
||||
AnalyticsValueStream thenExpr = params[1];
|
||||
AnalyticsValueStream elseExpr = params[2];
|
||||
|
@ -138,7 +138,7 @@ public class IfFunction extends AbstractAnalyticsValueStream {
|
|||
}
|
||||
return new IfFunction(castedIf,thenExpr,elseExpr);
|
||||
});
|
||||
|
||||
|
||||
public IfFunction(BooleanValue ifExpr, AnalyticsValueStream thenExpr, AnalyticsValueStream elseExpr) throws SolrException {
|
||||
this.ifExpr = ifExpr;
|
||||
this.thenExpr = thenExpr;
|
||||
|
@ -180,7 +180,7 @@ class ValueIfFunction extends AbstractAnalyticsValue {
|
|||
public static final String name = IfFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public ValueIfFunction(BooleanValue ifExpr, AnalyticsValue thenExpr, AnalyticsValue elseExpr) throws SolrException {
|
||||
this.ifExpr = ifExpr;
|
||||
this.thenExpr = thenExpr;
|
||||
|
@ -233,7 +233,7 @@ class BooleanStreamIfFunction extends AbstractBooleanValueStream {
|
|||
public static final String name = IfFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public BooleanStreamIfFunction(BooleanValue ifExpr, BooleanValueStream thenExpr, BooleanValueStream elseExpr) throws SolrException {
|
||||
this.ifExpr = ifExpr;
|
||||
this.thenExpr = thenExpr;
|
||||
|
@ -275,7 +275,7 @@ class BooleanIfFunction extends AbstractBooleanValue {
|
|||
public static final String name = IfFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public BooleanIfFunction(BooleanValue ifExpr, BooleanValue thenExpr, BooleanValue elseExpr) throws SolrException {
|
||||
this.ifExpr = ifExpr;
|
||||
this.thenExpr = thenExpr;
|
||||
|
@ -328,7 +328,7 @@ class IntStreamIfFunction extends AbstractIntValueStream {
|
|||
public static final String name = IfFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public IntStreamIfFunction(BooleanValue ifExpr, IntValueStream thenExpr, IntValueStream elseExpr) throws SolrException {
|
||||
this.ifExpr = ifExpr;
|
||||
this.thenExpr = thenExpr;
|
||||
|
@ -370,7 +370,7 @@ class IntIfFunction extends AbstractIntValue {
|
|||
public static final String name = IfFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public IntIfFunction(BooleanValue ifExpr, IntValue thenExpr, IntValue elseExpr) throws SolrException {
|
||||
this.ifExpr = ifExpr;
|
||||
this.thenExpr = thenExpr;
|
||||
|
@ -423,7 +423,7 @@ class LongStreamIfFunction extends AbstractLongValueStream {
|
|||
public static final String name = IfFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public LongStreamIfFunction(BooleanValue ifExpr, LongValueStream thenExpr, LongValueStream elseExpr) throws SolrException {
|
||||
this.ifExpr = ifExpr;
|
||||
this.thenExpr = thenExpr;
|
||||
|
@ -465,7 +465,7 @@ class LongIfFunction extends AbstractLongValue {
|
|||
public static final String name = IfFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public LongIfFunction(BooleanValue ifExpr, LongValue thenExpr, LongValue elseExpr) throws SolrException {
|
||||
this.ifExpr = ifExpr;
|
||||
this.thenExpr = thenExpr;
|
||||
|
@ -518,7 +518,7 @@ class FloatStreamIfFunction extends AbstractFloatValueStream {
|
|||
public static final String name = IfFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public FloatStreamIfFunction(BooleanValue ifExpr, FloatValueStream thenExpr, FloatValueStream elseExpr) throws SolrException {
|
||||
this.ifExpr = ifExpr;
|
||||
this.thenExpr = thenExpr;
|
||||
|
@ -560,7 +560,7 @@ class FloatIfFunction extends AbstractFloatValue {
|
|||
public static final String name = IfFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public FloatIfFunction(BooleanValue ifExpr, FloatValue thenExpr, FloatValue elseExpr) throws SolrException {
|
||||
this.ifExpr = ifExpr;
|
||||
this.thenExpr = thenExpr;
|
||||
|
@ -613,7 +613,7 @@ class DoubleStreamIfFunction extends AbstractDoubleValueStream {
|
|||
public static final String name = IfFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DoubleStreamIfFunction(BooleanValue ifExpr, DoubleValueStream thenExpr, DoubleValueStream elseExpr) throws SolrException {
|
||||
this.ifExpr = ifExpr;
|
||||
this.thenExpr = thenExpr;
|
||||
|
@ -655,7 +655,7 @@ class DoubleIfFunction extends AbstractDoubleValue {
|
|||
public static final String name = IfFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DoubleIfFunction(BooleanValue ifExpr, DoubleValue thenExpr, DoubleValue elseExpr) throws SolrException {
|
||||
this.ifExpr = ifExpr;
|
||||
this.thenExpr = thenExpr;
|
||||
|
@ -708,7 +708,7 @@ class DateStreamIfFunction extends AbstractDateValueStream {
|
|||
public static final String name = IfFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DateStreamIfFunction(BooleanValue ifExpr, DateValueStream thenExpr, DateValueStream elseExpr) throws SolrException {
|
||||
this.ifExpr = ifExpr;
|
||||
this.thenExpr = thenExpr;
|
||||
|
@ -750,7 +750,7 @@ class DateIfFunction extends AbstractDateValue {
|
|||
public static final String name = IfFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DateIfFunction(BooleanValue ifExpr, DateValue thenExpr, DateValue elseExpr) throws SolrException {
|
||||
this.ifExpr = ifExpr;
|
||||
this.thenExpr = thenExpr;
|
||||
|
@ -803,7 +803,7 @@ class StringStreamIfFunction extends AbstractStringValueStream {
|
|||
public static final String name = IfFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public StringStreamIfFunction(BooleanValue ifExpr, StringValueStream thenExpr, StringValueStream elseExpr) throws SolrException {
|
||||
this.ifExpr = ifExpr;
|
||||
this.thenExpr = thenExpr;
|
||||
|
@ -824,7 +824,7 @@ class StringStreamIfFunction extends AbstractStringValueStream {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -845,7 +845,7 @@ class StringIfFunction extends AbstractStringValue {
|
|||
public static final String name = IfFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public StringIfFunction(BooleanValue ifExpr, StringValue thenExpr, StringValue elseExpr) throws SolrException {
|
||||
this.ifExpr = ifExpr;
|
||||
this.thenExpr = thenExpr;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -30,8 +30,8 @@ import org.apache.solr.common.SolrException.ErrorCode;
|
|||
* <li>If one numeric Value or ValueStream is passed in, a {@link DoubleValue} or {@link DoubleValueStream}
|
||||
* representing the natural logarithm is returned.
|
||||
* <li>If two numeric Values are passed in, a {@link DoubleValue} representing the logarithm of the first with the second as the base is returned.
|
||||
* <li>If a numeric ValueStream and a numeric Value are passed in, a {@link DoubleValueStream} representing the logarithm of
|
||||
* the Value with each of the values of the ValueStream for a document as the base is returned.
|
||||
* <li>If a numeric ValueStream and a numeric Value are passed in, a {@link DoubleValueStream} representing the logarithm of
|
||||
* the Value with each of the values of the ValueStream for a document as the base is returned.
|
||||
* (Or the other way, since the Value and ValueStream can be used in either order)
|
||||
* </ul>
|
||||
*/
|
||||
|
|
|
@ -31,24 +31,24 @@ import org.apache.solr.common.SolrException.ErrorCode;
|
|||
* <ul>
|
||||
* <li>If a single {@link BooleanValueStream} is passed in, a {@link BooleanValue} representing the logical operation
|
||||
* on all of the values for each document is returned.
|
||||
* <li>If a {@link BooleanValueStream} and a {@link BooleanValue} are passed in, a {@link BooleanValue} representing the logical operation on
|
||||
* <li>If a {@link BooleanValueStream} and a {@link BooleanValue} are passed in, a {@link BooleanValue} representing the logical operation on
|
||||
* the {@link BooleanValue} and each of the values of the {@link BooleanValueStream} for a document is returned.
|
||||
* (Or the other way, since the Value and ValueStream can be used in either order)
|
||||
* <li>If multiple {@link BooleanValue}s are passed in, a {@link BooleanValue} representing the logical operation on all values is returned.
|
||||
* </ul>
|
||||
*/
|
||||
public class LogicFunction {
|
||||
|
||||
|
||||
private static BooleanValueStream createBitwiseFunction(String name, TwoBoolInBoolOutLambda comp, AnalyticsValueStream... params) {
|
||||
if (params.length == 0) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires parameters.");
|
||||
}
|
||||
}
|
||||
else if (params.length == 1) {
|
||||
if (params[0] instanceof BooleanValueStream) {
|
||||
return LambdaFunction.createBooleanLambdaFunction(name, comp, (BooleanValueStream)params[0]);
|
||||
}
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires boolean parameters. Incorrect param: "+params[0].getExpressionStr());
|
||||
}
|
||||
}
|
||||
else if (params.length == 2) {
|
||||
AnalyticsValueStream param1 = params[0];
|
||||
AnalyticsValueStream param2 = params[1];
|
||||
|
@ -67,7 +67,7 @@ public class LogicFunction {
|
|||
}
|
||||
return LambdaFunction.createBooleanLambdaFunction(name, comp, castedParams);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* A mapping function for the logical operation AND.
|
||||
*/
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.apache.solr.analytics.value.DoubleValueStream;
|
|||
* Uses:
|
||||
* <ul>
|
||||
* <li>If a single numeric ValueStream is passed in, a {@link DoubleValue} representing the multiplication of the values for each document is returned.
|
||||
* <li>If a numeric ValueStream and a numeric Value are passed in, a {@link DoubleValueStream} representing the multiplication of
|
||||
* <li>If a numeric ValueStream and a numeric Value are passed in, a {@link DoubleValueStream} representing the multiplication of
|
||||
* the Value and each of the values of the ValueStream for a document is returned.
|
||||
* (Or the other way, since the Value and ValueStream can be used in either order)
|
||||
* <li>If multiple numeric Values are passed in, a {@link DoubleValue} representing the multiplication of all values is returned.
|
||||
|
@ -40,13 +40,13 @@ public class MultFunction {
|
|||
public static final CreatorFunction creatorFunction = (params -> {
|
||||
if (params.length == 0) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires parameters.");
|
||||
}
|
||||
}
|
||||
else if (params.length == 1) {
|
||||
if (params[0] instanceof DoubleValueStream) {
|
||||
return LambdaFunction.createDoubleLambdaFunction(name, (a,b) -> a*b, (DoubleValueStream)params[0]);
|
||||
}
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires numeric parameters. Incorrect param: "+params[0].getExpressionStr());
|
||||
}
|
||||
}
|
||||
else if (params.length == 2) {
|
||||
AnalyticsValueStream param1 = params[0];
|
||||
AnalyticsValueStream param2 = params[1];
|
||||
|
|
|
@ -29,8 +29,8 @@ import org.apache.solr.common.SolrException.ErrorCode;
|
|||
* Uses:
|
||||
* <ul>
|
||||
* <li>If two numeric Values are passed in, a {@link DoubleValue} representing the first taken to the power of the second is returned.
|
||||
* <li>If a numeric ValueStream and a numeric Value are passed in, a {@link DoubleValueStream} representing the power of
|
||||
* the Value to each of the values of the ValueStream for a document is returned.
|
||||
* <li>If a numeric ValueStream and a numeric Value are passed in, a {@link DoubleValueStream} representing the power of
|
||||
* the Value to each of the values of the ValueStream for a document is returned.
|
||||
* (Or the other way, since the Value and ValueStream can be used in either order)
|
||||
* </ul>
|
||||
*/
|
||||
|
|
|
@ -72,7 +72,7 @@ import org.apache.solr.common.SolrException.ErrorCode;
|
|||
*/
|
||||
public class RemoveFunction {
|
||||
public static final String name = "remove";
|
||||
|
||||
|
||||
public static final CreatorFunction creatorFunction = (params -> {
|
||||
if (params.length != 2) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 2 paramaters, " + params.length + " found.");
|
||||
|
@ -138,7 +138,7 @@ class StreamRemoveFunction extends AbstractAnalyticsValueStream {
|
|||
public static final String name = RemoveFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public StreamRemoveFunction(AnalyticsValueStream baseExpr, AnalyticsValue removeExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.removeExpr = removeExpr;
|
||||
|
@ -157,7 +157,7 @@ class StreamRemoveFunction extends AbstractAnalyticsValueStream {
|
|||
baseExpr.streamObjects(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -179,14 +179,14 @@ class ValueRemoveFunction extends AbstractAnalyticsValue {
|
|||
public static final String name = RemoveFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public ValueRemoveFunction(AnalyticsValue baseExpr, AnalyticsValue removeExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.removeExpr = removeExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,removeExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,removeExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -198,12 +198,12 @@ class ValueRemoveFunction extends AbstractAnalyticsValue {
|
|||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -225,7 +225,7 @@ class BooleanStreamRemoveFunction extends AbstractBooleanValueStream {
|
|||
public static final String name = RemoveFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public BooleanStreamRemoveFunction(BooleanValueStream baseExpr, BooleanValue removeExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.removeExpr = removeExpr;
|
||||
|
@ -244,7 +244,7 @@ class BooleanStreamRemoveFunction extends AbstractBooleanValueStream {
|
|||
baseExpr.streamBooleans(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -266,16 +266,16 @@ class BooleanRemoveFunction extends AbstractBooleanValue {
|
|||
public static final String name = RemoveFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public BooleanRemoveFunction(BooleanValue baseExpr, BooleanValue removeExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.removeExpr = removeExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,removeExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,removeExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean getBoolean() {
|
||||
boolean value = baseExpr.getBoolean();
|
||||
|
@ -289,7 +289,7 @@ class BooleanRemoveFunction extends AbstractBooleanValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -309,7 +309,7 @@ class IntStreamRemoveFunction extends AbstractIntValueStream {
|
|||
public static final String name = RemoveFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public IntStreamRemoveFunction(IntValueStream baseExpr, IntValue removeExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.removeExpr = removeExpr;
|
||||
|
@ -328,7 +328,7 @@ class IntStreamRemoveFunction extends AbstractIntValueStream {
|
|||
baseExpr.streamInts(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -348,16 +348,16 @@ class IntRemoveFunction extends AbstractIntValue {
|
|||
public static final String name = RemoveFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public IntRemoveFunction(IntValue baseExpr, IntValue removeExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.removeExpr = removeExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,removeExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,removeExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
|
||||
@Override
|
||||
public int getInt() {
|
||||
int value = baseExpr.getInt();
|
||||
|
@ -371,7 +371,7 @@ class IntRemoveFunction extends AbstractIntValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -391,7 +391,7 @@ class LongStreamRemoveFunction extends AbstractLongValueStream {
|
|||
public static final String name = RemoveFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public LongStreamRemoveFunction(LongValueStream baseExpr, LongValue removeExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.removeExpr = removeExpr;
|
||||
|
@ -410,7 +410,7 @@ class LongStreamRemoveFunction extends AbstractLongValueStream {
|
|||
baseExpr.streamLongs(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -430,16 +430,16 @@ class LongRemoveFunction extends AbstractLongValue {
|
|||
public static final String name = RemoveFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public LongRemoveFunction(LongValue baseExpr, LongValue removeExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.removeExpr = removeExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,removeExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,removeExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
|
||||
@Override
|
||||
public long getLong() {
|
||||
long value = baseExpr.getLong();
|
||||
|
@ -453,7 +453,7 @@ class LongRemoveFunction extends AbstractLongValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -473,7 +473,7 @@ class FloatStreamRemoveFunction extends AbstractFloatValueStream {
|
|||
public static final String name = RemoveFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public FloatStreamRemoveFunction(FloatValueStream baseExpr, FloatValue removeExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.removeExpr = removeExpr;
|
||||
|
@ -492,7 +492,7 @@ class FloatStreamRemoveFunction extends AbstractFloatValueStream {
|
|||
baseExpr.streamFloats(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -512,16 +512,16 @@ class FloatRemoveFunction extends AbstractFloatValue {
|
|||
public static final String name = RemoveFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public FloatRemoveFunction(FloatValue baseExpr, FloatValue removeExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.removeExpr = removeExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,removeExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,removeExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
|
||||
@Override
|
||||
public float getFloat() {
|
||||
float value = baseExpr.getFloat();
|
||||
|
@ -535,7 +535,7 @@ class FloatRemoveFunction extends AbstractFloatValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -555,7 +555,7 @@ class DoubleStreamRemoveFunction extends AbstractDoubleValueStream {
|
|||
public static final String name = RemoveFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DoubleStreamRemoveFunction(DoubleValueStream baseExpr, DoubleValue removeExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.removeExpr = removeExpr;
|
||||
|
@ -574,7 +574,7 @@ class DoubleStreamRemoveFunction extends AbstractDoubleValueStream {
|
|||
baseExpr.streamDoubles(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -594,16 +594,16 @@ class DoubleRemoveFunction extends AbstractDoubleValue {
|
|||
public static final String name = RemoveFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DoubleRemoveFunction(DoubleValue baseExpr, DoubleValue removeExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.removeExpr = removeExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,removeExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,removeExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
|
||||
@Override
|
||||
public double getDouble() {
|
||||
double value = baseExpr.getDouble();
|
||||
|
@ -617,7 +617,7 @@ class DoubleRemoveFunction extends AbstractDoubleValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -637,7 +637,7 @@ class DateStreamRemoveFunction extends AbstractDateValueStream {
|
|||
public static final String name = RemoveFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DateStreamRemoveFunction(DateValueStream baseExpr, DateValue removeExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.removeExpr = removeExpr;
|
||||
|
@ -656,7 +656,7 @@ class DateStreamRemoveFunction extends AbstractDateValueStream {
|
|||
baseExpr.streamLongs(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -676,14 +676,14 @@ class DateRemoveFunction extends AbstractDateValue {
|
|||
public static final String name = RemoveFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DateRemoveFunction(DateValue baseExpr, DateValue removeExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.removeExpr = removeExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,removeExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,removeExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -699,7 +699,7 @@ class DateRemoveFunction extends AbstractDateValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -719,7 +719,7 @@ class StringStreamRemoveFunction extends AbstractStringValueStream {
|
|||
public static final String name = RemoveFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public StringStreamRemoveFunction(StringValueStream baseExpr, StringValue removeExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.removeExpr = removeExpr;
|
||||
|
@ -738,7 +738,7 @@ class StringStreamRemoveFunction extends AbstractStringValueStream {
|
|||
baseExpr.streamStrings(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -758,14 +758,14 @@ class StringRemoveFunction extends AbstractStringValue {
|
|||
public static final String name = RemoveFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public StringRemoveFunction(StringValue baseExpr, StringValue removeExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.removeExpr = removeExpr;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,removeExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,removeExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -781,7 +781,7 @@ class StringRemoveFunction extends AbstractStringValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
|
|
@ -133,8 +133,8 @@ public class ReplaceFunction {
|
|||
if (baseExpr instanceof AnalyticsValue) {
|
||||
return new ValueReplaceFunction((AnalyticsValue)baseExpr,(AnalyticsValue)compExpr,(AnalyticsValue)fillExpr);
|
||||
}
|
||||
return new StreamReplaceFunction(baseExpr,compExpr,fillExpr);
|
||||
|
||||
return new StreamReplaceFunction(baseExpr,compExpr,fillExpr);
|
||||
|
||||
});
|
||||
}
|
||||
class StreamReplaceFunction extends AbstractAnalyticsValueStream {
|
||||
|
@ -144,7 +144,7 @@ class StreamReplaceFunction extends AbstractAnalyticsValueStream {
|
|||
public static final String name = ReplaceFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public StreamReplaceFunction(AnalyticsValueStream baseExpr, AnalyticsValue compExpr, AnalyticsValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.compExpr = compExpr;
|
||||
|
@ -173,7 +173,7 @@ class StreamReplaceFunction extends AbstractAnalyticsValueStream {
|
|||
baseExpr.streamObjects(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -194,7 +194,7 @@ class ValueReplaceFunction extends AbstractAnalyticsValue {
|
|||
public static final String name = ReplaceFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public ValueReplaceFunction(AnalyticsValue baseExpr, AnalyticsValue compExpr, AnalyticsValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.compExpr = compExpr;
|
||||
|
@ -202,7 +202,7 @@ class ValueReplaceFunction extends AbstractAnalyticsValue {
|
|||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr,fillExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,compExpr,fillExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -220,7 +220,7 @@ class ValueReplaceFunction extends AbstractAnalyticsValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -241,7 +241,7 @@ class BooleanStreamReplaceFunction extends AbstractBooleanValueStream {
|
|||
public static final String name = ReplaceFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public BooleanStreamReplaceFunction(BooleanValueStream baseExpr, BooleanValue compExpr, BooleanValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.compExpr = compExpr;
|
||||
|
@ -270,7 +270,7 @@ class BooleanStreamReplaceFunction extends AbstractBooleanValueStream {
|
|||
baseExpr.streamBooleans(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -291,7 +291,7 @@ class BooleanReplaceFunction extends AbstractBooleanValue {
|
|||
public static final String name = ReplaceFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public BooleanReplaceFunction(BooleanValue baseExpr, BooleanValue compExpr, BooleanValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.compExpr = compExpr;
|
||||
|
@ -299,7 +299,7 @@ class BooleanReplaceFunction extends AbstractBooleanValue {
|
|||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr,fillExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,compExpr,fillExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -317,7 +317,7 @@ class BooleanReplaceFunction extends AbstractBooleanValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -338,7 +338,7 @@ class IntStreamReplaceFunction extends AbstractIntValueStream {
|
|||
public static final String name = ReplaceFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public IntStreamReplaceFunction(IntValueStream baseExpr, IntValue compExpr, IntValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.compExpr = compExpr;
|
||||
|
@ -367,7 +367,7 @@ class IntStreamReplaceFunction extends AbstractIntValueStream {
|
|||
baseExpr.streamInts(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -388,7 +388,7 @@ class IntReplaceFunction extends AbstractIntValue {
|
|||
public static final String name = ReplaceFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public IntReplaceFunction(IntValue baseExpr, IntValue compExpr, IntValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.compExpr = compExpr;
|
||||
|
@ -396,7 +396,7 @@ class IntReplaceFunction extends AbstractIntValue {
|
|||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr,fillExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,compExpr,fillExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -414,7 +414,7 @@ class IntReplaceFunction extends AbstractIntValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -435,7 +435,7 @@ class LongStreamReplaceFunction extends AbstractLongValueStream {
|
|||
public static final String name = ReplaceFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public LongStreamReplaceFunction(LongValueStream baseExpr, LongValue compExpr, LongValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.compExpr = compExpr;
|
||||
|
@ -464,7 +464,7 @@ class LongStreamReplaceFunction extends AbstractLongValueStream {
|
|||
baseExpr.streamLongs(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -485,7 +485,7 @@ class LongReplaceFunction extends AbstractLongValue {
|
|||
public static final String name = ReplaceFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public LongReplaceFunction(LongValue baseExpr, LongValue compExpr, LongValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.compExpr = compExpr;
|
||||
|
@ -493,7 +493,7 @@ class LongReplaceFunction extends AbstractLongValue {
|
|||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr,fillExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,compExpr,fillExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -511,7 +511,7 @@ class LongReplaceFunction extends AbstractLongValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -532,7 +532,7 @@ class FloatStreamReplaceFunction extends AbstractFloatValueStream {
|
|||
public static final String name = ReplaceFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public FloatStreamReplaceFunction(FloatValueStream baseExpr, FloatValue compExpr, FloatValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.compExpr = compExpr;
|
||||
|
@ -561,7 +561,7 @@ class FloatStreamReplaceFunction extends AbstractFloatValueStream {
|
|||
baseExpr.streamFloats(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -582,7 +582,7 @@ class FloatReplaceFunction extends AbstractFloatValue {
|
|||
public static final String name = ReplaceFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public FloatReplaceFunction(FloatValue baseExpr, FloatValue compExpr, FloatValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.compExpr = compExpr;
|
||||
|
@ -590,7 +590,7 @@ class FloatReplaceFunction extends AbstractFloatValue {
|
|||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr,fillExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,compExpr,fillExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -608,7 +608,7 @@ class FloatReplaceFunction extends AbstractFloatValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -629,7 +629,7 @@ class DoubleStreamReplaceFunction extends AbstractDoubleValueStream {
|
|||
public static final String name = ReplaceFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DoubleStreamReplaceFunction(DoubleValueStream baseExpr, DoubleValue compExpr, DoubleValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.compExpr = compExpr;
|
||||
|
@ -658,7 +658,7 @@ class DoubleStreamReplaceFunction extends AbstractDoubleValueStream {
|
|||
baseExpr.streamDoubles(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -679,7 +679,7 @@ class DoubleReplaceFunction extends AbstractDoubleValue {
|
|||
public static final String name = ReplaceFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DoubleReplaceFunction(DoubleValue baseExpr, DoubleValue compExpr, DoubleValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.compExpr = compExpr;
|
||||
|
@ -687,7 +687,7 @@ class DoubleReplaceFunction extends AbstractDoubleValue {
|
|||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr,fillExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,compExpr,fillExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -705,7 +705,7 @@ class DoubleReplaceFunction extends AbstractDoubleValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -726,7 +726,7 @@ class DateStreamReplaceFunction extends AbstractDateValueStream {
|
|||
public static final String name = ReplaceFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DateStreamReplaceFunction(DateValueStream baseExpr, DateValue compExpr, DateValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.compExpr = compExpr;
|
||||
|
@ -755,7 +755,7 @@ class DateStreamReplaceFunction extends AbstractDateValueStream {
|
|||
baseExpr.streamLongs(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -776,7 +776,7 @@ class DateReplaceFunction extends AbstractDateValue {
|
|||
public static final String name = ReplaceFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public DateReplaceFunction(DateValue baseExpr, DateValue compExpr, DateValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.compExpr = compExpr;
|
||||
|
@ -784,7 +784,7 @@ class DateReplaceFunction extends AbstractDateValue {
|
|||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr,fillExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,compExpr,fillExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -802,7 +802,7 @@ class DateReplaceFunction extends AbstractDateValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -823,7 +823,7 @@ class StringStreamReplaceFunction extends AbstractStringValueStream {
|
|||
public static final String name = ReplaceFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public StringStreamReplaceFunction(StringValueStream baseExpr, StringValue compExpr, StringValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.compExpr = compExpr;
|
||||
|
@ -852,7 +852,7 @@ class StringStreamReplaceFunction extends AbstractStringValueStream {
|
|||
baseExpr.streamStrings(cons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -873,7 +873,7 @@ class StringReplaceFunction extends AbstractStringValue {
|
|||
public static final String name = ReplaceFunction.name;
|
||||
private final String exprStr;
|
||||
private final ExpressionType funcType;
|
||||
|
||||
|
||||
public StringReplaceFunction(StringValue baseExpr, StringValue compExpr, StringValue fillExpr) throws SolrException {
|
||||
this.baseExpr = baseExpr;
|
||||
this.compExpr = compExpr;
|
||||
|
@ -881,7 +881,7 @@ class StringReplaceFunction extends AbstractStringValue {
|
|||
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,compExpr,fillExpr);
|
||||
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,compExpr,fillExpr);
|
||||
}
|
||||
|
||||
|
||||
boolean exists = false;
|
||||
|
||||
@Override
|
||||
|
@ -899,7 +899,7 @@ class StringReplaceFunction extends AbstractStringValue {
|
|||
public boolean exists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.apache.solr.common.SolrException.ErrorCode;
|
|||
* <ul>
|
||||
* <li>If two numeric Values are passed in, a {@link DoubleValue} representing the first subtracted by the second is returned.
|
||||
* <li>If a numeric ValueStream and a numeric Value are passed in, a {@link DoubleValueStream} representing the Value subtracted by
|
||||
* each of the values of the ValueStream for a document is returned.
|
||||
* each of the values of the ValueStream for a document is returned.
|
||||
* (Or the other way, since the Value and ValueStream can be used in either order)
|
||||
* </ul>
|
||||
*/
|
||||
|
|
|
@ -157,7 +157,7 @@ public class TopFunction {
|
|||
return LambdaFunction.createStringLambdaFunction(name, (a,b) -> (a.compareTo(b)>0)? a:b, castedParams, false);
|
||||
}
|
||||
}
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a comparable parameter. " +
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a comparable parameter. " +
|
||||
"Incorrect parameter: "+params[0].getExpressionStr());
|
||||
});
|
||||
}
|
|
@ -14,8 +14,8 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Mapping functions to use for analytics expressions.
|
||||
*/
|
||||
package org.apache.solr.analytics.function.mapping;
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Functions to use for analytics expressions.
|
||||
*/
|
||||
package org.apache.solr.analytics.function;
|
||||
|
|
|
@ -46,12 +46,12 @@ public class CountFunction extends AbstractLongValue implements ReductionFunctio
|
|||
}
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function a max of 1 paramater, " + params.length + " given.");
|
||||
});
|
||||
|
||||
|
||||
public CountFunction() {
|
||||
this.collector = new TotalCountCollector();
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name);
|
||||
}
|
||||
|
||||
|
||||
public CountFunction(AnalyticsValueStream param) {
|
||||
this.collector = new ExpressionCountCollector(param);
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
|
|
@ -46,12 +46,12 @@ public class DocCountFunction extends AbstractLongValue implements ReductionFunc
|
|||
}
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function accepts at most 1 paramater, " + params.length + " given.");
|
||||
});
|
||||
|
||||
|
||||
public DocCountFunction() {
|
||||
this.collector = new TotalCountCollector();
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name);
|
||||
}
|
||||
|
||||
|
||||
public DocCountFunction(AnalyticsValueStream param) {
|
||||
this.collector = new ExpressionCountCollector(param);
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
|
|
@ -70,7 +70,7 @@ public class MaxFunction {
|
|||
if (param instanceof StringValueStream) {
|
||||
return new StringMaxFunction((StringValueStream)param);
|
||||
}
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a comparable parameter. " +
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a comparable parameter. " +
|
||||
"Incorrect parameter: "+params[0].getExpressionStr());
|
||||
});
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ class IntMaxFunction extends AbstractIntValue implements ReductionFunction {
|
|||
private IntMaxCollector collector;
|
||||
public static final String name = MaxFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public IntMaxFunction(IntValueStream param) {
|
||||
this.collector = new IntMaxCollector(param);
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
@ -115,7 +115,7 @@ class LongMaxFunction extends AbstractLongValue implements ReductionFunction {
|
|||
private LongMaxCollector collector;
|
||||
public static final String name = MaxFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public LongMaxFunction(LongValueStream param) {
|
||||
this.collector = new LongMaxCollector(param);
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
@ -152,7 +152,7 @@ class FloatMaxFunction extends AbstractFloatValue implements ReductionFunction {
|
|||
private FloatMaxCollector collector;
|
||||
public static final String name = MaxFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public FloatMaxFunction(FloatValueStream param) {
|
||||
this.collector = new FloatMaxCollector(param);
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
@ -189,7 +189,7 @@ class DoubleMaxFunction extends AbstractDoubleValue implements ReductionFunction
|
|||
private DoubleMaxCollector collector;
|
||||
public static final String name = MaxFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public DoubleMaxFunction(DoubleValueStream param) {
|
||||
this.collector = new DoubleMaxCollector(param);
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
@ -226,7 +226,7 @@ class DateMaxFunction extends AbstractDateValue implements ReductionFunction {
|
|||
private LongMaxCollector collector;
|
||||
public static final String name = MaxFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public DateMaxFunction(LongValueStream param) {
|
||||
this.collector = new LongMaxCollector(param);
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
@ -263,7 +263,7 @@ class StringMaxFunction extends AbstractStringValue implements ReductionFunction
|
|||
private StringMaxCollector collector;
|
||||
public static final String name = MaxFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public StringMaxFunction(StringValueStream param) {
|
||||
this.collector = new StringMaxCollector(param);
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
|
|
@ -49,12 +49,12 @@ public class MeanFunction extends AbstractDoubleValue implements ReductionFuncti
|
|||
casted = (DoubleValueStream) params[0];
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires numeric parameter. " +
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires numeric parameter. " +
|
||||
"Incorrect parameter: "+params[0].getExpressionStr());
|
||||
}
|
||||
return new MeanFunction(casted);
|
||||
});
|
||||
|
||||
|
||||
public MeanFunction(DoubleValueStream param) {
|
||||
this.sumCollector = new SumCollector(param);
|
||||
this.countCollector = new ExpressionCountCollector(param);
|
||||
|
|
|
@ -65,14 +65,14 @@ abstract class NumericMedianFunction<T extends Comparable<T>> extends AbstractDo
|
|||
protected SortedListCollector<T> collector;
|
||||
public static final String name = MedianFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public NumericMedianFunction(DoubleValueStream param, SortedListCollector<T> collector) {
|
||||
this.collector = collector;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
}
|
||||
|
||||
protected abstract double collectOrd(int ord);
|
||||
|
||||
|
||||
@Override
|
||||
public double getDouble() {
|
||||
int size = collector.size();
|
||||
|
@ -155,7 +155,7 @@ class DateMedianFunction extends AbstractDateValue implements ReductionFunction
|
|||
private SortedLongListCollector collector;
|
||||
public static final String name = MedianFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public DateMedianFunction(DateValueStream param) {
|
||||
this.collector = new SortedLongListCollector(param);
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
|
|
@ -70,7 +70,7 @@ public class MinFunction {
|
|||
if (param instanceof StringValueStream) {
|
||||
return new StringMinFunction((StringValueStream)param);
|
||||
}
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a comparable parameter. " +
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a comparable parameter. " +
|
||||
"Incorrect parameter: "+params[0].getExpressionStr());
|
||||
});
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ class IntMinFunction extends AbstractIntValue implements ReductionFunction {
|
|||
private IntMinCollector collector;
|
||||
public static final String name = MinFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public IntMinFunction(IntValueStream param) {
|
||||
this.collector = new IntMinCollector(param);
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
@ -115,7 +115,7 @@ class LongMinFunction extends AbstractLongValue implements ReductionFunction {
|
|||
private LongMinCollector collector;
|
||||
public static final String name = MinFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public LongMinFunction(LongValueStream param) {
|
||||
this.collector = new LongMinCollector(param);
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
@ -152,7 +152,7 @@ class FloatMinFunction extends AbstractFloatValue implements ReductionFunction {
|
|||
private FloatMinCollector collector;
|
||||
public static final String name = MinFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public FloatMinFunction(FloatValueStream param) {
|
||||
this.collector = new FloatMinCollector(param);
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
@ -189,7 +189,7 @@ class DoubleMinFunction extends AbstractDoubleValue implements ReductionFunction
|
|||
private DoubleMinCollector collector;
|
||||
public static final String name = MinFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public DoubleMinFunction(DoubleValueStream param) {
|
||||
this.collector = new DoubleMinCollector(param);
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
@ -226,7 +226,7 @@ class DateMinFunction extends AbstractDateValue implements ReductionFunction {
|
|||
private LongMinCollector collector;
|
||||
public static final String name = MinFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public DateMinFunction(LongValueStream param) {
|
||||
this.collector = new LongMinCollector(param);
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
@ -263,7 +263,7 @@ class StringMinFunction extends AbstractStringValue implements ReductionFunction
|
|||
private StringMinCollector collector;
|
||||
public static final String name = MinFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public StringMinFunction(StringValueStream param) {
|
||||
this.collector = new StringMinCollector(param);
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
|
|
@ -40,7 +40,7 @@ public class MissingFunction extends AbstractLongValue implements ReductionFunct
|
|||
}
|
||||
return new MissingFunction(params[0]);
|
||||
});
|
||||
|
||||
|
||||
public MissingFunction(AnalyticsValueStream param) {
|
||||
this.collector = new ExpressionCountCollector(param);
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
|
|
@ -77,10 +77,10 @@ public class OrdinalFunction {
|
|||
return new DoubleOrdinalFunction((DoubleValueStream)param, ord);
|
||||
} else if (param instanceof StringValueStream) {
|
||||
return new StringOrdinalFunction((StringValueStream)param, ord);
|
||||
}
|
||||
}
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a comparable parameter.");
|
||||
});
|
||||
|
||||
|
||||
protected static String createOrdinalExpressionString(AnalyticsValueStream param, double ord) {
|
||||
return String.format(Locale.ROOT, "%s(%s,%s)",
|
||||
name,
|
||||
|
@ -93,7 +93,7 @@ class IntOrdinalFunction extends AbstractIntValue implements ReductionFunction {
|
|||
private int ordinal;
|
||||
public static final String name = OrdinalFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public IntOrdinalFunction(IntValueStream param, int ordinal) {
|
||||
this.collector = new SortedIntListCollector(param);
|
||||
this.ordinal = ordinal;
|
||||
|
@ -138,7 +138,7 @@ class LongOrdinalFunction extends AbstractLongValue implements ReductionFunction
|
|||
private int ordinal;
|
||||
public static final String name = OrdinalFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public LongOrdinalFunction(LongValueStream param, int ordinal) {
|
||||
this.collector = new SortedLongListCollector(param);
|
||||
this.ordinal = ordinal;
|
||||
|
@ -183,7 +183,7 @@ class FloatOrdinalFunction extends AbstractFloatValue implements ReductionFuncti
|
|||
private int ordinal;
|
||||
public static final String name = OrdinalFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public FloatOrdinalFunction(FloatValueStream param, int ordinal) {
|
||||
this.collector = new SortedFloatListCollector(param);
|
||||
this.ordinal = ordinal;
|
||||
|
@ -228,7 +228,7 @@ class DoubleOrdinalFunction extends AbstractDoubleValue implements ReductionFunc
|
|||
private int ordinal;
|
||||
public static final String name = OrdinalFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public DoubleOrdinalFunction(DoubleValueStream param, int ordinal) {
|
||||
this.collector = new SortedDoubleListCollector(param);
|
||||
this.ordinal = ordinal;
|
||||
|
@ -273,7 +273,7 @@ class DateOrdinalFunction extends AbstractDateValue implements ReductionFunction
|
|||
private int ordinal;
|
||||
public static final String name = OrdinalFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public DateOrdinalFunction(LongValueStream param, int ordinal) {
|
||||
this.collector = new SortedLongListCollector(param);
|
||||
this.ordinal = ordinal;
|
||||
|
@ -318,7 +318,7 @@ class StringOrdinalFunction extends AbstractStringValue implements ReductionFunc
|
|||
private int ordinal;
|
||||
public static final String name = OrdinalFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public StringOrdinalFunction(StringValueStream param, int ordinal) {
|
||||
this.collector = new SortedStringListCollector(param);
|
||||
this.ordinal = ordinal;
|
||||
|
|
|
@ -78,10 +78,10 @@ public class PercentileFunction {
|
|||
return new DoublePercentileFunction((DoubleValueStream)param, perc);
|
||||
} else if (param instanceof StringValueStream) {
|
||||
return new StringPercentileFunction((StringValueStream)param, perc);
|
||||
}
|
||||
}
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires a comparable parameter.");
|
||||
});
|
||||
|
||||
|
||||
protected static String createPercentileExpressionString(AnalyticsValueStream param, double perc) {
|
||||
return String.format(Locale.ROOT, "%s(%s,%s)",
|
||||
name,
|
||||
|
@ -94,7 +94,7 @@ class IntPercentileFunction extends AbstractIntValue implements ReductionFunctio
|
|||
private double percentile;
|
||||
public static final String name = PercentileFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public IntPercentileFunction(IntValueStream param, double percentile) {
|
||||
this.collector = new SortedIntListCollector(param);
|
||||
this.percentile = percentile;
|
||||
|
@ -135,7 +135,7 @@ class LongPercentileFunction extends AbstractLongValue implements ReductionFunct
|
|||
private double percentile;
|
||||
public static final String name = PercentileFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public LongPercentileFunction(LongValueStream param, double percentile) {
|
||||
this.collector = new SortedLongListCollector(param);
|
||||
this.percentile = percentile;
|
||||
|
@ -176,7 +176,7 @@ class FloatPercentileFunction extends AbstractFloatValue implements ReductionFun
|
|||
private double percentile;
|
||||
public static final String name = PercentileFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public FloatPercentileFunction(FloatValueStream param, double percentile) {
|
||||
this.collector = new SortedFloatListCollector(param);
|
||||
this.percentile = percentile;
|
||||
|
@ -217,7 +217,7 @@ class DoublePercentileFunction extends AbstractDoubleValue implements ReductionF
|
|||
private double percentile;
|
||||
public static final String name = PercentileFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public DoublePercentileFunction(DoubleValueStream param, double percentile) {
|
||||
this.collector = new SortedDoubleListCollector(param);
|
||||
this.percentile = percentile;
|
||||
|
@ -258,7 +258,7 @@ class DatePercentileFunction extends AbstractDateValue implements ReductionFunct
|
|||
private double percentile;
|
||||
public static final String name = PercentileFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public DatePercentileFunction(LongValueStream param, double percentile) {
|
||||
this.collector = new SortedLongListCollector(param);
|
||||
this.percentile = percentile;
|
||||
|
@ -299,7 +299,7 @@ class StringPercentileFunction extends AbstractStringValue implements ReductionF
|
|||
private double percentile;
|
||||
public static final String name = PercentileFunction.name;
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public StringPercentileFunction(StringValueStream param, double percentile) {
|
||||
this.collector = new SortedStringListCollector(param);
|
||||
this.percentile = percentile;
|
||||
|
|
|
@ -46,12 +46,12 @@ public class SumFunction extends AbstractDoubleValue implements ReductionFunctio
|
|||
casted = (DoubleValueStream) params[0];
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires numeric parameter. " +
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires numeric parameter. " +
|
||||
"Incorrect parameter: "+params[0].getExpressionStr());
|
||||
}
|
||||
return new SumFunction(casted);
|
||||
});
|
||||
|
||||
|
||||
public SumFunction(DoubleValueStream param) {
|
||||
this.collector = new SumCollector(param);
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
|
|
@ -65,7 +65,7 @@ public class UniqueFunction extends AbstractLongValue implements ReductionFuncti
|
|||
}
|
||||
return new UniqueFunction(param, collector);
|
||||
});
|
||||
|
||||
|
||||
public UniqueFunction(AnalyticsValueStream param, UniqueCollector<?> collector) {
|
||||
this.collector = collector;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.apache.solr.analytics.value.AnalyticsValueStream;
|
|||
public abstract class CountCollector extends ReductionDataCollector<CountCollector.CountData> {
|
||||
public static final String name = "count";
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public CountCollector(String exprStr) {
|
||||
this.exprStr = exprStr;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public abstract class CountCollector extends ReductionDataCollector<CountCollect
|
|||
|
||||
/**
|
||||
* The number of Solr Documents for which the given analytics expression exists.
|
||||
*
|
||||
*
|
||||
* @return the count
|
||||
*/
|
||||
public long count() {
|
||||
|
@ -43,7 +43,7 @@ public abstract class CountCollector extends ReductionDataCollector<CountCollect
|
|||
}
|
||||
/**
|
||||
* The number of Solr Documents used in this reduction.
|
||||
*
|
||||
*
|
||||
* @return the number of documents
|
||||
*/
|
||||
public long docCount() {
|
||||
|
@ -93,7 +93,7 @@ public abstract class CountCollector extends ReductionDataCollector<CountCollect
|
|||
public String getExpressionStr() {
|
||||
return exprStr;
|
||||
}
|
||||
|
||||
|
||||
public static class CountData extends ReductionData {
|
||||
long count;
|
||||
long missing;
|
||||
|
@ -102,24 +102,24 @@ public abstract class CountCollector extends ReductionDataCollector<CountCollect
|
|||
|
||||
/**
|
||||
* Represents a {@code count(expr)} expression. This collects 3 values:
|
||||
*
|
||||
*
|
||||
* docCount - The number of Solr Documents for which the wrapped expression exists.
|
||||
* count - The number of values which wrapped expression contains.
|
||||
* missing - The number of Solr Documents for which the wrapped expression does not exist.
|
||||
*/
|
||||
public static class ExpressionCountCollector extends CountCollector {
|
||||
private final AnalyticsValueStream param;
|
||||
|
||||
|
||||
public ExpressionCountCollector(AnalyticsValueStream param) {
|
||||
super(AnalyticsValueStream.createExpressionString(name, param));
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
|
||||
private long missing;
|
||||
|
||||
|
||||
/**
|
||||
* The number of Solr Documents for which the given analytics expression does not exist.
|
||||
*
|
||||
*
|
||||
* @return the number of missing values
|
||||
*/
|
||||
public long missing() {
|
||||
|
@ -137,7 +137,7 @@ public abstract class CountCollector extends ReductionDataCollector<CountCollect
|
|||
super.setData(data);
|
||||
missing = ((CountData)data).missing;
|
||||
}
|
||||
|
||||
|
||||
long tempCount;
|
||||
int tempMissing;
|
||||
int tempDocCount;
|
||||
|
@ -150,7 +150,7 @@ public abstract class CountCollector extends ReductionDataCollector<CountCollect
|
|||
tempMissing = tempCount == 0 ? 1 : 0;
|
||||
tempDocCount = tempCount > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void apply(CountData data) {
|
||||
data.count += tempCount;
|
||||
|
@ -168,16 +168,16 @@ public abstract class CountCollector extends ReductionDataCollector<CountCollect
|
|||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Represents a {@code count()} expression. This collects the number of Solr Documents used in a result set.
|
||||
*/
|
||||
public static class TotalCountCollector extends CountCollector {
|
||||
|
||||
|
||||
public TotalCountCollector() {
|
||||
super(AnalyticsValueStream.createExpressionString(name));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void apply(CountData data) {
|
||||
data.count += 1;
|
||||
|
|
|
@ -49,16 +49,16 @@ import org.apache.solr.analytics.value.StringValueStream;
|
|||
public abstract class MaxCollector<T extends ReductionData> extends ReductionDataCollector<T> {
|
||||
public static final String name = "max";
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
protected MaxCollector(AnalyticsValueStream param) {
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
}
|
||||
|
||||
|
||||
private boolean exists;
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if any of the values being reduce exist, and false if none of them do.
|
||||
*
|
||||
*
|
||||
* @return whether a max value exists
|
||||
*/
|
||||
public boolean exists() {
|
||||
|
@ -86,7 +86,7 @@ public abstract class MaxCollector<T extends ReductionData> extends ReductionDat
|
|||
|
||||
public static class IntMaxCollector extends MaxCollector<IntMaxCollector.MaxData> {
|
||||
private IntValueStream param;
|
||||
|
||||
|
||||
public IntMaxCollector(IntValueStream param) {
|
||||
super(param);
|
||||
this.param = param;
|
||||
|
@ -100,10 +100,10 @@ public abstract class MaxCollector<T extends ReductionData> extends ReductionDat
|
|||
}
|
||||
|
||||
int max;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the max value of the set data.
|
||||
*
|
||||
*
|
||||
* @return the max
|
||||
*/
|
||||
public int max() {
|
||||
|
@ -129,7 +129,7 @@ public abstract class MaxCollector<T extends ReductionData> extends ReductionDat
|
|||
data.exists = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer) {
|
||||
consumer.accept(new IntCheckedReservation(
|
||||
|
@ -155,17 +155,17 @@ public abstract class MaxCollector<T extends ReductionData> extends ReductionDat
|
|||
super.setData(data);
|
||||
max = ((MaxData)data).val;
|
||||
}
|
||||
|
||||
|
||||
public static class MaxData extends ReductionData {
|
||||
int val;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static class LongMaxCollector extends MaxCollector<LongMaxCollector.MaxData> {
|
||||
private LongValueStream param;
|
||||
|
||||
|
||||
public LongMaxCollector(LongValueStream param) {
|
||||
super(param);
|
||||
this.param = param;
|
||||
|
@ -179,10 +179,10 @@ public abstract class MaxCollector<T extends ReductionData> extends ReductionDat
|
|||
}
|
||||
|
||||
long max;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the max value of the set data.
|
||||
*
|
||||
*
|
||||
* @return the max
|
||||
*/
|
||||
public long max() {
|
||||
|
@ -208,7 +208,7 @@ public abstract class MaxCollector<T extends ReductionData> extends ReductionDat
|
|||
data.exists = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer) {
|
||||
consumer.accept(new LongCheckedReservation(
|
||||
|
@ -234,7 +234,7 @@ public abstract class MaxCollector<T extends ReductionData> extends ReductionDat
|
|||
super.setData(data);
|
||||
max = ((MaxData)data).val;
|
||||
}
|
||||
|
||||
|
||||
public static class MaxData extends ReductionData {
|
||||
long val;
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ public abstract class MaxCollector<T extends ReductionData> extends ReductionDat
|
|||
|
||||
public static class FloatMaxCollector extends MaxCollector<FloatMaxCollector.MaxData> {
|
||||
private FloatValueStream param;
|
||||
|
||||
|
||||
public FloatMaxCollector(FloatValueStream param) {
|
||||
super(param);
|
||||
this.param = param;
|
||||
|
@ -256,10 +256,10 @@ public abstract class MaxCollector<T extends ReductionData> extends ReductionDat
|
|||
}
|
||||
|
||||
float max;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the max value of the set data.
|
||||
*
|
||||
*
|
||||
* @return the max
|
||||
*/
|
||||
public float max() {
|
||||
|
@ -285,7 +285,7 @@ public abstract class MaxCollector<T extends ReductionData> extends ReductionDat
|
|||
data.exists = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer) {
|
||||
consumer.accept(new FloatCheckedReservation(
|
||||
|
@ -311,7 +311,7 @@ public abstract class MaxCollector<T extends ReductionData> extends ReductionDat
|
|||
super.setData(data);
|
||||
max = ((MaxData)data).val;
|
||||
}
|
||||
|
||||
|
||||
public static class MaxData extends ReductionData {
|
||||
float val;
|
||||
}
|
||||
|
@ -319,7 +319,7 @@ public abstract class MaxCollector<T extends ReductionData> extends ReductionDat
|
|||
|
||||
public static class DoubleMaxCollector extends MaxCollector<DoubleMaxCollector.MaxData> {
|
||||
private DoubleValueStream param;
|
||||
|
||||
|
||||
public DoubleMaxCollector(DoubleValueStream param) {
|
||||
super(param);
|
||||
this.param = param;
|
||||
|
@ -333,10 +333,10 @@ public abstract class MaxCollector<T extends ReductionData> extends ReductionDat
|
|||
}
|
||||
|
||||
double max;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the max value of the set data.
|
||||
*
|
||||
*
|
||||
* @return the max
|
||||
*/
|
||||
public double max() {
|
||||
|
@ -362,7 +362,7 @@ public abstract class MaxCollector<T extends ReductionData> extends ReductionDat
|
|||
data.exists = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer) {
|
||||
consumer.accept(new DoubleCheckedReservation(
|
||||
|
@ -388,17 +388,17 @@ public abstract class MaxCollector<T extends ReductionData> extends ReductionDat
|
|||
super.setData(data);
|
||||
max = ((MaxData)data).val;
|
||||
}
|
||||
|
||||
|
||||
public static class MaxData extends ReductionData {
|
||||
double val;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static class StringMaxCollector extends MaxCollector<StringMaxCollector.MaxData> {
|
||||
private StringValueStream param;
|
||||
|
||||
|
||||
public StringMaxCollector(StringValueStream param) {
|
||||
super(param);
|
||||
this.param = param;
|
||||
|
@ -412,10 +412,10 @@ public abstract class MaxCollector<T extends ReductionData> extends ReductionDat
|
|||
}
|
||||
|
||||
String max;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the max value of the set data.
|
||||
*
|
||||
*
|
||||
* @return the max
|
||||
*/
|
||||
public String max() {
|
||||
|
@ -441,7 +441,7 @@ public abstract class MaxCollector<T extends ReductionData> extends ReductionDat
|
|||
data.exists = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer) {
|
||||
consumer.accept(new StringCheckedReservation(
|
||||
|
@ -467,7 +467,7 @@ public abstract class MaxCollector<T extends ReductionData> extends ReductionDat
|
|||
super.setData(data);
|
||||
max = ((MaxData)data).val;
|
||||
}
|
||||
|
||||
|
||||
public static class MaxData extends ReductionData {
|
||||
String val;
|
||||
}
|
||||
|
|
|
@ -49,16 +49,16 @@ import org.apache.solr.analytics.value.StringValueStream;
|
|||
public abstract class MinCollector<T extends ReductionData> extends ReductionDataCollector<T> {
|
||||
public static final String name = "min";
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
protected MinCollector(AnalyticsValueStream param) {
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
}
|
||||
|
||||
|
||||
private boolean exists;
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if any of the values being reduce exist, and false if none of them do.
|
||||
*
|
||||
*
|
||||
* @return whether a min value exists
|
||||
*/
|
||||
public boolean exists() {
|
||||
|
@ -86,7 +86,7 @@ public abstract class MinCollector<T extends ReductionData> extends ReductionDat
|
|||
|
||||
public static class IntMinCollector extends MinCollector<IntMinCollector.MinData> {
|
||||
private IntValueStream param;
|
||||
|
||||
|
||||
public IntMinCollector(IntValueStream param) {
|
||||
super(param);
|
||||
this.param = param;
|
||||
|
@ -100,10 +100,10 @@ public abstract class MinCollector<T extends ReductionData> extends ReductionDat
|
|||
}
|
||||
|
||||
int min;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the min value of the set data.
|
||||
*
|
||||
*
|
||||
* @return the min
|
||||
*/
|
||||
public int min() {
|
||||
|
@ -129,7 +129,7 @@ public abstract class MinCollector<T extends ReductionData> extends ReductionDat
|
|||
data.exists = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer) {
|
||||
consumer.accept(new IntCheckedReservation(
|
||||
|
@ -155,17 +155,17 @@ public abstract class MinCollector<T extends ReductionData> extends ReductionDat
|
|||
super.setData(data);
|
||||
min = ((MinData)data).val;
|
||||
}
|
||||
|
||||
|
||||
public static class MinData extends ReductionData {
|
||||
int val;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static class LongMinCollector extends MinCollector<LongMinCollector.MinData> {
|
||||
private LongValueStream param;
|
||||
|
||||
|
||||
public LongMinCollector(LongValueStream param) {
|
||||
super(param);
|
||||
this.param = param;
|
||||
|
@ -179,10 +179,10 @@ public abstract class MinCollector<T extends ReductionData> extends ReductionDat
|
|||
}
|
||||
|
||||
long min;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the min value of the set data.
|
||||
*
|
||||
*
|
||||
* @return the min
|
||||
*/
|
||||
public long min() {
|
||||
|
@ -208,7 +208,7 @@ public abstract class MinCollector<T extends ReductionData> extends ReductionDat
|
|||
data.exists = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer) {
|
||||
consumer.accept(new LongCheckedReservation(
|
||||
|
@ -234,7 +234,7 @@ public abstract class MinCollector<T extends ReductionData> extends ReductionDat
|
|||
super.setData(data);
|
||||
min = ((MinData)data).val;
|
||||
}
|
||||
|
||||
|
||||
public static class MinData extends ReductionData {
|
||||
long val;
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ public abstract class MinCollector<T extends ReductionData> extends ReductionDat
|
|||
|
||||
public static class FloatMinCollector extends MinCollector<FloatMinCollector.MinData> {
|
||||
private FloatValueStream param;
|
||||
|
||||
|
||||
public FloatMinCollector(FloatValueStream param) {
|
||||
super(param);
|
||||
this.param = param;
|
||||
|
@ -256,10 +256,10 @@ public abstract class MinCollector<T extends ReductionData> extends ReductionDat
|
|||
}
|
||||
|
||||
float min;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the min value of the set data.
|
||||
*
|
||||
*
|
||||
* @return the min
|
||||
*/
|
||||
public float min() {
|
||||
|
@ -285,7 +285,7 @@ public abstract class MinCollector<T extends ReductionData> extends ReductionDat
|
|||
data.exists = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer) {
|
||||
consumer.accept(new FloatCheckedReservation(
|
||||
|
@ -311,7 +311,7 @@ public abstract class MinCollector<T extends ReductionData> extends ReductionDat
|
|||
super.setData(data);
|
||||
min = ((MinData)data).val;
|
||||
}
|
||||
|
||||
|
||||
public static class MinData extends ReductionData {
|
||||
float val;
|
||||
}
|
||||
|
@ -319,7 +319,7 @@ public abstract class MinCollector<T extends ReductionData> extends ReductionDat
|
|||
|
||||
public static class DoubleMinCollector extends MinCollector<DoubleMinCollector.MinData> {
|
||||
private DoubleValueStream param;
|
||||
|
||||
|
||||
public DoubleMinCollector(DoubleValueStream param) {
|
||||
super(param);
|
||||
this.param = param;
|
||||
|
@ -333,10 +333,10 @@ public abstract class MinCollector<T extends ReductionData> extends ReductionDat
|
|||
}
|
||||
|
||||
double min;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the min value of the set data.
|
||||
*
|
||||
*
|
||||
* @return the min
|
||||
*/
|
||||
public double min() {
|
||||
|
@ -362,7 +362,7 @@ public abstract class MinCollector<T extends ReductionData> extends ReductionDat
|
|||
data.exists = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer) {
|
||||
consumer.accept(new DoubleCheckedReservation(
|
||||
|
@ -388,17 +388,17 @@ public abstract class MinCollector<T extends ReductionData> extends ReductionDat
|
|||
super.setData(data);
|
||||
min = ((MinData)data).val;
|
||||
}
|
||||
|
||||
|
||||
public static class MinData extends ReductionData {
|
||||
double val;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static class StringMinCollector extends MinCollector<StringMinCollector.MinData> {
|
||||
private StringValueStream param;
|
||||
|
||||
|
||||
public StringMinCollector(StringValueStream param) {
|
||||
super(param);
|
||||
this.param = param;
|
||||
|
@ -412,10 +412,10 @@ public abstract class MinCollector<T extends ReductionData> extends ReductionDat
|
|||
}
|
||||
|
||||
String min;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the min value of the set data.
|
||||
*
|
||||
*
|
||||
* @return the min
|
||||
*/
|
||||
public String min() {
|
||||
|
@ -441,7 +441,7 @@ public abstract class MinCollector<T extends ReductionData> extends ReductionDat
|
|||
data.exists = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer) {
|
||||
consumer.accept(new StringCheckedReservation(
|
||||
|
@ -467,7 +467,7 @@ public abstract class MinCollector<T extends ReductionData> extends ReductionDat
|
|||
super.setData(data);
|
||||
min = ((MinData)data).val;
|
||||
}
|
||||
|
||||
|
||||
public static class MinData extends ReductionData {
|
||||
String val;
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ import org.apache.solr.analytics.stream.reservation.ReductionDataReservation;
|
|||
import org.apache.solr.analytics.value.AnalyticsValue;
|
||||
|
||||
/**
|
||||
* Manager of a specific instance of {@link ReductionData} collection.
|
||||
*
|
||||
* Manager of a specific instance of {@link ReductionData} collection.
|
||||
*
|
||||
* @param <T> the type of reduction data being collected
|
||||
*/
|
||||
public abstract class ReductionDataCollector<T extends ReductionData> {
|
||||
|
@ -33,49 +33,49 @@ public abstract class ReductionDataCollector<T extends ReductionData> {
|
|||
protected ArrayList<T> lastingTargets;
|
||||
protected ArrayList<T> collectionTargets;
|
||||
protected T ioData;
|
||||
|
||||
|
||||
protected ReductionDataCollector() {
|
||||
lastingTargets = new ArrayList<>();
|
||||
collectionTargets = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Submits the data reservations needed for this data collector.
|
||||
*
|
||||
*
|
||||
* @param consumer the consumer which the reservations are submitted to
|
||||
*/
|
||||
public abstract void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer);
|
||||
|
||||
/**
|
||||
* A clean slate to start a new reduction.
|
||||
*
|
||||
*
|
||||
* @return the new reduction data
|
||||
*/
|
||||
public abstract T newData();
|
||||
|
||||
|
||||
/**
|
||||
* Add a reduction data to target during collection.
|
||||
* The given target is valid until the lasting targets are cleared.
|
||||
*
|
||||
*
|
||||
* @param data the data to target
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addLastingCollectTarget(ReductionData data) {
|
||||
lastingTargets.add((T) data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear the lasting collection targets. After this is called the current lasting
|
||||
* targets will not be affected by future {@link #collectAndApply()} calls.
|
||||
* targets will not be affected by future {@link #collectAndApply()} calls.
|
||||
*/
|
||||
public void clearLastingCollectTargets() {
|
||||
lastingTargets.clear();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new reduction data to target during collection.
|
||||
* The given target is only valid for one call to {@link #collectAndApply()}.
|
||||
*
|
||||
*
|
||||
* @return the reduction data created
|
||||
*/
|
||||
public T newDataTarget() {
|
||||
|
@ -83,11 +83,11 @@ public abstract class ReductionDataCollector<T extends ReductionData> {
|
|||
collectionTargets.add(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a reduction data to target during collection.
|
||||
* The given target is only valid for one call to {@link #collectAndApply()}.
|
||||
*
|
||||
*
|
||||
* @param data the data to target
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -98,7 +98,7 @@ public abstract class ReductionDataCollector<T extends ReductionData> {
|
|||
/**
|
||||
* Collect the info for the current Solr Document and apply the results to the
|
||||
* given collection targets.
|
||||
*
|
||||
*
|
||||
* After application, all non-lasting targets are removed.
|
||||
*/
|
||||
public void collectAndApply() {
|
||||
|
@ -107,33 +107,33 @@ public abstract class ReductionDataCollector<T extends ReductionData> {
|
|||
collectionTargets.forEach( target -> apply(target) );
|
||||
collectionTargets.clear();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Collect the information from current Solr Document.
|
||||
*/
|
||||
protected void collect() { }
|
||||
|
||||
|
||||
/**
|
||||
* Apply the collected info to the given reduction data.
|
||||
* Should always be called after a {@link #collect()} call.
|
||||
*
|
||||
*
|
||||
* @param data reduction data to apply collected info to
|
||||
*/
|
||||
protected abstract void apply(T data);
|
||||
|
||||
|
||||
/**
|
||||
* Create a new reduction data to use in exporting and merging.
|
||||
*
|
||||
*
|
||||
* @return the created reduction data
|
||||
*/
|
||||
public T newDataIO() {
|
||||
ioData = newData();
|
||||
return ioData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the reduction data to use in exporting and merging.
|
||||
*
|
||||
*
|
||||
* @param data the data to use
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -143,41 +143,41 @@ public abstract class ReductionDataCollector<T extends ReductionData> {
|
|||
|
||||
/**
|
||||
* Finalize the reduction with the merged data stored in the parameter.
|
||||
* Once the reduction is finalized, the {@link ReductionFunction}s that use this
|
||||
* data collector act like regular {@link AnalyticsValue} classes that
|
||||
* Once the reduction is finalized, the {@link ReductionFunction}s that use this
|
||||
* data collector act like regular {@link AnalyticsValue} classes that
|
||||
* can be accessed through their {@code get<value-type>} methods.
|
||||
*
|
||||
*
|
||||
* (FOR CLOUD)
|
||||
*
|
||||
*
|
||||
* @param data the merged data to compute a reduction for
|
||||
*/
|
||||
public abstract void setMergedData(ReductionData data);
|
||||
|
||||
/**
|
||||
* Finalize the reduction with the collected data stored in the parameter.
|
||||
* Once the reduction is finalized, the {@link ReductionFunction}s that use this
|
||||
* data collector act like regular {@link AnalyticsValue} classes that
|
||||
* Once the reduction is finalized, the {@link ReductionFunction}s that use this
|
||||
* data collector act like regular {@link AnalyticsValue} classes that
|
||||
* can be accessed through their {@code get<value-type>} methods.
|
||||
*
|
||||
*
|
||||
* (FOR SINGLE-SHARD)
|
||||
*
|
||||
*
|
||||
* @param data the collected data to compute a reduction for
|
||||
*/
|
||||
public abstract void setData(ReductionData data);
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the reduction data collector. This is the same across all instances of the data collector.
|
||||
*
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public abstract String getName();
|
||||
|
||||
|
||||
/**
|
||||
* The unique expression string of the reduction data collector, given all inputs and parameters.
|
||||
* Used during {@link ReductionDataCollector} syncing. Since the string should be unique,
|
||||
* only one of expression is kept.
|
||||
*
|
||||
* @return the expression string
|
||||
*
|
||||
* @return the expression string
|
||||
*/
|
||||
public abstract String getExpressionStr();
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ import org.apache.solr.analytics.value.StringValueStream;
|
|||
|
||||
/**
|
||||
* Collector of sorted lists.
|
||||
*
|
||||
*
|
||||
* Once the sorted list has been collected, it can be reduced by calculating a median, percentiles, or ordinals.
|
||||
* All of the above reductions over the same data share one {@link SortedListCollector}.
|
||||
* <p>
|
||||
|
@ -58,19 +58,19 @@ import org.apache.solr.analytics.value.StringValueStream;
|
|||
public abstract class SortedListCollector<T extends Comparable<T>> extends ReductionDataCollector<SortedListCollector.SortedListData<T>> {
|
||||
public static final String name = "sorted";
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
protected SortedListCollector(AnalyticsValueStream param, String specificationName) {
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name + "_" + specificationName,param);
|
||||
|
||||
|
||||
tempList = new ArrayList<>();
|
||||
|
||||
|
||||
calcMedian = false;
|
||||
calcPercs = new HashSet<>();
|
||||
calcOrds = new HashSet<>();
|
||||
}
|
||||
|
||||
|
||||
private List<T> list;
|
||||
|
||||
|
||||
private boolean calcMedian;
|
||||
private Set<Double> calcPercs;
|
||||
private Set<Integer> calcOrds;
|
||||
|
@ -85,10 +85,10 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
|
|||
public void calcMedian() {
|
||||
calcMedian = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Informs the collector that the following percentile needs to be computed.
|
||||
*
|
||||
*
|
||||
* @param percentile requested percentile
|
||||
*/
|
||||
public void calcPercentile(double percentile) {
|
||||
|
@ -97,7 +97,7 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
|
|||
|
||||
/**
|
||||
* Informs the collector that the following ordinal needs to be computed.
|
||||
*
|
||||
*
|
||||
* @param ordinal requested ordinal
|
||||
*/
|
||||
public void calcOrdinal(int ordinal) {
|
||||
|
@ -106,11 +106,11 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
|
|||
|
||||
/**
|
||||
* Once the data has been set by either {@link #setData} or {@link #setMergedData},
|
||||
* this returns the value at the given sorted index.
|
||||
*
|
||||
* this returns the value at the given sorted index.
|
||||
*
|
||||
* Only the indices specified by {@link #calcMedian}, {@link #calcPercentile}, and {@link #calcOrdinal}
|
||||
* will contain valid data. All other indices may return unsorted data.
|
||||
*
|
||||
*
|
||||
* @param index the index of the sorted data to return
|
||||
*/
|
||||
public T get(int index) {
|
||||
|
@ -124,36 +124,36 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
|
|||
data.exists = false;
|
||||
return data;
|
||||
}
|
||||
|
||||
ArrayList<T> tempList;
|
||||
|
||||
ArrayList<T> tempList;
|
||||
@Override
|
||||
protected void apply(SortedListData<T> data) {
|
||||
data.list.addAll(tempList);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Starts the import of the shard data.
|
||||
*
|
||||
*
|
||||
* @param size the size of the incoming shard list
|
||||
*/
|
||||
protected void startImport(int size) {
|
||||
ioData.list.ensureCapacity(ioData.list.size() + size);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Merges the current list with the incoming value.
|
||||
*
|
||||
*
|
||||
* @param value the next imported value to add
|
||||
*/
|
||||
protected void importNext(T value) {
|
||||
ioData.list.add(value);
|
||||
}
|
||||
|
||||
|
||||
Iterator<T> iter;
|
||||
/**
|
||||
* The list to be exported is unsorted.
|
||||
* The lists of all shards will be combined with the {@link #startImport} and {@link #importNext} methods.
|
||||
*
|
||||
*
|
||||
* @return the size of the list being exported.
|
||||
*/
|
||||
public int startExport() {
|
||||
|
@ -162,7 +162,7 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
|
|||
}
|
||||
/**
|
||||
* Return the next value in the list.
|
||||
*
|
||||
*
|
||||
* @return the next sorted value
|
||||
*/
|
||||
public T exportNext() {
|
||||
|
@ -179,7 +179,7 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
|
|||
|
||||
/**
|
||||
* This is where the given indices are put in their sorted positions.
|
||||
*
|
||||
*
|
||||
* Only the given indices are guaranteed to be in sorted order.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -190,7 +190,7 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
|
|||
if (size <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Ordinals start at 0 and end at size-1
|
||||
Set<Integer> ordinals = new HashSet<>();
|
||||
for (double percentile : calcPercs) {
|
||||
|
@ -221,14 +221,14 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
|
|||
public String getExpressionStr() {
|
||||
return exprStr;
|
||||
}
|
||||
|
||||
|
||||
public static class SortedListData<D extends Comparable<D>> extends ReductionData {
|
||||
ArrayList<D> list;
|
||||
}
|
||||
|
||||
public static class SortedIntListCollector extends SortedListCollector<Integer> {
|
||||
private IntValueStream param;
|
||||
|
||||
|
||||
public SortedIntListCollector(IntValueStream param) {
|
||||
super(param, "int");
|
||||
this.param = param;
|
||||
|
@ -239,7 +239,7 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
|
|||
tempList.clear();
|
||||
param.streamInts( val -> tempList.add(val) );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer) {
|
||||
consumer.accept(new IntArrayReservation(
|
||||
|
@ -250,10 +250,10 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
|
|||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class SortedLongListCollector extends SortedListCollector<Long> {
|
||||
private LongValueStream param;
|
||||
|
||||
|
||||
public SortedLongListCollector(LongValueStream param) {
|
||||
super(param, "long");
|
||||
this.param = param;
|
||||
|
@ -264,7 +264,7 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
|
|||
tempList.clear();
|
||||
param.streamLongs( val -> tempList.add(val) );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer) {
|
||||
consumer.accept(new LongArrayReservation(
|
||||
|
@ -275,10 +275,10 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
|
|||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class SortedFloatListCollector extends SortedListCollector<Float> {
|
||||
private FloatValueStream param;
|
||||
|
||||
|
||||
public SortedFloatListCollector(FloatValueStream param) {
|
||||
super(param, "float");
|
||||
this.param = param;
|
||||
|
@ -289,7 +289,7 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
|
|||
tempList.clear();
|
||||
param.streamFloats( val -> tempList.add(val) );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer) {
|
||||
consumer.accept(new FloatArrayReservation(
|
||||
|
@ -300,10 +300,10 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
|
|||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class SortedDoubleListCollector extends SortedListCollector<Double> {
|
||||
private DoubleValueStream param;
|
||||
|
||||
|
||||
public SortedDoubleListCollector(DoubleValueStream param) {
|
||||
super(param, "double");
|
||||
this.param = param;
|
||||
|
@ -314,7 +314,7 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
|
|||
tempList.clear();
|
||||
param.streamDoubles( val -> tempList.add(val) );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer) {
|
||||
consumer.accept(new DoubleArrayReservation(
|
||||
|
@ -325,10 +325,10 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
|
|||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class SortedStringListCollector extends SortedListCollector<String> {
|
||||
private StringValueStream param;
|
||||
|
||||
|
||||
public SortedStringListCollector(StringValueStream param) {
|
||||
super(param, "string");
|
||||
this.param = param;
|
||||
|
@ -339,7 +339,7 @@ public abstract class SortedListCollector<T extends Comparable<T>> extends Reduc
|
|||
tempList.clear();
|
||||
param.streamStrings( val -> tempList.add(val) );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer) {
|
||||
consumer.accept(new StringArrayReservation(
|
||||
|
|
|
@ -24,35 +24,35 @@ import org.apache.solr.analytics.value.AnalyticsValueStream;
|
|||
import org.apache.solr.analytics.value.DoubleValueStream;
|
||||
|
||||
/**
|
||||
* Collects the sum of the given {@link DoubleValueStream} parameter.
|
||||
* Collects the sum of the given {@link DoubleValueStream} parameter.
|
||||
*/
|
||||
public class SumCollector extends ReductionDataCollector<SumCollector.SumData> {
|
||||
private final DoubleValueStream param;
|
||||
public static final String name = "sum";
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public SumCollector(DoubleValueStream param) {
|
||||
this.param = param;
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
}
|
||||
|
||||
|
||||
private double sum;
|
||||
private boolean exists;
|
||||
|
||||
/**
|
||||
* Return the sum of the set data
|
||||
*
|
||||
*
|
||||
* @return the sum
|
||||
*/
|
||||
public double sum() {
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return whether a sum exists.
|
||||
* A sum will always exist if there is at least one existing value for the parameter,
|
||||
* A sum will always exist if there is at least one existing value for the parameter,
|
||||
* otherwise the sum does not exist.
|
||||
*
|
||||
*
|
||||
* @return whether a sum exists
|
||||
*/
|
||||
public boolean exists() {
|
||||
|
@ -116,7 +116,7 @@ public class SumCollector extends ReductionDataCollector<SumCollector.SumData> {
|
|||
public String getExpressionStr() {
|
||||
return exprStr;
|
||||
}
|
||||
|
||||
|
||||
public static class SumData extends ReductionData {
|
||||
double sum;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.apache.solr.analytics.value.LongValueStream;
|
|||
import org.apache.solr.analytics.value.StringValueStream;
|
||||
|
||||
/**
|
||||
* Collects the number of unique values that exist for the given parameter.
|
||||
* Collects the number of unique values that exist for the given parameter.
|
||||
* <p>
|
||||
* Supported types are:
|
||||
* <ul>
|
||||
|
@ -50,17 +50,17 @@ import org.apache.solr.analytics.value.StringValueStream;
|
|||
public abstract class UniqueCollector<T> extends ReductionDataCollector<UniqueCollector.UniqueData<T>> {
|
||||
public static final String name = "unique";
|
||||
private final String exprStr;
|
||||
|
||||
|
||||
public UniqueCollector(AnalyticsValueStream param) {
|
||||
this.exprStr = AnalyticsValueStream.createExpressionString(name,param);
|
||||
this.tempSet = new HashSet<T>();
|
||||
}
|
||||
|
||||
|
||||
private long count;
|
||||
|
||||
/**
|
||||
* Get the count of unique values in the set data.
|
||||
*
|
||||
*
|
||||
* @return the count of unique values
|
||||
*/
|
||||
public long count() {
|
||||
|
@ -74,13 +74,13 @@ public abstract class UniqueCollector<T> extends ReductionDataCollector<UniqueCo
|
|||
data.exists = false;
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
Set<T> tempSet;
|
||||
@Override
|
||||
protected void apply(UniqueData<T> data) {
|
||||
data.set.addAll(tempSet);
|
||||
}
|
||||
|
||||
|
||||
Iterator<T> iter;
|
||||
public int startExport() {
|
||||
iter = ioData.set.iterator();
|
||||
|
@ -108,14 +108,14 @@ public abstract class UniqueCollector<T> extends ReductionDataCollector<UniqueCo
|
|||
public String getExpressionStr() {
|
||||
return exprStr;
|
||||
}
|
||||
|
||||
|
||||
public static class UniqueData<T> extends ReductionData {
|
||||
Set<T> set;
|
||||
}
|
||||
|
||||
public static class UniqueIntCollector extends UniqueCollector<Integer> {
|
||||
private IntValueStream param;
|
||||
|
||||
|
||||
public UniqueIntCollector(IntValueStream param) {
|
||||
super(param);
|
||||
this.param = param;
|
||||
|
@ -126,7 +126,7 @@ public abstract class UniqueCollector<T> extends ReductionDataCollector<UniqueCo
|
|||
tempSet.clear();
|
||||
param.streamInts( val -> tempSet.add(val) );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer) {
|
||||
consumer.accept(new IntArrayReservation(
|
||||
|
@ -137,10 +137,10 @@ public abstract class UniqueCollector<T> extends ReductionDataCollector<UniqueCo
|
|||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class UniqueLongCollector extends UniqueCollector<Long> {
|
||||
private LongValueStream param;
|
||||
|
||||
|
||||
public UniqueLongCollector(LongValueStream param) {
|
||||
super(param);
|
||||
this.param = param;
|
||||
|
@ -151,7 +151,7 @@ public abstract class UniqueCollector<T> extends ReductionDataCollector<UniqueCo
|
|||
tempSet.clear();
|
||||
param.streamLongs( val -> tempSet.add(val) );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer) {
|
||||
consumer.accept(new LongArrayReservation(
|
||||
|
@ -162,10 +162,10 @@ public abstract class UniqueCollector<T> extends ReductionDataCollector<UniqueCo
|
|||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class UniqueFloatCollector extends UniqueCollector<Float> {
|
||||
private FloatValueStream param;
|
||||
|
||||
|
||||
public UniqueFloatCollector(FloatValueStream param) {
|
||||
super(param);
|
||||
this.param = param;
|
||||
|
@ -176,7 +176,7 @@ public abstract class UniqueCollector<T> extends ReductionDataCollector<UniqueCo
|
|||
tempSet.clear();
|
||||
param.streamFloats( val -> tempSet.add(val) );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer) {
|
||||
consumer.accept(new FloatArrayReservation(
|
||||
|
@ -187,10 +187,10 @@ public abstract class UniqueCollector<T> extends ReductionDataCollector<UniqueCo
|
|||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class UniqueDoubleCollector extends UniqueCollector<Double> {
|
||||
private DoubleValueStream param;
|
||||
|
||||
|
||||
public UniqueDoubleCollector(DoubleValueStream param) {
|
||||
super(param);
|
||||
this.param = param;
|
||||
|
@ -201,7 +201,7 @@ public abstract class UniqueCollector<T> extends ReductionDataCollector<UniqueCo
|
|||
tempSet.clear();
|
||||
param.streamDoubles( val -> tempSet.add(val) );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer) {
|
||||
consumer.accept(new DoubleArrayReservation(
|
||||
|
@ -212,10 +212,10 @@ public abstract class UniqueCollector<T> extends ReductionDataCollector<UniqueCo
|
|||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class UniqueStringCollector extends UniqueCollector<String> {
|
||||
private StringValueStream param;
|
||||
|
||||
|
||||
public UniqueStringCollector(StringValueStream param) {
|
||||
super(param);
|
||||
this.param = param;
|
||||
|
@ -226,7 +226,7 @@ public abstract class UniqueCollector<T> extends ReductionDataCollector<UniqueCo
|
|||
tempSet.clear();
|
||||
param.streamStrings( val -> tempSet.add(val) );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void submitReservations(Consumer<ReductionDataReservation<?,?>> consumer) {
|
||||
consumer.accept(new StringArrayReservation(
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Reduction data collectors to use while computing analytics expressions.
|
||||
* For multi-sharded collections, this is the data that is sent from shard to shard.
|
||||
*/
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Reduction functions to use for analytics expressions.
|
||||
*/
|
||||
package org.apache.solr.analytics.function.reduction;
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A solr component to compute complex analytics over search results.
|
||||
|
||||
/**
|
||||
* A solr component to compute complex analytics over search results.
|
||||
*/
|
||||
package org.apache.solr.analytics;
|
||||
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* MBean plugins for stats collection
|
||||
|
||||
/**
|
||||
* MBean plugins for stats collection
|
||||
*/
|
||||
package org.apache.solr.analytics.plugin;
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ import org.apache.solr.response.AnalyticsShardResponseWriter;
|
|||
|
||||
/**
|
||||
* This class manages the requesting of shard responses from all shards in the queried collection.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Shard Requests are sent to the {@link AnalyticsHandler} instead of the {@link AnalyticsComponent},
|
||||
* which is the entrance to the analytics component for all client requests.
|
||||
|
@ -63,7 +63,7 @@ public class AnalyticsShardRequestManager {
|
|||
private final SolrParams params;
|
||||
protected transient CloudSolrClient cloudSolrClient;
|
||||
protected transient List<String> replicaUrls;
|
||||
|
||||
|
||||
/**
|
||||
* All shards responses, which are received in parallel, are funneled into the manager.
|
||||
* So the manager must be transient.
|
||||
|
@ -77,7 +77,7 @@ public class AnalyticsShardRequestManager {
|
|||
|
||||
/**
|
||||
* Send out shard requests to each shard in the given collection.
|
||||
*
|
||||
*
|
||||
* @param collection that is being queried
|
||||
* @param zkHost of the solr cloud hosting the collection
|
||||
* @throws IOException if an exception occurs while picking shards or sending requests
|
||||
|
@ -93,10 +93,10 @@ public class AnalyticsShardRequestManager {
|
|||
cloudSolrClient.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pick one replica from each shard to send the shard requests to.
|
||||
*
|
||||
*
|
||||
* @param collection that is being queried
|
||||
* @throws IOException if an exception occurs while finding replicas
|
||||
*/
|
||||
|
@ -129,15 +129,15 @@ public class AnalyticsShardRequestManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Send a shard request to each chosen replica, streaming
|
||||
* Send a shard request to each chosen replica, streaming
|
||||
* the responses back to the {@link AnalyticsRequestManager}
|
||||
* through the {@link AnalyticsShardResponseParser}.
|
||||
* <p>
|
||||
* A thread pool is used to send the requests simultaneously,
|
||||
* A thread pool is used to send the requests simultaneously,
|
||||
* and therefore importing the results is also done in parallel.
|
||||
* However the manager can only import one shard response at a time,
|
||||
* so the {@link AnalyticsShardResponseParser} is blocked until each import is finished.
|
||||
*
|
||||
*
|
||||
* @throws IOException if an exception occurs while sending requests.
|
||||
*/
|
||||
private void streamFromShards() throws IOException {
|
||||
|
@ -172,11 +172,11 @@ public class AnalyticsShardRequestManager {
|
|||
/**
|
||||
* Create a {@link SolrParams} for shard requests. The only parameters that are copied over from
|
||||
* the original search request are "q" and "fq".
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* The request is sent to the {@link AnalyticsHandler} and the output will be encoded in the analytics bit-stream
|
||||
* format generated by the {@link AnalyticsShardResponseWriter}.
|
||||
*
|
||||
*
|
||||
* @param paramsIn of the original solr request
|
||||
* @param analyticsRequest string representation
|
||||
* @return shard request SolrParams
|
||||
|
@ -205,14 +205,14 @@ public class AnalyticsShardRequestManager {
|
|||
|
||||
/**
|
||||
* Create a requester for analytics shard data.
|
||||
*
|
||||
*
|
||||
* @param baseUrl of the replica to send the request to
|
||||
*/
|
||||
public AnalyticsShardRequester(String baseUrl) {
|
||||
this.baseUrl = baseUrl;
|
||||
this.client = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send the analytics request to the shard.
|
||||
*/
|
||||
|
@ -229,10 +229,10 @@ public class AnalyticsShardRequestManager {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Close the connection to the solr instance.
|
||||
*
|
||||
*
|
||||
* @throws IOException if an error occurs while closing the connection
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
|
|
|
@ -31,17 +31,17 @@ import java.io.Reader;
|
|||
|
||||
/**
|
||||
* This parser initiates a merge of an Analytics Shard Response, sent from the {@link AnalyticsHandler}.
|
||||
*
|
||||
*
|
||||
* The input stream is immediately sent to the given {@link AnalyticsRequestManager} to merge.
|
||||
*/
|
||||
public class AnalyticsShardResponseParser extends ResponseParser {
|
||||
public static final String BINARY_CONTENT_TYPE = "application/octet-stream";
|
||||
public static final String STREAM = "application/octet-stream";
|
||||
|
||||
|
||||
private final AnalyticsRequestManager manager;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param manager the manager of the current Analytics Request, will manage the merging of shard data
|
||||
*/
|
||||
public AnalyticsShardResponseParser(AnalyticsRequestManager manager) {
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Classes to manage the I/O between shards.
|
||||
*/
|
||||
package org.apache.solr.analytics.stream;
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.apache.solr.analytics.stream.reservation.write.BooleanDataArrayWriter
|
|||
import org.apache.solr.analytics.util.function.BooleanConsumer;
|
||||
|
||||
public class BooleanArrayReservation extends ReductionDataArrayReservation<BooleanConsumer, BooleanSupplier> {
|
||||
|
||||
|
||||
public BooleanArrayReservation(BooleanConsumer applier, IntConsumer sizeApplier, BooleanSupplier extractor, IntSupplier sizeExtractor) {
|
||||
super(applier, sizeApplier, extractor, sizeExtractor);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.apache.solr.analytics.stream.reservation.write.BooleanCheckedDataWrit
|
|||
import org.apache.solr.analytics.util.function.BooleanConsumer;
|
||||
|
||||
public class BooleanCheckedReservation extends ReductionCheckedDataReservation<BooleanConsumer, BooleanSupplier> {
|
||||
|
||||
|
||||
public BooleanCheckedReservation(BooleanConsumer applier, BooleanSupplier extractor, BooleanSupplier exists) {
|
||||
super(applier, extractor, exists);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.apache.solr.analytics.stream.reservation.write.BooleanDataWriter;
|
|||
import org.apache.solr.analytics.util.function.BooleanConsumer;
|
||||
|
||||
public class BooleanReservation extends ReductionDataReservation<BooleanConsumer, BooleanSupplier> {
|
||||
|
||||
|
||||
public BooleanReservation(BooleanConsumer applier, BooleanSupplier extractor) {
|
||||
super(applier, extractor);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.apache.solr.analytics.stream.reservation.read.DoubleDataArrayReader;
|
|||
import org.apache.solr.analytics.stream.reservation.write.DoubleDataArrayWriter;
|
||||
|
||||
public class DoubleArrayReservation extends ReductionDataArrayReservation<DoubleConsumer, DoubleSupplier> {
|
||||
|
||||
|
||||
public DoubleArrayReservation(DoubleConsumer applier, IntConsumer sizeApplier, DoubleSupplier extractor, IntSupplier sizeExtractor) {
|
||||
super(applier, sizeApplier, extractor, sizeExtractor);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.apache.solr.analytics.stream.reservation.read.DoubleCheckedDataReader
|
|||
import org.apache.solr.analytics.stream.reservation.write.DoubleCheckedDataWriter;
|
||||
|
||||
public class DoubleCheckedReservation extends ReductionCheckedDataReservation<DoubleConsumer, DoubleSupplier> {
|
||||
|
||||
|
||||
public DoubleCheckedReservation(DoubleConsumer applier, DoubleSupplier extractor, BooleanSupplier exists) {
|
||||
super(applier, extractor, exists);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.apache.solr.analytics.stream.reservation.read.DoubleDataReader;
|
|||
import org.apache.solr.analytics.stream.reservation.write.DoubleDataWriter;
|
||||
|
||||
public class DoubleReservation extends ReductionDataReservation<DoubleConsumer, DoubleSupplier> {
|
||||
|
||||
|
||||
public DoubleReservation(DoubleConsumer applier, DoubleSupplier extractor) {
|
||||
super(applier, extractor);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.apache.solr.analytics.util.function.FloatConsumer;
|
|||
import org.apache.solr.analytics.util.function.FloatSupplier;
|
||||
|
||||
public class FloatArrayReservation extends ReductionDataArrayReservation<FloatConsumer, FloatSupplier> {
|
||||
|
||||
|
||||
public FloatArrayReservation(FloatConsumer applier, IntConsumer sizeApplier, FloatSupplier extractor, IntSupplier sizeExtractor) {
|
||||
super(applier, sizeApplier, extractor, sizeExtractor);
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue