You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2021/03/10 09:53:36 UTC
[lucene] 22/45: SOLR-15191: Fix JSON faceting on EnumFieldType
(#2426)
This is an automated email from the ASF dual-hosted git repository.
dweiss pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene.git
commit 319d06977dd909edd28927a6d7224635d5aca230
Author: Thomas Wöckinger <th...@users.noreply.github.com>
AuthorDate: Sat Feb 27 20:33:39 2021 +0100
SOLR-15191: Fix JSON faceting on EnumFieldType (#2426)
* Fix JSON Faceting on EnumFieldType if allBuckets, numBuckets or missing is set.
* Enhance hash method of JSON faceting to support EnumFieldType and perhaps some other/custom field types
Co-authored-by: Thomas Wöckinger <tw...@silbergrau.com>
Co-authored-by: David Smiley <ds...@apache.org>
---
solr/CHANGES.txt | 5 ++++
.../solr/search/facet/FacetRangeProcessor.java | 30 +++++++---------------
.../test/org/apache/solr/schema/EnumFieldTest.java | 25 ++++++++++++++++++
3 files changed, 39 insertions(+), 21 deletions(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index cc5028e..087ab75 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -35,6 +35,9 @@ Improvements
* SOLR-15038: Add elevateOnlyDocsMatchingQuery and collectElevatedDocsWhenCollapsing parameters to query elevation.
(Dennis Berger, Tobias Kässmann via Bruno Roustant)
+* SOLR-15191: Enhance hash method of JSON faceting to support EnumFieldType and perhaps some other/custom field types
+ too. (Thomas Wöckinger, David Smiley)
+
* SOLR-15194: Allow Solr to make outbound non SSL calls to a JWT IDP via -Dsolr.auth.jwt.allowOutboundHttp=true property. (Eric Pugh)
Optimizations
@@ -54,6 +57,8 @@ Bug Fixes
cache and not know hot to deal with them when writing the updated doc to the update log.
(David Smiley)
+* SOLR-15191: Fix JSON Faceting on EnumFieldType if allBuckets, numBuckets or missing is set.
+ (Thomas Wöckinger, David Smiley)
Other Changes
---------------------
diff --git a/solr/core/src/java/org/apache/solr/search/facet/FacetRangeProcessor.java b/solr/core/src/java/org/apache/solr/search/facet/FacetRangeProcessor.java
index 3cf2f90..29f26f0 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/FacetRangeProcessor.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/FacetRangeProcessor.java
@@ -143,37 +143,25 @@ class FacetRangeProcessor extends FacetProcessor<FacetRange> {
* @see FacetFieldProcessorByHashDV
*/
public static Calc getNumericCalc(SchemaField sf) {
- Calc calc;
final FieldType ft = sf.getType();
- if (ft instanceof TrieField || ft.isPointField()) {
+ if (ft.getNumberType() != null) {
switch (ft.getNumberType()) {
case FLOAT:
- calc = new FloatCalc(sf);
- break;
+ return new FloatCalc(sf);
case DOUBLE:
- calc = new DoubleCalc(sf);
- break;
+ return new DoubleCalc(sf);
case INTEGER:
- calc = new IntCalc(sf);
- break;
+ return new IntCalc(sf);
case LONG:
- calc = new LongCalc(sf);
- break;
+ return new LongCalc(sf);
case DATE:
- calc = new DateCalc(sf, null);
- break;
- default:
- throw new SolrException
- (SolrException.ErrorCode.BAD_REQUEST,
- "Expected numeric field type :" + sf);
+ return new DateCalc(sf, null);
}
- } else {
- throw new SolrException
- (SolrException.ErrorCode.BAD_REQUEST,
- "Expected numeric field type :" + sf);
}
- return calc;
+
+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
+ "Expected numeric field type :" + sf);
}
/**
diff --git a/solr/core/src/test/org/apache/solr/schema/EnumFieldTest.java b/solr/core/src/test/org/apache/solr/schema/EnumFieldTest.java
index 98e55fa..521ce65 100644
--- a/solr/core/src/test/org/apache/solr/schema/EnumFieldTest.java
+++ b/solr/core/src/test/org/apache/solr/schema/EnumFieldTest.java
@@ -570,4 +570,29 @@ public class EnumFieldTest extends SolrTestCaseJ4 {
doInitCore();
}
}
+
+ @Test
+ public void testFacetEnumSearch() throws Exception {
+ assumeFalse("Skipping testing of EnumFieldType without docValues, which is unsupported.",
+ System.getProperty("solr.tests.EnumFieldType").equals("solr.EnumFieldType")
+ && System.getProperty("solr.tests.numeric.dv").equals("false"));
+
+ clearIndex();
+
+ assertU(adoc("id", "0", FIELD_NAME, "Not Available"));
+ assertU(adoc("id", "1", FIELD_NAME, "Low"));
+ assertU(adoc("id", "2", FIELD_NAME, "Medium"));
+ assertU(adoc("id", "3", FIELD_NAME, "High"));
+ assertU(adoc("id", "4", FIELD_NAME, "Critical"));
+ assertU(adoc("id", "5", FIELD_NAME, "Critical"));
+
+ assertU(commit());
+
+ final String jsonFacetParam = "{ " + FIELD_NAME + " : { type : terms, field : " + FIELD_NAME + ", "+
+ "missing : true, exists : true, allBuckets : true, method : enum }}";
+
+ assertQ(req("fl", "" + FIELD_NAME, "q", FIELD_NAME + ":*", "json.facet", jsonFacetParam),
+ "//*[@name='facets']/int/text()=6",
+ "//*[@name='allBuckets']/long/text()=6");
+ }
}