Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6C632200CC6 for ; Mon, 3 Jul 2017 13:57:46 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 6B75D160C04; Mon, 3 Jul 2017 11:57:46 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 778EE160C06 for ; Mon, 3 Jul 2017 13:57:44 +0200 (CEST) Received: (qmail 77966 invoked by uid 500); 3 Jul 2017 11:57:42 -0000 Mailing-List: contact commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list commits@lucene.apache.org Received: (qmail 77782 invoked by uid 99); 3 Jul 2017 11:57:42 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Jul 2017 11:57:42 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 814EBE041D; Mon, 3 Jul 2017 11:57:41 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ab@apache.org To: commits@lucene.apache.org Date: Mon, 03 Jul 2017 11:57:50 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [10/58] [abbrv] lucene-solr:jira/solr-10879: SOLR-10123: Upgraded the Analytics Component to version 2.0 archived-at: Mon, 03 Jul 2017 11:57:46 -0000 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 expressions; - private Set hiddenExpressions; - private List fieldFacets; - private List rangeFacets; - private List 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 expressions) { - this.expressions = expressions; - } - - public void addExpression(ExpressionRequest expressionRequest) { - expressions.add(expressionRequest); - } - - public List getExpressions() { - return expressions; - } - - public void addHiddenExpression(ExpressionRequest expressionRequest) { - expressions.add(expressionRequest); - hiddenExpressions.add(expressionRequest.getName()); - } - - public Set getHiddenExpressions() { - return hiddenExpressions; - } - - public void setFieldFacets(List fieldFacets) { - this.fieldFacets = fieldFacets; - } - - public List getFieldFacets() { - return fieldFacets; - } - - public void setRangeFacets(List rangeFacets) { - this.rangeFacets = rangeFacets; - } - - public List getRangeFacets() { - return rangeFacets; - } - - public void setQueryFacets(List queryFacets) { - this.queryFacets = queryFacets; - } - - public List getQueryFacets() { - return queryFacets; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(""); - 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(""); - 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 parse(IndexSchema schema, SolrParams params) { - Map requestMap = new HashMap<>(); - Map> fieldFacetMap = new HashMap<>(); - Map> fieldFacetSet = new HashMap<>(); - Map> rangeFacetMap = new HashMap<>(); - Map> rangeFacetSet = new HashMap<>(); - Map> queryFacetMap = new HashMap<>(); - Map> queryFacetSet = new HashMap<>(); - List requestList = new ArrayList<>(); - - Iterator 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 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 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 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> fieldFacetMap, Map> fieldFacetSet, String requestName, String[] fields) { - Map facetMap = fieldFacetMap.get(requestName); - if (facetMap == null) { - facetMap = new HashMap<>(); - fieldFacetMap.put(requestName, facetMap); - } - Set 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> fieldFacetMap, String requestName, String field, String paramType, String[] params) { - Map 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> rangeFacetSet, String requestName, String[] fields) { - Set 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> rangeFacetMap, String requestName, String field, String paramType, String[] params) { - Map 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> queryFacetSet, String requestName, String[] names) { - Set 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> queryFacetMap, String requestName, String name, String paramType, String[] params) { - Map 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 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 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 currentList, QueryFacetRequest queryFacet) { - Set 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 res = new NamedList<>(); - List 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 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 { - 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 ""; - } - -} 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 ""; - } - } - - 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 ""; - } - - - -} 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 queries; - private Set dependencies; - - public QueryFacetRequest() { - dependencies = new HashSet<>(); - } - - public QueryFacetRequest(String name) { - this.name = name; - this.queries = new ArrayList<>(); - dependencies = new HashSet<>(); - } - - public List getQueries() { - return queries; - } - - public void setQueries(List queries) { - this.queries = queries; - } - - public void addQuery(String query) { - queries.add(query); - } - - public Set getDependencies() { - return dependencies; - } - - public void setDependencies(Set 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 include; - protected boolean includeCalled = false; - protected EnumSet 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 getInclude() { - return include; - } - - public void setInclude(EnumSet 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 getOthers() { - return others; - } - - public void setOthers(EnumSet 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 ""; - } - - - -} 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; - -/** - * AbstractDelegationStatsCollector 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 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 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; - -/** - * MedianStatsCollector computes the median. - */ -public class MedianStatsCollector extends AbstractDelegatingStatsCollector{ - - private final List 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; - -/** - * MinMaxStatsCollector 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 statsList; - protected final ValueSource source; - protected FunctionValues function; - protected ValueFiller valueFiller; - - public MinMaxStatsCollector(ValueSource source, Set 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, 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 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; - -/** - * NumericStatsCollector 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 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; - -/** - * PercentileStatsCollector computes a given list of percentiles. - */ -@SuppressWarnings("rawtypes") -public class PercentileStatsCollector extends AbstractDelegatingStatsCollector{ - public final List 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 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; - -/** - * StatsCollector 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 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(); -}