You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2021/06/08 12:35:19 UTC

[GitHub] [lucene-solr] dsmiley commented on a change in pull request #2508: SOLR-15457: Returning EnumFieldValue in faceting buckets again.

dsmiley commented on a change in pull request #2508:
URL: https://github.com/apache/lucene-solr/pull/2508#discussion_r647383022



##########
File path: solr/core/src/test/org/apache/solr/schema/EnumFieldTest.java
##########
@@ -592,6 +592,11 @@ public void testFacetEnumSearch() throws Exception {
 
     assertQ(req("fl", "" + FIELD_NAME, "q", FIELD_NAME + ":*", "json.facet", jsonFacetParam),
         "//*[@name='facets']/int/text()=6",
-        "//*[@name='allBuckets']/long/text()=6");
+        "//*[@name='allBuckets']/long/text()=6",

Review comment:
       So there was a gap in our testing then, I suppose?

##########
File path: solr/core/src/java/org/apache/solr/search/facet/FacetRangeProcessor.java
##########
@@ -774,6 +763,30 @@ public Long parseAndAddGap(@SuppressWarnings("rawtypes") Comparable value, Strin
     }
   }
 
+  private static class EnumCalc extends Calc {
+
+    private final EnumMapping mapping;
+    public EnumCalc(final SchemaField f) {
+      super(f);
+      mapping = ((AbstractEnumField)field.getType()).getEnumMapping();
+    }
+    @Override
+    public EnumFieldValue bitsToValue(long bits) {
+      Integer val = (int)bits;
+      return new EnumFieldValue(val, mapping.intValueToStringValue(val));
+    }
+    @Override
+    protected EnumFieldValue parseStr(String rawval) {

Review comment:
       The test didn't exercise this.  The impl looks suspicious because it parses a String to an integer.

##########
File path: solr/core/src/java/org/apache/solr/search/facet/FacetRangeProcessor.java
##########
@@ -774,6 +763,30 @@ public Long parseAndAddGap(@SuppressWarnings("rawtypes") Comparable value, Strin
     }
   }
 
+  private static class EnumCalc extends Calc {
+
+    private final EnumMapping mapping;
+    public EnumCalc(final SchemaField f) {
+      super(f);
+      mapping = ((AbstractEnumField)field.getType()).getEnumMapping();
+    }
+    @Override
+    public EnumFieldValue bitsToValue(long bits) {
+      Integer val = (int)bits;
+      return new EnumFieldValue(val, mapping.intValueToStringValue(val));
+    }
+    @Override
+    protected EnumFieldValue parseStr(String rawval) {
+      Integer val = Integer.valueOf(rawval);
+      return new EnumFieldValue(val, mapping.intValueToStringValue(val));
+    }
+    @Override
+    protected EnumFieldValue parseAndAddGap(@SuppressWarnings("rawtypes") Comparable value, String gap) {

Review comment:
       The test didn't exercise this.  The impl looks suspicious because it parses a String to an integer.

##########
File path: solr/core/src/java/org/apache/solr/search/facet/FacetRangeProcessor.java
##########
@@ -171,22 +176,7 @@ public static Calc getNumericCalc(SchemaField sf) {
   private static Calc getCalcForField(SchemaField sf) {
     final FieldType ft = sf.getType();
     if (ft instanceof TrieField || ft.isPointField()) {
-      switch (ft.getNumberType()) {
-        case FLOAT:
-          return new FloatCalc(sf);
-        case DOUBLE:
-          return new DoubleCalc(sf);
-        case INTEGER:
-          return new IntCalc(sf);
-        case LONG:
-          return new LongCalc(sf);
-        case DATE:
-          return new DateCalc(sf, null);
-        default:
-          throw new SolrException
-              (SolrException.ErrorCode.BAD_REQUEST,
-                  "Unable to range facet on numeric field of unexpected type:" + sf.getName());
-      }
+      return getNumericCalc(sf);

Review comment:
       Nice!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org