You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by GitBox <gi...@apache.org> on 2019/04/10 08:28:07 UTC

[GitHub] [lucene-solr] chatman commented on a change in pull request #597: [SOLR-13272] feat(facet/interval): support json facet requests for interval facet

chatman commented on a change in pull request #597: [SOLR-13272] feat(facet/interval): support json facet requests for interval facet
URL: https://github.com/apache/lucene-solr/pull/597#discussion_r273843687
 
 

 ##########
 File path: solr/core/src/java/org/apache/solr/search/facet/FacetIntervalProcessor.java
 ##########
 @@ -0,0 +1,154 @@
+/*
+ * 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.search.facet;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.solr.common.SolrException;
+
+class FacetIntervalsProcessor extends FacetRangeProcessor {
+  final Object interval;
+
+  FacetIntervalsProcessor(FacetContext fcontext, FacetIntervals freq) {
+    super(fcontext, freq);
+    if (freq.interval == null) {
+      throw new SolrException
+          (SolrException.ErrorCode.BAD_REQUEST, "Interval param is mandatory");
+    }
+    interval = freq.interval;
+  }
+
+  @Override
+  public void process() throws IOException {
+    handleDomainChanges();
+    if (fcontext.facetInfo != null) { // refinement?
+      response = refineFacets();
+    } else {
+      // phase#1: build list of all buckets and return full facets...
+      if (freq.gap != null) {
+        throw new SolrException
+            (SolrException.ErrorCode.BAD_REQUEST, "Cannot set gap and interval param together");
+      }
+      createIntervalRangeList();
+      response = getRangeCountsIndexed();
+    }
+  }
+
+  private void createIntervalRangeList() throws IOException {
+    rangeList = new ArrayList<>();
+    otherList = new ArrayList<>(3);
+
+    Comparable low = start;
+    Comparable loop_end = this.end;
+    List<Range> ranges = parseInterval(interval);
+    for (Range range : ranges) {
+      rangeList.add(range);
+    }
+    createOtherList(loop_end);
+  }
+
+  private List<Range> parseInterval(Object input) {
+    //interval :[{key:"set1",value:"[0,10]"}]
+    //@todo apoorv handle exception, sort orders
+    List<Map<String, String>> intervals = (List<Map<String, String>>) input;
 
 Review comment:
   >  Another question: shouldn't we employ json to carry those intervals? (might not be good idea at all)
   Might make it verbose for simple ranges.
   
   >  Also, why value? I'd rather call it range
   +1

----------------------------------------------------------------
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


With regards,
Apache Git Services

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