lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hoss...@apache.org
Subject svn commit: r1176097 - in /lucene/dev/trunk: modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ solr/ solr/core/src/java/org/apache/solr/search/ solr/core/src/test/org/apache/solr/search/function/
Date Mon, 26 Sep 2011 22:03:31 GMT
Author: hossman
Date: Mon Sep 26 22:03:31 2011
New Revision: 1176097

URL: http://svn.apache.org/viewvc?rev=1176097&view=rev
Log:
SOLR-2757: min/max functions now take unlimited number of arguments

Added:
    lucene/dev/trunk/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/MaxFloatFunction.java
  (with props)
    lucene/dev/trunk/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/MinFloatFunction.java
  (with props)
Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java

Added: lucene/dev/trunk/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/MaxFloatFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/MaxFloatFunction.java?rev=1176097&view=auto
==============================================================================
--- lucene/dev/trunk/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/MaxFloatFunction.java
(added)
+++ lucene/dev/trunk/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/MaxFloatFunction.java
Mon Sep 26 22:03:31 2011
@@ -0,0 +1,50 @@
+/**
+ * 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.lucene.queries.function.valuesource;
+
+import org.apache.lucene.queries.function.DocValues;
+import org.apache.lucene.queries.function.ValueSource;
+
+/**
+ * <code>MaxFloatFunction</code> returns the max of it's components.
+ */
+public class MaxFloatFunction extends MultiFloatFunction {
+  public MaxFloatFunction(ValueSource[] sources) {
+    super(sources);
+  }
+
+  @Override  
+  protected String name() {
+    return "max";
+  }
+
+  @Override
+  protected float func(int doc, DocValues[] valsArr) {
+    boolean first = true;
+    float val = 0.0f;
+    for (DocValues vals : valsArr) {
+      if (first) {
+        first = false;
+        val = vals.floatVal(doc);
+      } else {
+        val = Math.max(vals.floatVal(doc),val);
+      }
+    }
+    return val;
+  }
+}

Added: lucene/dev/trunk/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/MinFloatFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/MinFloatFunction.java?rev=1176097&view=auto
==============================================================================
--- lucene/dev/trunk/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/MinFloatFunction.java
(added)
+++ lucene/dev/trunk/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/MinFloatFunction.java
Mon Sep 26 22:03:31 2011
@@ -0,0 +1,50 @@
+/**
+ * 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.lucene.queries.function.valuesource;
+
+import org.apache.lucene.queries.function.DocValues;
+import org.apache.lucene.queries.function.ValueSource;
+
+/**
+ * <code>MinFloatFunction</code> returns the min of it's components.
+ */
+public class MinFloatFunction extends MultiFloatFunction {
+  public MinFloatFunction(ValueSource[] sources) {
+    super(sources);
+  }
+
+  @Override  
+  protected String name() {
+    return "min";
+  }
+
+  @Override
+  protected float func(int doc, DocValues[] valsArr) {
+    boolean first = true;
+    float val = 0.0f;
+    for (DocValues vals : valsArr) {
+      if (first) {
+        first = false;
+        val = vals.floatVal(doc);
+      } else {
+        val = Math.min(vals.floatVal(doc),val);
+      }
+    }
+    return val;
+  }
+}

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1176097&r1=1176096&r2=1176097&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Mon Sep 26 22:03:31 2011
@@ -31,7 +31,7 @@ Apache UIMA 2.3.1
 Apache ZooKeeper 3.3.3
 
 
-Upgrading from Solr 3.4-dev
+Upgrading from Solr 3.5-dev
 ----------------------
 
 * The Lucene index format has changed and as a result, once you upgrade, 
@@ -398,6 +398,9 @@ Bug Fixes
 
 * LUCENE-3457: Upgrade commons-compress to 1.2 (Doron Cohen)
 
+* SOLR-2757: min() and max() functions now support an arbitrary number of 
+  ValueSources  (Bill Bell via hossman)
+
 ==================  3.4.0  ==================
 
 Upgrading from Solr 3.3

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java?rev=1176097&r1=1176096&r2=1176097&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java Mon
Sep 26 22:03:31 2011
@@ -483,19 +483,20 @@ public abstract class ValueSourceParser 
         return Math.atan2(a.doubleVal(doc), b.doubleVal(doc));
       }
     });
-    addParser(new Double2Parser("max") {
+    addParser("max", new ValueSourceParser() {
       @Override
-      public double func(int doc, DocValues a, DocValues b) {
-        return Math.max(a.doubleVal(doc), b.doubleVal(doc));
+      public ValueSource parse(FunctionQParser fp) throws ParseException {
+        List<ValueSource> sources = fp.parseValueSourceList();
+        return new MaxFloatFunction(sources.toArray(new ValueSource[sources.size()]));
       }
     });
-    addParser(new Double2Parser("min") {
+    addParser("min", new ValueSourceParser() {
       @Override
-      public double func(int doc, DocValues a, DocValues b) {
-        return Math.min(a.doubleVal(doc), b.doubleVal(doc));
+      public ValueSource parse(FunctionQParser fp) throws ParseException {
+        List<ValueSource> sources = fp.parseValueSourceList();
+        return new MinFloatFunction(sources.toArray(new ValueSource[sources.size()]));
       }
     });
-
     addParser("sqedist", new ValueSourceParser() {
       @Override
       public ValueSource parse(FunctionQParser fp) throws ParseException {

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java?rev=1176097&r1=1176096&r2=1176097&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java
(original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java
Mon Sep 26 22:03:31 2011
@@ -571,7 +571,9 @@ public class TestFunctionQuery extends S
     dofunc("sqrt(9)", Math.sqrt(9));
     dofunc("cbrt(8)", Math.cbrt(8));
     dofunc("max(0,1)", Math.max(0,1));
+    dofunc("max(10,3,8,7,5,4)", Math.max(Math.max(Math.max(Math.max(Math.max(10,3),8),7),5),4));
     dofunc("min(0,1)", Math.min(0,1));
+    dofunc("min(10,3,8,7,5,4)", Math.min(Math.min(Math.min(Math.min(Math.min(10,3),8),7),5),4));
     dofunc("log(100)", Math.log10(100));
     dofunc("ln(3)", Math.log(3));
     dofunc("exp(1)", Math.exp(1));



Mime
View raw message