You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2017/09/04 23:57:49 UTC

[1/2] lucene-solr:master: SOLR-10613: add flag to FunctionQParser to use FieldNameValueSource place holder when encountering a field name

Repository: lucene-solr
Updated Branches:
  refs/heads/master 3423ae4b9 -> c6a5f10fd


SOLR-10613: add flag to FunctionQParser to use FieldNameValueSource place holder when encountering a field name


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/33178fb5
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/33178fb5
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/33178fb5

Branch: refs/heads/master
Commit: 33178fb5ccd43fa0c54d2df3760d3362c2700a28
Parents: 3423ae4
Author: yonik <yo...@apache.org>
Authored: Mon Sep 4 18:58:31 2017 -0400
Committer: yonik <yo...@apache.org>
Committed: Mon Sep 4 18:58:52 2017 -0400

----------------------------------------------------------------------
 .../org/apache/solr/search/FunctionQParser.java | 11 +++-
 .../apache/solr/search/ValueSourceParser.java   |  4 +-
 .../org/apache/solr/search/facet/MinMaxAgg.java | 12 +++-
 .../search/function/FieldNameValueSource.java   | 60 ++++++++++++++++++++
 4 files changed, 81 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/33178fb5/solr/core/src/java/org/apache/solr/search/FunctionQParser.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/FunctionQParser.java b/solr/core/src/java/org/apache/solr/search/FunctionQParser.java
index 7e6a706..d3a311d 100644
--- a/solr/core/src/java/org/apache/solr/search/FunctionQParser.java
+++ b/solr/core/src/java/org/apache/solr/search/FunctionQParser.java
@@ -25,6 +25,7 @@ import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.request.SolrQueryRequest;
 import org.apache.solr.schema.SchemaField;
 import org.apache.solr.search.facet.AggValueSource;
+import org.apache.solr.search.function.FieldNameValueSource;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -33,6 +34,7 @@ public class FunctionQParser extends QParser {
 
   public static final int FLAG_CONSUME_DELIMITER = 0x01;  // consume delimiter after parsing arg
   public static final int FLAG_IS_AGG = 0x02;
+  public static final int FLAG_USE_FIELDNAME_SOURCE = 0x04; // When a field name is encountered, use the placeholder FieldNameValueSource instead of resolving to a real ValueSource
   public static final int FLAG_DEFAULT = FLAG_CONSUME_DELIMITER;
 
   /** @lucene.internal */
@@ -374,8 +376,13 @@ public class FunctionQParser extends QParser {
         } else if ("false".equals(id)) {
           valueSource = new BoolConstValueSource(false);
         } else {
-          SchemaField f = req.getSchema().getField(id);
-          valueSource = f.getType().getValueSource(f, this);
+          if ((flags & FLAG_USE_FIELDNAME_SOURCE) != 0) {
+            // Don't try to create a ValueSource for the field, just use a placeholder.
+            valueSource = new FieldNameValueSource(id);
+          } else {
+            SchemaField f = req.getSchema().getField(id);
+            valueSource = f.getType().getValueSource(f, this);
+          }
         }
       }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/33178fb5/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java b/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
index 7d6d162..51048d2 100644
--- a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
+++ b/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
@@ -1017,14 +1017,14 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
     addParser("agg_min", new ValueSourceParser() {
       @Override
       public ValueSource parse(FunctionQParser fp) throws SyntaxError {
-        return new MinMaxAgg("min", fp.parseValueSource());
+        return new MinMaxAgg("min", fp.parseValueSource(FunctionQParser.FLAG_DEFAULT | FunctionQParser.FLAG_USE_FIELDNAME_SOURCE));
       }
     });
 
     addParser("agg_max", new ValueSourceParser() {
       @Override
       public ValueSource parse(FunctionQParser fp) throws SyntaxError {
-        return new MinMaxAgg("max", fp.parseValueSource());
+        return new MinMaxAgg("max", fp.parseValueSource(FunctionQParser.FLAG_DEFAULT | FunctionQParser.FLAG_USE_FIELDNAME_SOURCE));
       }
     });
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/33178fb5/solr/core/src/java/org/apache/solr/search/facet/MinMaxAgg.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/facet/MinMaxAgg.java b/solr/core/src/java/org/apache/solr/search/facet/MinMaxAgg.java
index a6d6b97..9569599 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/MinMaxAgg.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/MinMaxAgg.java
@@ -28,6 +28,7 @@ import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.LongValues;
 import org.apache.solr.schema.SchemaField;
 import org.apache.solr.schema.StrFieldSource;
