SOLR-3642: Correct broken check for multivalued fields in stats.facet

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1363555 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2012-07-19 21:28:11 +00:00
parent fc2d0ca5e6
commit 47541d03bc
3 changed files with 31 additions and 5 deletions

View File

@ -112,6 +112,8 @@ Bug Fixes
file name using the "config" attribute prevented the override file from being
used. (Ryan Zezeski, hossman)
* SOLR-3642: Correct broken check for multivalued fields in stats.facet
(Yandong Yao, hossman)
Other Changes
----------------------

View File

@ -256,13 +256,12 @@ class SimpleStats {
FieldCache.DocTermsIndex facetTermsIndex;
for( String facetField : facet ) {
SchemaField fsf = searcher.getSchema().getField(facetField);
FieldType facetFieldType = fsf.getType();
if (facetFieldType.isTokenized() || facetFieldType.isMultiValued()) {
if ( fsf.multiValued()) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
"Stats can only facet on single-valued fields, not: " + facetField
+ "[" + facetFieldType + "]");
}
"Stats can only facet on single-valued fields, not: " + facetField );
}
try {
facetTermsIndex = FieldCache.DEFAULT.getTermsIndex(searcher.getAtomicReader(), facetField);
}

View File

@ -27,6 +27,10 @@ import java.text.SimpleDateFormat;
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.schema.IndexSchema;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
@ -340,4 +344,25 @@ public class StatsComponentTest extends AbstractSolrTestCase {
assertQ("test string statistics values", req,
"//null[@name='active_dt'][.='']");
}
public void testStatsFacetMultivaluedErrorHandling() throws Exception {
SolrCore core = h.getCore();
SchemaField foo_ss = core.getSchema().getField("foo_ss");
assertU(adoc("id", "1", "active_i", "1", "foo_ss", "aa" ));
assertU(adoc("id", "2", "active_i", "1", "foo_ss", "bb" ));
assertU(adoc("id", "3", "active_i", "5", "foo_ss", "aa" ));
assertU(commit());
assertTrue("schema no longer satisfies test requirements: foo_ss no longer multivalued", foo_ss.multiValued());
assertTrue("schema no longer satisfies test requirements: foo_ss's fieldtype no longer single valued", ! foo_ss.getType().isMultiValued());
assertQEx("no failure trying to get stats facet on foo_ss",
req("q", "*:*",
"stats", "true",
"stats.field", "active_i",
"stats.facet", "foo_ss"),
400);
}
}