SOLR-1276: Stats Component test

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@803571 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Grant Ingersoll 2009-08-12 15:54:36 +00:00
parent bf3968ddaf
commit 70039d6ff1
2 changed files with 146 additions and 0 deletions

View File

@ -581,6 +581,8 @@ Other Changes
44. Upgraded to Lucene 2.9-dev r801856 (Mark Miller)
45. SOLR1276: Added StatsComponentTest (Rafał Kuć, gsingers)
Build
----------------------
1. SOLR-776: Added in ability to sign artifacts via Ant for releases (gsingers)

View File

@ -0,0 +1,144 @@
package org.apache.solr.handler.component;
/**
* 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.
*/
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.MapSolrParams;
import org.apache.solr.common.params.StatsParams;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.util.AbstractSolrTestCase;
import java.util.HashMap;
import java.util.Map;
/**
* Statistics Component Test
*/
public class StatsComponentTest extends AbstractSolrTestCase {
@Override
public String getSchemaFile() {
return "schema11.xml";
}
@Override
public String getSolrConfigFile() {
return "solrconfig.xml";
}
@Override
public void setUp() throws Exception {
super.setUp();
lrf = h.getRequestFactory("standard", 0, 20);
}
public void testFieldStatisticsResult() throws Exception {
SolrCore core = h.getCore();
assertU(adoc("id", "1", "stats_i", "-10"));
assertU(adoc("id", "2", "stats_i", "-20"));
assertU(adoc("id", "3", "stats_i", "-30"));
assertU(adoc("id", "4", "stats_i", "-40"));
assertU(commit());
Map<String, String> args = new HashMap<String, String>();
args.put(CommonParams.Q, "*:*");
args.put(StatsParams.STATS, "true");
args.put(StatsParams.STATS_FIELD, "stats_i");
args.put("indent", "true");
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("test statistics values", req
, "//double[@name='min'][.='-40.0']"
, "//double[@name='max'][.='-10.0']"
, "//double[@name='sum'][.='-100.0']"
, "//long[@name='count'][.='4']"
, "//long[@name='missing'][.='0']"
, "//double[@name='sumOfSquares'][.='3000.0']"
, "//double[@name='mean'][.='-25.0']"
, "//double[@name='stddev'][.='12.909944487358056']"
);
}
public void testFieldStatisticsMissingResult() throws Exception {
SolrCore core = h.getCore();
assertU(adoc("id", "1", "stats_i", "-10"));
assertU(adoc("id", "2", "stats_i", "-20"));
assertU(adoc("id", "3"));
assertU(adoc("id", "4", "stats_i", "-40"));
assertU(commit());
Map<String, String> args = new HashMap<String, String>();
args.put(CommonParams.Q, "*:*");
args.put(StatsParams.STATS, "true");
args.put(StatsParams.STATS_FIELD, "stats_i");
args.put("indent", "true");
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("test statistics values", req
, "//double[@name='min'][.='-40.0']"
, "//double[@name='max'][.='-10.0']"
, "//double[@name='sum'][.='-70.0']"
, "//long[@name='count'][.='3']"
, "//long[@name='missing'][.='1']"
, "//double[@name='sumOfSquares'][.='2100.0']"
, "//double[@name='mean'][.='--23.333333333333332']"
, "//double[@name='stddev'][.='15.275252316519467']"
);
}
public void testFacetStatisticsResult() throws Exception {
SolrCore core = h.getCore();
assertU(adoc("id", "1", "stats_i", "10", "active_s", "true"));
assertU(adoc("id", "2", "stats_i", "20", "active_s", "true"));
assertU(adoc("id", "3", "stats_i", "30", "active_s", "false"));
assertU(adoc("id", "4", "stats_i", "40", "active_s", "false"));
assertU(commit());
Map<String, String> args = new HashMap<String, String>();
args.put(CommonParams.Q, "*:*");
args.put(StatsParams.STATS, "true");
args.put(StatsParams.STATS_FIELD, "stats_i");
args.put(StatsParams.STATS_FACET, "active_s");
args.put("indent", "true");
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("test value for active_s=true", req
, "//lst[@name='true']/double[@name='min'][.='10.0']"
, "//lst[@name='true']/double[@name='max'][.='20.0']"
, "//lst[@name='true']/double[@name='sum'][.='30.0']"
, "//lst[@name='true']/long[@name='count'][.='2']"
, "//lst[@name='true']/long[@name='missing'][.='0']"
, "//lst[@name='true']/double[@name='sumOfSquares'][.='500.0']"
, "//lst[@name='true']/double[@name='mean'][.='15.0']"
, "//lst[@name='true']/double[@name='stddev'][.='7.0710678118654755']"
);
assertQ("test value for active_s=false", req
, "//lst[@name='false']/double[@name='min'][.='30.0']"
, "//lst[@name='false']/double[@name='max'][.='40.0']"
, "//lst[@name='false']/double[@name='sum'][.='70.0']"
, "//lst[@name='false']/long[@name='count'][.='2']"
, "//lst[@name='false']/long[@name='missing'][.='0']"
, "//lst[@name='false']/double[@name='sumOfSquares'][.='2500.0']"
, "//lst[@name='false']/double[@name='mean'][.='35.0']"
, "//lst[@name='false']/double[@name='stddev'][.='7.0710678118654755']"
);
}
}