+import org.apache.solr.search.function.FieldNameValueSource;
 
 public class MinMaxAgg extends SimpleAggValueSource {
   final int minmax; // a multiplier to reverse the normal order of compare if this is max instead of min (i.e. max will be -1)
@@ -41,9 +42,16 @@ public class MinMaxAgg extends SimpleAggValueSource {
   public SlotAcc createSlotAcc(FacetContext fcontext, int numDocs, int numSlots) throws IOException {
     ValueSource vs = getArg();
 
+    SchemaField sf = null;
+
+    if (vs instanceof FieldNameValueSource) {
+      String field = ((FieldNameValueSource)vs).getFieldName();
+      sf = fcontext.qcontext.searcher().getSchema().getField(field);
+
+      vs = sf.getType().getValueSource(sf, null); // temporary implementation to make existing code work
+    }
+
     if (vs instanceof StrFieldSource) {
-      String field = ((StrFieldSource) vs).getField();
-      SchemaField sf = fcontext.qcontext.searcher().getSchema().getField(field);
       if (sf.multiValued() || sf.getType().multiValuedFieldCache()) {
         if (sf.hasDocValues()) {
           // dv

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/33178fb5/solr/core/src/java/org/apache/solr/search/function/FieldNameValueSource.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/function/FieldNameValueSource.java b/solr/core/src/java/org/apache/solr/search/function/FieldNameValueSource.java
new file mode 100644
index 0000000..c122dbb
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/search/function/FieldNameValueSource.java
@@ -0,0 +1,60 @@
+/*
+ * 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.function;
+
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ValueSource;
+
+/** Placeholder value source.
+ * @lucene.internal */
+public class FieldNameValueSource extends ValueSource {
+  private String fieldName;
+
+  public FieldNameValueSource(String fieldName) {
+    this.fieldName = fieldName;
+  }
+
+  public String getFieldName() {
+    return fieldName;
+  }
+
+  @Override
+  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+    throw new UnsupportedOperationException("FieldNameValueSource should not be directly used: " + this);
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    return o instanceof FieldNameValueSource && fieldName.equals(((FieldNameValueSource)o).getFieldName());
+  }
+
+  @Override
+  public int hashCode() {
+    return fieldName.hashCode();
+  }
+
+  @Override
+  public String description() {
+    return "FIELDNAME(" + fieldName + ")";
+  }
+}


[2/2] lucene-solr:master: SOLR-11322: omit val for min/max when no values in field for bucket

Posted by yo...@apache.org.
SOLR-11322: omit val for min/max when no values in field for bucket


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/c6a5f10f
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/c6a5f10f
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/c6a5f10f

Branch: refs/heads/master
Commit: c6a5f10fd364a0c63477348560e0c6eb1a742d3e
Parents: 33178fb
Author: yonik <yo...@apache.org>
Authored: Mon Sep 4 19:19:40 2017 -0400
Committer: yonik <yo...@apache.org>
Committed: Mon Sep 4 19:19:40 2017 -0400

----------------------------------------------------------------------
 solr/CHANGES.txt                                          |  4 ++++
 .../src/java/org/apache/solr/search/facet/MinMaxAgg.java  | 10 ++++++++++
 .../test/org/apache/solr/search/facet/TestJsonFacets.java |  4 ++--
 3 files changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c6a5f10f/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 4ccc609..56b55c9 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -183,6 +183,10 @@ Other Changes
 
 * SOLR-11209: Upgrade HttpClient to 4.5.3. (Hrishikesh Gadre via Mark Miller)
 
+* SOLR-11322: JSON Facet API: instead of returning NaN, min & max aggregations omit
+  the value for any bucket with no values in the numeric field. (yonik)
+
+
 ==================  7.0.0 ==================
 
 Versions of Major Components

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c6a5f10f/solr/core/src/java/org/apache/solr/search/facet/MinMaxAgg.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/facet/MinMaxAgg.java b/solr/core/src/java/org/apache/solr/search/facet/MinMaxAgg.java
index 9569599..0f4bea6 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/MinMaxAgg.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/MinMaxAgg.java
@@ -137,6 +137,16 @@ public class MinMaxAgg extends SimpleAggValueSource {
         result[slotNum] = val;
       }
     }
+
+    @Override
+    public Object getValue(int slot) {
+      double val = result[slot];
+      if (Double.isNaN(val)) {
+        return null;
+      } else {
+        return val;
+      }
+    }
   }
 
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c6a5f10f/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java
index 3ee069f..5ecd3a1 100644
--- a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java
+++ b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java
@@ -1019,8 +1019,8 @@ public class TestJsonFacets extends SolrTestCaseHS {
             ",sum1:0.0," +
             " sumsq1:0.0," +
             " avg1:0.0," +   // TODO: undesirable. omit?
-            " min1:'NaN'," + // TODO: undesirable. omit?
-            " max1:'NaN'," +
+            // " min1:'NaN'," +
+            // " max1:'NaN'," +
             " numwhere:0," +
             " unique_num_i:0," +
             " unique_num_d:0," +