You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dp...@apache.org on 2017/06/28 18:17:33 UTC
[10/20] lucene-solr:master: SOLR-10123: Upgraded the Analytics
Component to version 2.0
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d5963beb/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/AnalyticsRequest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/AnalyticsRequest.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/AnalyticsRequest.java
deleted file mode 100644
index d147e6e..0000000
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/AnalyticsRequest.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.analytics.request;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Contains the specifications of an Analytics Request, specifically a name,
- * a list of Expressions, a list of field facets, a list of range facets, a list of query facets
- * and the list of expressions and their results calculated in previous AnalyticsRequests.
- */
-public class AnalyticsRequest {
-
- private String name;
- private List<ExpressionRequest> expressions;
- private Set<String> hiddenExpressions;
- private List<FieldFacetRequest> fieldFacets;
- private List<RangeFacetRequest> rangeFacets;
- private List<QueryFacetRequest> queryFacets;
-
- public AnalyticsRequest(String name) {
- this.name = name;
- expressions = new ArrayList<>();
- hiddenExpressions = new HashSet<>();
- fieldFacets = new ArrayList<>();
- rangeFacets = new ArrayList<>();
- queryFacets = new ArrayList<>();
- }
-
- public String getName() {
- return name;
- }
-
- public void setExpressions(List<ExpressionRequest> expressions) {
- this.expressions = expressions;
- }
-
- public void addExpression(ExpressionRequest expressionRequest) {
- expressions.add(expressionRequest);
- }
-
- public List<ExpressionRequest> getExpressions() {
- return expressions;
- }
-
- public void addHiddenExpression(ExpressionRequest expressionRequest) {
- expressions.add(expressionRequest);
- hiddenExpressions.add(expressionRequest.getName());
- }
-
- public Set<String> getHiddenExpressions() {
- return hiddenExpressions;
- }
-
- public void setFieldFacets(List<FieldFacetRequest> fieldFacets) {
- this.fieldFacets = fieldFacets;
- }
-
- public List<FieldFacetRequest> getFieldFacets() {
- return fieldFacets;
- }
-
- public void setRangeFacets(List<RangeFacetRequest> rangeFacets) {
- this.rangeFacets = rangeFacets;
- }
-
- public List<RangeFacetRequest> getRangeFacets() {
- return rangeFacets;
- }
-
- public void setQueryFacets(List<QueryFacetRequest> queryFacets) {
- this.queryFacets = queryFacets;
- }
-
- public List<QueryFacetRequest> getQueryFacets() {
- return queryFacets;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder("<AnalyticsRequest name=" + name + ">");
- for (ExpressionRequest exp : expressions) {
- builder.append(exp.toString());
- }
- for (FieldFacetRequest facet : fieldFacets) {
- builder.append(facet.toString());
- }
- for (RangeFacetRequest facet : rangeFacets) {
- builder.append(facet.toString());
- }
- for (QueryFacetRequest facet : queryFacets) {
- builder.append(facet.toString());
- }
- builder.append("</AnalyticsRequest>");
- return builder.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d5963beb/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/AnalyticsRequestFactory.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/AnalyticsRequestFactory.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/AnalyticsRequestFactory.java
deleted file mode 100644
index 3773ff6..0000000
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/AnalyticsRequestFactory.java
+++ /dev/null
@@ -1,308 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.analytics.request;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.solr.analytics.request.FieldFacetRequest.FacetSortSpecification;
-import org.apache.solr.analytics.util.AnalyticsParams;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-import org.apache.solr.common.params.FacetParams.FacetRangeInclude;
-import org.apache.solr.common.params.FacetParams.FacetRangeOther;
-import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.schema.IndexSchema;
-
-/**
- * Parses the SolrParams to create a list of analytics requests.
- */
-public class AnalyticsRequestFactory implements AnalyticsParams {
-
- public static final Pattern statPattern = Pattern.compile("^o(?:lap)?\\.([^\\.]+)\\.(?:"+EXPRESSION+")\\.([^\\.]+)$", Pattern.CASE_INSENSITIVE);
- public static final Pattern hiddenStatPattern = Pattern.compile("^o(?:lap)?\\.([^\\.]+)\\.(?:"+HIDDEN_EXPRESSION+")\\.([^\\.]+)$", Pattern.CASE_INSENSITIVE);
- public static final Pattern fieldFacetPattern = Pattern.compile("^o(?:lap)?\\.([^\\.]+)\\.(?:"+FIELD_FACET+")$", Pattern.CASE_INSENSITIVE);
- public static final Pattern fieldFacetParamPattern = Pattern.compile("^o(?:lap)?\\.([^\\.]+)\\.(?:"+FIELD_FACET+")\\.([^\\.]+)\\.("+LIMIT+"|"+OFFSET+"|"+HIDDEN+"|"+SHOW_MISSING+"|"+SORT_STATISTIC+"|"+SORT_DIRECTION+")$", Pattern.CASE_INSENSITIVE);
- public static final Pattern rangeFacetPattern = Pattern.compile("^o(?:lap)?\\.([^\\.]+)\\.(?:"+RANGE_FACET+")$", Pattern.CASE_INSENSITIVE);
- public static final Pattern rangeFacetParamPattern = Pattern.compile("^o(?:lap)?\\.([^\\.]+)\\.(?:"+RANGE_FACET+")\\.([^\\.]+)\\.("+START+"|"+END+"|"+GAP+"|"+HARDEND+"|"+INCLUDE_BOUNDARY+"|"+OTHER_RANGE+")$", Pattern.CASE_INSENSITIVE);
- public static final Pattern queryFacetPattern = Pattern.compile("^o(?:lap)?\\.([^\\.]+)\\.(?:"+QUERY_FACET+")$", Pattern.CASE_INSENSITIVE);
- public static final Pattern queryFacetParamPattern = Pattern.compile("^o(?:lap)?\\.([^\\.]+)\\.(?:"+QUERY_FACET+")\\.([^\\.]+)\\.("+QUERY+"|"+DEPENDENCY+")$", Pattern.CASE_INSENSITIVE);
-
- public static List<AnalyticsRequest> parse(IndexSchema schema, SolrParams params) {
- Map<String, AnalyticsRequest> requestMap = new HashMap<>();
- Map<String, Map<String,FieldFacetRequest>> fieldFacetMap = new HashMap<>();
- Map<String, Set<String>> fieldFacetSet = new HashMap<>();
- Map<String, Map<String,RangeFacetRequest>> rangeFacetMap = new HashMap<>();
- Map<String, Set<String>> rangeFacetSet = new HashMap<>();
- Map<String, Map<String,QueryFacetRequest>> queryFacetMap = new HashMap<>();
- Map<String, Set<String>> queryFacetSet = new HashMap<>();
- List<AnalyticsRequest> requestList = new ArrayList<>();
-
- Iterator<String> paramsIterator = params.getParameterNamesIterator();
- while (paramsIterator.hasNext()) {
- String param = paramsIterator.next();
- CharSequence paramSequence = param.subSequence(0, param.length());
-
- // Check if stat
- Matcher m = statPattern.matcher(paramSequence);
- if (m.matches()) {
- makeExpression(requestMap,m.group(1),m.group(2),params.get(param));
- } else {
- // Check if hidden stat
- m = hiddenStatPattern.matcher(paramSequence);
- if (m.matches()) {
- makeHiddenExpression(requestMap,m.group(1),m.group(2),params.get(param));
- } else {
- // Check if field facet
- m = fieldFacetPattern.matcher(paramSequence);
- if (m.matches()) {
- makeFieldFacet(schema,fieldFacetMap,fieldFacetSet,m.group(1),params.getParams(param));
- } else {
- // Check if field facet parameter
- m = fieldFacetParamPattern.matcher(paramSequence);
- if (m.matches()) {
- setFieldFacetParam(schema,fieldFacetMap,m.group(1),m.group(2),m.group(3),params.getParams(param));
- } else {
- // Check if range facet
- m = rangeFacetPattern.matcher(paramSequence);
- if (m.matches()) {
- makeRangeFacet(schema,rangeFacetSet,m.group(1),params.getParams(param));
- } else {
- // Check if range facet parameter
- m = rangeFacetParamPattern.matcher(paramSequence);
- if (m.matches()) {
- setRangeFacetParam(schema,rangeFacetMap,m.group(1),m.group(2),m.group(3),params.getParams(param));
- } else {
- // Check if query facet
- m = queryFacetPattern.matcher(paramSequence);
- if (m.matches()) {
- makeQueryFacet(schema,queryFacetSet,m.group(1),params.getParams(param));
- } else {
- // Check if query
- m = queryFacetParamPattern.matcher(paramSequence);
- if (m.matches()) {
- setQueryFacetParam(schema,queryFacetMap,m.group(1),m.group(2),m.group(3),params.getParams(param));
- }
- }
- }
- }
- }
- }
- }
- }
- }
- for (String reqName : requestMap.keySet()) {
- AnalyticsRequest ar = requestMap.get(reqName);
- List<FieldFacetRequest> ffrs = new ArrayList<>();
- if (fieldFacetSet.get(reqName)!=null) {
- for (String field : fieldFacetSet.get(reqName)) {
- ffrs.add(fieldFacetMap.get(reqName).get(field));
- }
- }
- ar.setFieldFacets(ffrs);
-
- List<RangeFacetRequest> rfrs = new ArrayList<>();
- if (rangeFacetSet.get(reqName)!=null) {
- for (String field : rangeFacetSet.get(reqName)) {
- RangeFacetRequest rfr = rangeFacetMap.get(reqName).get(field);
- if (rfr != null) {
- rfrs.add(rfr);
- }
- }
- }
- ar.setRangeFacets(rfrs);
-
- List<QueryFacetRequest> qfrs = new ArrayList<>();
- if (queryFacetSet.get(reqName)!=null) {
- for (String name : queryFacetSet.get(reqName)) {
- QueryFacetRequest qfr = queryFacetMap.get(reqName).get(name);
- if (qfr != null) {
- addQueryFacet(qfrs,qfr);
- }
- }
- }
- for (QueryFacetRequest qfr : qfrs) {
- if (qfr.getDependencies().size()>0) {
- throw new SolrException(ErrorCode.BAD_REQUEST,"The query facet dependencies "+qfr.getDependencies().toString()+" either do not exist or are defined in a dependency looop.");
- }
- }
- ar.setQueryFacets(qfrs);
- requestList.add(ar);
- }
- return requestList;
- }
-
- private static void makeFieldFacet(IndexSchema schema, Map<String, Map<String, FieldFacetRequest>> fieldFacetMap, Map<String, Set<String>> fieldFacetSet, String requestName, String[] fields) {
- Map<String, FieldFacetRequest> facetMap = fieldFacetMap.get(requestName);
- if (facetMap == null) {
- facetMap = new HashMap<>();
- fieldFacetMap.put(requestName, facetMap);
- }
- Set<String> set = fieldFacetSet.get(requestName);
- if (set == null) {
- set = new HashSet<>();
- fieldFacetSet.put(requestName, set);
- }
- for (String field : fields) {
- if (facetMap.get(field) == null) {
- facetMap.put(field,new FieldFacetRequest(schema.getField(field)));
- }
- set.add(field);
- }
- }
-
- private static void setFieldFacetParam(IndexSchema schema, Map<String, Map<String, FieldFacetRequest>> fieldFacetMap, String requestName, String field, String paramType, String[] params) {
- Map<String, FieldFacetRequest> facetMap = fieldFacetMap.get(requestName);
- if (facetMap == null) {
- facetMap = new HashMap<>();
- fieldFacetMap.put(requestName, facetMap);
- }
- FieldFacetRequest fr = facetMap.get(field);
- if (fr == null) {
- fr = new FieldFacetRequest(schema.getField(field));
- facetMap.put(field,fr);
- }
- if (paramType.equals("limit")||paramType.equals("l")) {
- fr.setLimit(Integer.parseInt(params[0]));
- } else if (paramType.equals("offset")||paramType.equals("off")) {
- fr.setOffset(Integer.parseInt(params[0]));
- } else if (paramType.equals("hidden")||paramType.equals("h")) {
- fr.setHidden(Boolean.parseBoolean(params[0]));
- } else if (paramType.equals("showmissing")||paramType.equals("sm")) {
- fr.showMissing(Boolean.parseBoolean(params[0]));
- } else if (paramType.equals("sortstatistic")||paramType.equals("sortstat")||paramType.equals("ss")) {
- fr.setSort(new FacetSortSpecification(params[0],fr.getDirection()));
- } else if (paramType.equals("sortdirection")||paramType.equals("sd")) {
- fr.setDirection(params[0]);
- }
- }
-
- private static void makeRangeFacet(IndexSchema schema, Map<String, Set<String>> rangeFacetSet, String requestName, String[] fields) {
- Set<String> set = rangeFacetSet.get(requestName);
- if (set == null) {
- set = new HashSet<>();
- rangeFacetSet.put(requestName, set);
- }
- for (String field : fields) {
- set.add(field);
- }
- }
-
- private static void setRangeFacetParam(IndexSchema schema, Map<String, Map<String, RangeFacetRequest>> rangeFacetMap, String requestName, String field, String paramType, String[] params) {
- Map<String, RangeFacetRequest> facetMap = rangeFacetMap.get(requestName);
- if (facetMap == null) {
- facetMap = new HashMap<>();
- rangeFacetMap.put(requestName, facetMap);
- }
- RangeFacetRequest rr = facetMap.get(field);
- if (rr == null) {
- rr = new RangeFacetRequest(schema.getField(field));
- facetMap.put(field,rr);
- }
- if (paramType.equals("start")||paramType.equals("st")) {
- rr.setStart(params[0]);
- } else if (paramType.equals("end")||paramType.equals("e")) {
- rr.setEnd(params[0]);
- } else if (paramType.equals("gap")||paramType.equals("g")) {
- rr.setGaps(params[0].split(","));
- } else if (paramType.equals("hardend")||paramType.equals("he")) {
- rr.setHardEnd(Boolean.parseBoolean(params[0]));
- } else if (paramType.equals("includebound")||paramType.equals("ib")) {
- for (String param : params) {
- rr.addInclude(FacetRangeInclude.get(param));
- }
- } else if (paramType.equals("otherrange")||paramType.equals("or")) {
- for (String param : params) {
- rr.addOther(FacetRangeOther.get(param));
- }
- }
- }
-
- private static void makeQueryFacet(IndexSchema schema,Map<String, Set<String>> queryFacetSet, String requestName, String[] names) {
- Set<String> set = queryFacetSet.get(requestName);
- if (set == null) {
- set = new HashSet<>();
- queryFacetSet.put(requestName, set);
- }
- for (String name : names) {
- set.add(name);
- }
- }
-
- private static void setQueryFacetParam(IndexSchema schema, Map<String, Map<String, QueryFacetRequest>> queryFacetMap, String requestName, String name, String paramType, String[] params) {
- Map<String, QueryFacetRequest> facetMap = queryFacetMap.get(requestName);
- if (facetMap == null) {
- facetMap = new HashMap<>();
- queryFacetMap.put(requestName, facetMap);
- }
- QueryFacetRequest qr = facetMap.get(name);
- if (qr == null) {
- qr = new QueryFacetRequest(name);
- facetMap.put(name,qr);
- }
- if (paramType.equals("query")||paramType.equals("q")) {
- for (String query : params) {
- qr.addQuery(query);
- }
- } else if (paramType.equals("dependency")||paramType.equals("d")) {
- for (String depend : params) {
- qr.addDependency(depend);
- }
- }
- }
-
- private static void makeHiddenExpression(Map<String, AnalyticsRequest> requestMap, String requestName, String expressionName, String expression) {
- AnalyticsRequest req = requestMap.get(requestName);
- if (req == null) {
- req = new AnalyticsRequest(requestName);
- requestMap.put(requestName, req);
- }
- req.addHiddenExpression(new ExpressionRequest(expressionName,expression));
- }
-
- private static void makeExpression(Map<String, AnalyticsRequest> requestMap, String requestName, String expressionName, String expression) {
- AnalyticsRequest req = requestMap.get(requestName);
- if (req == null) {
- req = new AnalyticsRequest(requestName);
- requestMap.put(requestName, req);
- }
- req.addExpression(new ExpressionRequest(expressionName,expression));
- }
-
- private static void addQueryFacet(List<QueryFacetRequest> currentList, QueryFacetRequest queryFacet) {
- Set<String> depends = queryFacet.getDependencies();
- int place = 0;
- for (QueryFacetRequest qfr : currentList) {
- if (qfr.getDependencies().remove(queryFacet.getName())) {
- break;
- }
- place++;
- depends.remove(qfr.getName());
- }
- currentList.add(place,queryFacet);
- for (int count = place+1; count < currentList.size(); count++) {
- currentList.get(count).getDependencies().remove(queryFacet.getName());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d5963beb/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/AnalyticsStats.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/AnalyticsStats.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/AnalyticsStats.java
deleted file mode 100644
index 771aff7..0000000
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/AnalyticsStats.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.analytics.request;
-
-import java.io.IOException;
-import java.lang.invoke.MethodHandles;
-import java.util.List;
-
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.search.DocIdSet;
-import org.apache.lucene.search.DocIdSetIterator;
-import org.apache.solr.analytics.accumulator.BasicAccumulator;
-import org.apache.solr.analytics.accumulator.FacetingAccumulator;
-import org.apache.solr.analytics.accumulator.ValueAccumulator;
-import org.apache.solr.analytics.plugin.AnalyticsStatisticsCollector;
-import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.search.DocSet;
-import org.apache.solr.search.Filter;
-import org.apache.solr.search.SolrIndexSearcher;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Class which computes the set of {@link AnalyticsRequest}s.
- */
-public class AnalyticsStats {
- protected DocSet docs;
- protected SolrParams params;
- protected SolrIndexSearcher searcher;
- protected SolrQueryRequest req;
- protected AnalyticsStatisticsCollector statsCollector;
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
- public AnalyticsStats(SolrQueryRequest req, DocSet docs, SolrParams params, AnalyticsStatisticsCollector statsCollector) {
- this.req = req;
- this.searcher = req.getSearcher();
- this.docs = docs;
- this.params = params;
- this.statsCollector = statsCollector;
- }
-
- /**
- * Calculates the analytics requested in the Parameters.
- *
- * @return List of results formated to mirror the input XML.
- * @throws IOException if execution fails
- */
- public NamedList<?> execute() throws IOException {
- statsCollector.startRequest();
- NamedList<Object> res = new NamedList<>();
- List<AnalyticsRequest> requests;
-
- requests = AnalyticsRequestFactory.parse(searcher.getSchema(), params);
-
- if(requests == null || requests.size()==0){
- return res;
- }
- statsCollector.addRequests(requests.size());
-
- // Get filter to all docs
- Filter filter = docs.getTopFilter();
-
- // Computing each Analytics Request Separately
- for( AnalyticsRequest areq : requests ){
- // The Accumulator which will control the statistics generation
- // for the entire analytics request
- ValueAccumulator accumulator;
-
- // The number of total facet requests
- int facets = areq.getFieldFacets().size()+areq.getRangeFacets().size()+areq.getQueryFacets().size();
- try {
- if( facets== 0 ){
- accumulator = BasicAccumulator.create(searcher, docs, areq);
- } else {
- accumulator = FacetingAccumulator.create(searcher, docs, areq, req);
- }
- } catch (IOException e) {
- log.warn("Analytics request '"+areq.getName()+"' failed", e);
- continue;
- }
-
- statsCollector.addStatsCollected(((BasicAccumulator)accumulator).getNumStatsCollectors());
- statsCollector.addStatsRequests(areq.getExpressions().size());
- statsCollector.addFieldFacets(areq.getFieldFacets().size());
- statsCollector.addRangeFacets(areq.getRangeFacets().size());
- statsCollector.addQueryFacets(areq.getQueryFacets().size());
- statsCollector.addQueries(((BasicAccumulator)accumulator).getNumQueries());
-
- // Loop through the documents returned by the query and add to accumulator
- List<LeafReaderContext> contexts = searcher.getTopReaderContext().leaves();
- for (int leafNum = 0; leafNum < contexts.size(); leafNum++) {
- LeafReaderContext context = contexts.get(leafNum);
- DocIdSet dis = filter.getDocIdSet(context, null); // solr docsets already exclude any deleted docs
- DocIdSetIterator disi = null;
- if (dis != null) {
- disi = dis.iterator();
- }
-
- if (disi != null) {
- accumulator.getLeafCollector(context);
- int doc = disi.nextDoc();
- while( doc != DocIdSetIterator.NO_MORE_DOCS){
- // Add a document to the statistics being generated
- accumulator.collect(doc);
- doc = disi.nextDoc();
- }
- }
- }
-
- // do some post-processing
- accumulator.postProcess();
-
- // compute the stats
- accumulator.compute();
-
- res.add(areq.getName(),accumulator.export());
- }
-
- statsCollector.endRequest();
- return res;
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d5963beb/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/ExpressionRequest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/ExpressionRequest.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/ExpressionRequest.java
deleted file mode 100644
index a833c80..0000000
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/ExpressionRequest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.analytics.request;
-
-import org.apache.solr.analytics.expression.Expression;
-
-/**
- * Contains name and string representation of an expression.
- */
-public class ExpressionRequest implements Comparable<ExpressionRequest> {
- private String name;
- private String expressionString;
- private Expression expression;
-
- /**
- * @param name The name of the Expression.
- * @param expressionString The string representation of the desired Expression.
- */
- public ExpressionRequest(String name, String expressionString) {
- this.name = name;
- this.expressionString = expressionString;
- }
-
- public void setExpressionString(String expressionString) {
- this.expressionString = expressionString;
- }
-
- public String getExpressionString() {
- return expressionString;
- }
-
- public void setExpression(Expression expression) {
- this.expression = expression;
- }
-
- public Expression getExpression() {
- return expression;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- @Override
- public int compareTo(ExpressionRequest o) {
- return name.compareTo(o.getName());
- }
-
- @Override
- public String toString() {
- return "<ExpressionRequest name=" + name + " expression=" + expressionString + "/>";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d5963beb/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/FacetRequest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/FacetRequest.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/FacetRequest.java
deleted file mode 100644
index 936af72..0000000
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/FacetRequest.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.analytics.request;
-
-public interface FacetRequest {
-
- /**
- * Get the name of this facet (commonly the field name)
- * @return the name
- */
- String getName();
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d5963beb/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/FieldFacetRequest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/FieldFacetRequest.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/FieldFacetRequest.java
deleted file mode 100644
index 67d93da..0000000
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/FieldFacetRequest.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.analytics.request;
-
-import org.apache.solr.analytics.util.AnalyticsParams;
-import org.apache.solr.schema.SchemaField;
-
-import java.util.Locale;
-
-
-/**
- * Contains all of the specifications for a field facet.
- */
-public class FieldFacetRequest extends AbstractFieldFacetRequest {
-
- private FacetSortSpecification sort = null;
- private FacetSortDirection dir = null;
- private int limit;
- private int offset;
- private boolean missing;
- private boolean hidden;
-
-
- public static enum FacetSortDirection {
- ASCENDING ,
- DESCENDING;
-
- public static FacetSortDirection fromExternal(String value){
- final String sort = value.toLowerCase(Locale.ROOT);
- if( "asc".equals(sort) ) return ASCENDING;
- if( "ascending".equals(sort) ) return ASCENDING;
- if( "desc".equals(sort) ) return DESCENDING;
- if( "descending".equals(sort) ) return DESCENDING;
- return Enum.valueOf(FacetSortDirection.class, value);
- }
- }
-
- /**
- * Specifies how to sort the buckets of a field facet.
- *
- */
- public static class FacetSortSpecification {
- private String statistic;
- private FacetSortDirection direction = FacetSortDirection.DESCENDING;
-
- public FacetSortSpecification(){}
-
- /**
- * @param statistic The name of a statistic specified in the {@link AnalyticsRequest}
- * which is wrapping the {@link FieldFacetRequest} being sorted.
- */
- public FacetSortSpecification(String statistic) {
- this.statistic = statistic;
- }
-
- public FacetSortSpecification(String statistic, FacetSortDirection direction) {
- this(statistic);
- this.direction = direction;
- }
-
- public String getStatistic() {
- return statistic;
- }
- public void setStatistic(String statistic) {
- this.statistic = statistic;
- }
- public FacetSortDirection getDirection() {
- return direction;
- }
- public void setDirection(FacetSortDirection direction) {
- this.direction = direction;
- }
-
- public static FacetSortSpecification fromExternal(String spec){
- String[] parts = spec.split(" ",2);
- if( parts.length == 1 ){
- return new FacetSortSpecification(parts[0]);
- } else {
- return new FacetSortSpecification(parts[0], FacetSortDirection.fromExternal(parts[1]));
- }
- }
-
- @Override
- public String toString() {
- return "<SortSpec stat=" + statistic + " dir=" + direction + ">";
- }
- }
-
- public FieldFacetRequest(SchemaField field) {
- super(field);
- this.limit = AnalyticsParams.DEFAULT_LIMIT;
- this.hidden = AnalyticsParams.DEFAULT_HIDDEN;
- }
-
- public FacetSortDirection getDirection() {
- return dir;
- }
-
- public void setDirection(String dir) {
- this.dir = FacetSortDirection.fromExternal(dir);
- if (sort!=null) {
- sort.setDirection(this.dir);
- }
- }
-
- public FacetSortSpecification getSort() {
- return sort;
- }
-
- public void setSort(FacetSortSpecification sort) {
- this.sort = sort;
- }
-
- public boolean showsMissing() {
- return missing;
- }
-
- /**
- * If there are missing values in the facet field, include the bucket
- * for the missing facet values in the facet response.
- * @param missing true/false if we calculate missing
- */
- public void showMissing(boolean missing) {
- this.missing = missing;
- }
-
- public int getLimit() {
- return limit;
- }
-
- public void setLimit(int limit) {
- this.limit = limit;
- }
-
- public int getOffset() {
- return offset;
- }
-
- public void setOffset(int offset) {
- this.offset = offset;
- }
-
- public boolean isHidden() {
- return hidden;
- }
-
- public void setHidden(boolean hidden) {
- this.hidden = hidden;
- }
-
- @Override
- public String toString() {
- return "<FieldFacetRequest field="+field.getName()+(sort==null?"":" sort=" + sort) + " limit=" + limit+" offset="+offset+">";
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d5963beb/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/QueryFacetRequest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/QueryFacetRequest.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/QueryFacetRequest.java
deleted file mode 100644
index fbe34db..0000000
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/QueryFacetRequest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.analytics.request;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Contains all of the specifications for a query facet.
- */
-public class QueryFacetRequest implements FacetRequest {
- private String name;
- private List<String> queries;
- private Set<String> dependencies;
-
- public QueryFacetRequest() {
- dependencies = new HashSet<>();
- }
-
- public QueryFacetRequest(String name) {
- this.name = name;
- this.queries = new ArrayList<>();
- dependencies = new HashSet<>();
- }
-
- public List<String> getQueries() {
- return queries;
- }
-
- public void setQueries(List<String> queries) {
- this.queries = queries;
- }
-
- public void addQuery(String query) {
- queries.add(query);
- }
-
- public Set<String> getDependencies() {
- return dependencies;
- }
-
- public void setDependencies(Set<String> dependencies) {
- this.dependencies = dependencies;
- }
-
- public void addDependency(String dependency) {
- dependencies.add(dependency);
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d5963beb/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/RangeFacetRequest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/RangeFacetRequest.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/RangeFacetRequest.java
deleted file mode 100644
index ec9cf6b..0000000
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/RangeFacetRequest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.analytics.request;
-
-import java.util.Arrays;
-import java.util.EnumSet;
-
-import org.apache.solr.analytics.util.AnalyticsParams;
-import org.apache.solr.common.params.FacetParams.FacetRangeInclude;
-import org.apache.solr.common.params.FacetParams.FacetRangeOther;
-import org.apache.solr.schema.SchemaField;
-
-/**
- * Contains all of the specifications for a range facet.
- */
-public class RangeFacetRequest extends AbstractFieldFacetRequest {
- protected String start;
- protected String end;
- protected String[] gaps;
- protected boolean hardEnd = false;
- protected EnumSet<FacetRangeInclude> include;
- protected boolean includeCalled = false;
- protected EnumSet<FacetRangeOther> others;
- protected boolean othersCalled = false;
-
- public RangeFacetRequest(SchemaField field) {
- super(field);
- include = EnumSet.of(AnalyticsParams.DEFAULT_INCLUDE);
- others = EnumSet.of(AnalyticsParams.DEFAULT_OTHER);
- }
-
- public RangeFacetRequest(SchemaField field, String start, String end, String[] gaps) {
- super(field);
- this.start = start;
- this.end = end;
- this.gaps = gaps;
- }
-
- public String getStart() {
- return start;
- }
-
- public void setStart(String start) {
- this.start = start;
- }
-
- public String getEnd() {
- return end;
- }
-
- public void setEnd(String end) {
- this.end = end;
- }
-
- public EnumSet<FacetRangeInclude> getInclude() {
- return include;
- }
-
- public void setInclude(EnumSet<FacetRangeInclude> include) {
- includeCalled = true;
- this.include = include;
- }
-
- public void addInclude(FacetRangeInclude include) {
- if (includeCalled) {
- this.include.add(include);
- } else {
- includeCalled = true;
- this.include = EnumSet.of(include);
- }
- }
-
- public String[] getGaps() {
- return gaps;
- }
-
- public void setGaps(String[] gaps) {
- this.gaps = gaps;
- }
-
- public boolean isHardEnd() {
- return hardEnd;
- }
-
- public void setHardEnd(boolean hardEnd) {
- this.hardEnd = hardEnd;
- }
-
- public EnumSet<FacetRangeOther> getOthers() {
- return others;
- }
-
- public void setOthers(EnumSet<FacetRangeOther> others) {
- othersCalled = true;
- this.others = others;
- }
-
- public void addOther(FacetRangeOther other) {
- if (othersCalled) {
- this.others.add(other);
- } else {
- othersCalled = true;
- this.others = EnumSet.of(other);
- }
- }
-
- @Override
- public String toString() {
- return "<RangeFacetRequest field="+field.getName() + " start=" + start + ", end=" + end + ", gap=" + Arrays.toString(gaps) + ", hardEnd=" + hardEnd +
- ", include=" + include + ", others=" + others +">";
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d5963beb/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/package-info.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/package-info.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/package-info.java
deleted file mode 100644
index de2feb3..0000000
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/request/package-info.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Request objects for creating Analytics requests
- */
-package org.apache.solr.analytics.request;
-
-
-
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d5963beb/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/AbstractDelegatingStatsCollector.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/AbstractDelegatingStatsCollector.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/AbstractDelegatingStatsCollector.java
deleted file mode 100644
index 92969f1..0000000
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/AbstractDelegatingStatsCollector.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.analytics.statistics;
-
-import java.io.IOException;
-import java.util.Set;
-
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.queries.function.FunctionValues;
-import org.apache.lucene.util.mutable.MutableValue;
-
-/**
- * <code>AbstractDelegationStatsCollector</code> objects wrap other StatsCollectors.
- * While they compute their own statistics they pass along all inputs and requests
- * to the delegates as well.
- */
-public abstract class AbstractDelegatingStatsCollector implements StatsCollector{
- protected final StatsCollector delegate;
- protected final Set<String> statsList;
- MutableValue value;
- FunctionValues function;
-
- /**
- * @param delegate The delegate computing statistics on the same set of values.
- */
- public AbstractDelegatingStatsCollector(StatsCollector delegate) {
- this.delegate = delegate;
- this.statsList = delegate.getStatsList();
- }
-
- public void setNextReader(LeafReaderContext context) throws IOException {
- delegate.setNextReader(context);
- value = getValue();
- function = getFunction();
- }
-
- public StatsCollector delegate(){
- return delegate;
- }
-
- public Set<String> getStatsList(){
- return statsList;
- }
-
- public MutableValue getValue() {
- return delegate.getValue();
- }
-
- public FunctionValues getFunction() {
- return delegate.getFunction();
- }
-
- public void collect(int doc) throws IOException {
- delegate.collect(doc);
- }
-
- public String valueSourceString() {
- return delegate.valueSourceString();
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d5963beb/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/MedianStatsCollector.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/MedianStatsCollector.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/MedianStatsCollector.java
deleted file mode 100644
index bf71429..0000000
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/MedianStatsCollector.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.analytics.statistics;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import org.apache.solr.analytics.util.MedianCalculator;
-
-/**
- * <code>MedianStatsCollector</code> computes the median.
- */
-public class MedianStatsCollector extends AbstractDelegatingStatsCollector{
-
- private final List<Double> values = new ArrayList<>();
- protected double median;
-
- public MedianStatsCollector(StatsCollector delegate) {
- super(delegate);
- }
-
- public Double getMedian() {
- return new Double(MedianCalculator.getMedian(values));
- }
-
- @Override
- public Comparable getStat(String stat) {
- if (stat.equals("median")) {
- return new Double(median);
- }
- return delegate.getStat(stat);
- }
-
- public void compute(){
- delegate.compute();
- median = getMedian();
- }
-
- @Override
- public void collect(int doc) throws IOException {
- super.collect(doc);
- if (value.exists) {
- values.add(function.doubleVal(doc));
- }
- }
-}
-class DateMedianStatsCollector extends MedianStatsCollector{
-
- public DateMedianStatsCollector(StatsCollector delegate) {
- super(delegate);
- }
-
- @Override
- public Comparable getStat(String stat) {
- if (stat.equals("median")) {
- return new Date((long)median);
- }
- return delegate.getStat(stat);
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d5963beb/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/MinMaxStatsCollector.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/MinMaxStatsCollector.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/MinMaxStatsCollector.java
deleted file mode 100644
index c21b045..0000000
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/MinMaxStatsCollector.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.analytics.statistics;
-
-import java.io.IOException;
-import java.util.Locale;
-import java.util.Set;
-
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.queries.function.FunctionValues;
-import org.apache.lucene.queries.function.FunctionValues.ValueFiller;
-import org.apache.lucene.queries.function.ValueSource;
-import org.apache.lucene.util.mutable.MutableValue;
-
-/**
- * <code>MinMaxStatsCollector</code> computes the min, max, number of values and number of missing values.
- */
-public class MinMaxStatsCollector implements StatsCollector{
- protected long missingCount = 0;
- protected long valueCount = 0;
- protected MutableValue max;
- protected MutableValue min;
- protected MutableValue value;
- protected final Set<String> statsList;
- protected final ValueSource source;
- protected FunctionValues function;
- protected ValueFiller valueFiller;
-
- public MinMaxStatsCollector(ValueSource source, Set<String> statsList) {
- this.source = source;
- this.statsList = statsList;
- }
-
- public void setNextReader(LeafReaderContext context) throws IOException {
- function = source.getValues(null, context);
- valueFiller = function.getValueFiller();
- value = valueFiller.getValue();
- }
-
- public void collect(int doc) throws IOException {
- valueFiller.fillValue(doc);
- if( value.exists ){
- valueCount += 1;
- if ( max==null ) max = value.duplicate();
- else if( !max.exists || value.compareTo(max) > 0 ) max.copy(value);
- if ( min==null ) min = value.duplicate();
- else if( !min.exists || value.compareTo(min) < 0 ) min.copy(value);
- } else {
- missingCount += 1;
- }
- }
-
- @Override
- public String toString() {
- return String.format(Locale.ROOT, "<min=%s max=%s c=%d m=%d>", min, max, valueCount, missingCount );
- }
-
- public Comparable getStat(String stat){
- if (stat.equals("min")&&min!=null) {
- return (Comparable)min.toObject();
- }
- if (stat.equals("max")&&max!=null) {
- return (Comparable)max.toObject();
- }
- if (stat.equals("count")) {
- return new Long(valueCount);
- }
- if (stat.equals("missing")) {
- return new Long(missingCount);
- }
-
- return null;
-// throw new IllegalArgumentException("No stat named '"+stat+"' in this collector " + this);
- }
-
- public Set<String> getStatsList() {
- return statsList;
- }
-
- @Override
- public void compute() { }
-
- @Override
- public MutableValue getValue() {
- return value;
- }
-
- @Override
- public FunctionValues getFunction() {
- return function;
- }
-
- public String valueSourceString() {
- return source.toString();
- }
-
- public String statString(String stat) {
- return stat+"("+valueSourceString()+")";
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d5963beb/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/NumericStatsCollector.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/NumericStatsCollector.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/NumericStatsCollector.java
deleted file mode 100644
index 1f22baa..0000000
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/NumericStatsCollector.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.analytics.statistics;
-
-import java.io.IOException;
-import java.util.Set;
-
-import org.apache.lucene.queries.function.ValueSource;
-
-/**
- * <code>NumericStatsCollector</code> computes the sum, sum of squares, mean and standard deviation.
- */
-public class NumericStatsCollector extends MinMaxStatsCollector {
- protected double sum = 0;
- protected double sumOfSquares = 0;
- protected double mean = 0;
- protected double stddev = 0;
-
- public NumericStatsCollector(ValueSource source, Set<String> statsList) {
- super(source, statsList);
- }
-
- public void collect(int doc) throws IOException {
- super.collect(doc);
- double value = function.doubleVal(doc);
- sum += value;
- sumOfSquares += (value * value);
- }
-
- @Override
- public Comparable getStat(String stat) {
- if (stat.equals("sum")) {
- return new Double(sum);
- }
- if (stat.equals("sumofsquares")) {
- return new Double(sumOfSquares);
- }
- if (stat.equals("mean")) {
- return new Double(mean);
- }
- if (stat.equals("stddev")) {
- return new Double(stddev);
- }
- return super.getStat(stat);
- }
-
- @Override
- public void compute(){
- super.compute();
- mean = (valueCount==0)? 0:sum / valueCount;
- stddev = (valueCount <= 1) ? 0.0D : Math.sqrt((sumOfSquares/valueCount) - (mean*mean));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d5963beb/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/PercentileStatsCollector.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/PercentileStatsCollector.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/PercentileStatsCollector.java
deleted file mode 100644
index e12cb83..0000000
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/PercentileStatsCollector.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.analytics.statistics;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.regex.Pattern;
-
-import org.apache.solr.analytics.util.PercentileCalculator;
-
-import com.google.common.collect.Iterables;
-
-/**
- * <code>PercentileStatsCollector</code> computes a given list of percentiles.
- */
-@SuppressWarnings("rawtypes")
-public class PercentileStatsCollector extends AbstractDelegatingStatsCollector{
- public final List<Comparable> values = new ArrayList<>();
- public static final Pattern PERCENTILE_PATTERN = Pattern.compile("perc(?:entile)?_(\\d+)",Pattern.CASE_INSENSITIVE);
- protected final double[] percentiles;
- protected final String[] percentileNames;
- protected Comparable[] results;
-
- public PercentileStatsCollector(StatsCollector delegate, double[] percentiles, String[] percentileNames) {
- super(delegate);
- this.percentiles = percentiles;
- this.percentileNames = percentileNames;
- }
-
- @Override
- public Comparable getStat(String stat) {
- for( int i=0; i < percentiles.length; i++ ){
- if (stat.equals(percentileNames[i])) {
- if (results!=null) {
- return results[i];
- } else {
- return null;
- }
- }
- }
- return delegate.getStat(stat);
- }
-
- public void compute(){
- delegate.compute();
- if (values.size()>0) {
- results = Iterables.toArray(getPercentiles(),Comparable.class);
- } else {
- results = null;
- }
- }
-
- @SuppressWarnings({ "unchecked"})
- protected List<Comparable> getPercentiles() {
- return PercentileCalculator.getPercentiles(values, percentiles);
- }
-
- public void collect(int doc) throws IOException {
- super.collect(doc);
- if (value.exists) {
- values.add((Comparable)value.toObject());
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d5963beb/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/StatsCollector.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/StatsCollector.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/StatsCollector.java
deleted file mode 100644
index 039300f..0000000
--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/StatsCollector.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr.analytics.statistics;
-
-import java.io.IOException;
-import java.util.Set;
-
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.queries.function.FunctionValues;
-import org.apache.lucene.util.mutable.MutableValue;
-
-/**
- * <code>StatsCollector</code> implementations reduce a list of Objects to a single value.
- * Most implementations reduce a list to a statistic on that list.
- */
-public interface StatsCollector {
-
- /**
- * Collect values from the value source and add to statistics.
- * @param doc Document to collect from
- */
- void collect(int doc) throws IOException;
-
- /**
- * @param context The context to read documents from.
- * @throws IOException if setting next reader fails
- */
- void setNextReader(LeafReaderContext context) throws IOException;
-
- MutableValue getValue();
- FunctionValues getFunction();
-
- /**
- * @return The set of statistics being computed by the stats collector.
- */
- Set<String> getStatsList();
-
- /**
- * Return the value of the given statistic.
- * @param stat the stat
- * @return a comparable
- */
- Comparable getStat(String stat);
-
- /**
- * After all documents have been collected, this method should be
- * called to finalize the calculations of each statistic.
- */
- void compute();
-
- /**
- * @return The string representation of the value source.
- */
- String valueSourceString();
-}