You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jb...@apache.org on 2018/09/07 19:48:57 UTC
lucene-solr:branch_7x: SOLR-11943: Change location... to latlon...
Repository: lucene-solr
Updated Branches:
refs/heads/branch_7x 66dfc59e6 -> 893a678dc
SOLR-11943: Change location... to latlon...
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/893a678d
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/893a678d
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/893a678d
Branch: refs/heads/branch_7x
Commit: 893a678dc7bdb8bf65116660c0956b8e245620ed
Parents: 66dfc59
Author: Joel Bernstein <jb...@apache.org>
Authored: Fri Sep 7 15:42:03 2018 -0400
Committer: Joel Bernstein <jb...@apache.org>
Committed: Fri Sep 7 15:43:36 2018 -0400
----------------------------------------------------------------------
.../org/apache/solr/client/solrj/io/Lang.java | 2 +-
.../solrj/io/eval/LatLonVectorsEvaluator.java | 115 +++++++++++++++++++
.../solrj/io/eval/LocationVectorsEvaluator.java | 105 -----------------
.../apache/solr/client/solrj/io/TestLang.java | 2 +-
.../solrj/io/stream/MathExpressionTest.java | 4 +-
5 files changed, 119 insertions(+), 109 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/893a678d/solr/solrj/src/java/org/apache/solr/client/solrj/io/Lang.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/Lang.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/Lang.java
index 9568ecb..3f24e7b 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/Lang.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/Lang.java
@@ -255,7 +255,7 @@ public class Lang {
.withFunctionName("removeCache", RemoveCacheEvaluator.class)
.withFunctionName("listCache", ListCacheEvaluator.class)
.withFunctionName("zscores", NormalizeEvaluator.class)
- .withFunctionName("locationVectors", LocationVectorsEvaluator.class)
+ .withFunctionName("latlonVectors", LatLonVectorsEvaluator.class)
// Boolean Stream Evaluators
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/893a678d/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/LatLonVectorsEvaluator.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/LatLonVectorsEvaluator.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/LatLonVectorsEvaluator.java
new file mode 100644
index 0000000..de8168a
--- /dev/null
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/LatLonVectorsEvaluator.java
@@ -0,0 +1,115 @@
+/*
+ * 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.client.solrj.io.eval;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
+
+import org.apache.solr.client.solrj.io.Tuple;
+import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
+import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter;
+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
+
+/**
+ * The LatLonVectorsEvaluator maps to the latlonVectors Math Expression. The latlonVectors expression
+ * takes a list of Tuples that contain a lat,lon point field and a named parameter called field
+ * as input. The field parameter specifies which field to parse the lat,lon vectors from in the Tuples.
+ *
+ * The latlonVectors function returns a matrix of lat,lon vectors. Each row in the matrix
+ * contains a single lat,lon pair.
+ *
+ **/
+
+public class LatLonVectorsEvaluator extends RecursiveObjectEvaluator implements ManyValueWorker {
+ protected static final long serialVersionUID = 1L;
+
+ private String field;
+
+ public LatLonVectorsEvaluator(StreamExpression expression, StreamFactory factory) throws IOException {
+ super(expression, factory);
+
+ List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);
+
+ for (StreamExpressionNamedParameter namedParam : namedParams) {
+ if(namedParam.getName().equals("field")) {
+ this.field = namedParam.getParameter().toString();
+ } else {
+ throw new IOException("Unexpected named parameter:" + namedParam.getName());
+ }
+ }
+
+ if(field == null) {
+ throw new IOException("The named parameter \"field\" must be set for the latlonVectors function.");
+ }
+ }
+
+ @Override
+ public Object doWork(Object... objects) throws IOException {
+
+ if (objects.length == 1) {
+ //Just docs
+ if(!(objects[0] instanceof List)) {
+ throw new IOException("The latlonVectors function expects a list of Tuples as a parameter.");
+ } else {
+ List list = (List)objects[0];
+ if(list.size() > 0) {
+ Object o = list.get(0);
+ if(!(o instanceof Tuple)) {
+ throw new IOException("The latlonVectors function expects a list of Tuples as a parameter.");
+ }
+ } else {
+ throw new IOException("Empty list was passed as a parameter to termVectors function.");
+ }
+ }
+
+ List<Tuple> tuples = (List<Tuple>) objects[0];
+
+ double[][] locationVectors = new double[tuples.size()][2];
+ List<String> features = new ArrayList();
+ features.add("lat");
+ features.add("lon");
+
+ List<String> rowLabels = new ArrayList();
+
+ for(int i=0; i< tuples.size(); i++) {
+ Tuple tuple = tuples.get(i);
+ String value = tuple.getString(field);
+ String[] latLong = null;
+ if(value.contains(",")) {
+ latLong = value.split(",");
+ } else {
+ latLong = value.split(" ");
+ }
+
+ locationVectors[i][0] = Double.parseDouble(latLong[0].trim());
+ locationVectors[i][1] = Double.parseDouble(latLong[1].trim());
+ if(tuple.get("id") != null) {
+ rowLabels.add(tuple.get("id").toString());
+ }
+ }
+
+ Matrix matrix = new Matrix(locationVectors);
+ matrix.setColumnLabels(features);
+ matrix.setRowLabels(rowLabels);
+ return matrix;
+ } else {
+ throw new IOException("The latlonVectors function takes a single positional parameter.");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/893a678d/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/LocationVectorsEvaluator.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/LocationVectorsEvaluator.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/LocationVectorsEvaluator.java
deleted file mode 100644
index 0c1ba99..0000000
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/LocationVectorsEvaluator.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * 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.client.solrj.io.eval;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.ArrayList;
-
-import org.apache.solr.client.solrj.io.Tuple;
-import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
-import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter;
-import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
-
-public class LocationVectorsEvaluator extends RecursiveObjectEvaluator implements ManyValueWorker {
- protected static final long serialVersionUID = 1L;
-
- private String field;
-
- public LocationVectorsEvaluator(StreamExpression expression, StreamFactory factory) throws IOException {
- super(expression, factory);
-
- List<StreamExpressionNamedParameter> namedParams = factory.getNamedOperands(expression);
-
- for (StreamExpressionNamedParameter namedParam : namedParams) {
- if(namedParam.getName().equals("field")) {
- this.field = namedParam.getParameter().toString();
- } else {
- throw new IOException("Unexpected named parameter:" + namedParam.getName());
- }
- }
-
- if(field == null) {
- throw new IOException("The named parameter \"field\" must be set for the locationVectors function.");
- }
- }
-
- @Override
- public Object doWork(Object... objects) throws IOException {
-
- if (objects.length == 1) {
- //Just docs
- if(!(objects[0] instanceof List)) {
- throw new IOException("The locationVectors function expects a list of Tuples as a parameter.");
- } else {
- List list = (List)objects[0];
- if(list.size() > 0) {
- Object o = list.get(0);
- if(!(o instanceof Tuple)) {
- throw new IOException("The locationVectors function expects a list of Tuples as a parameter.");
- }
- } else {
- throw new IOException("Empty list was passed as a parameter to termVectors function.");
- }
- }
-
- List<Tuple> tuples = (List<Tuple>) objects[0];
-
- double[][] locationVectors = new double[tuples.size()][2];
- List<String> features = new ArrayList();
- features.add("lat");
- features.add("long");
-
- List<String> rowLabels = new ArrayList();
-
- for(int i=0; i< tuples.size(); i++) {
- Tuple tuple = tuples.get(i);
- String value = tuple.getString(field);
- String[] latLong = null;
- if(value.contains(",")) {
- latLong = value.split(",");
- } else {
- latLong = value.split(" ");
- }
-
- locationVectors[i][0] = Double.parseDouble(latLong[0].trim());
- locationVectors[i][1] = Double.parseDouble(latLong[1].trim());
- if(tuple.get("id") != null) {
- rowLabels.add(tuple.get("id").toString());
- }
- }
-
- Matrix matrix = new Matrix(locationVectors);
- matrix.setColumnLabels(features);
- matrix.setRowLabels(rowLabels);
- return matrix;
- } else {
- throw new IOException("The termVectors function takes a single positional parameter.");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/893a678d/solr/solrj/src/test/org/apache/solr/client/solrj/io/TestLang.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/TestLang.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/TestLang.java
index ee8c1e1..12ff2e9 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/TestLang.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/TestLang.java
@@ -70,7 +70,7 @@ public class TestLang extends LuceneTestCase {
"mod", "ceil", "floor", "sin", "asin", "sinh", "cos", "acos", "cosh", "tan", "atan", "tanh", "round", "sqrt",
"cbrt", "coalesce", "uuid", "if", "convert", "valueAt", "memset", "fft", "ifft", "euclidean","manhattan",
"earthMovers", "canberra", "chebyshev", "ones", "zeros", "setValue", "getValue", "knnRegress", "gaussfit",
- "outliers", "stream", "getCache", "putCache", "listCache", "removeCache", "zscores", "locationVectors"};
+ "outliers", "stream", "getCache", "putCache", "listCache", "removeCache", "zscores", "latlonVectors"};
@Test
public void testLang() {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/893a678d/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java
index 4bcf50d..137add6 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java
@@ -312,7 +312,7 @@ public class MathExpressionTest extends SolrCloudTestCase {
}
@Test
- public void testLocationFunctions() throws Exception {
+ public void testLatlonFunctions() throws Exception {
UpdateRequest updateRequest = new UpdateRequest();
int i=0;
@@ -326,7 +326,7 @@ public class MathExpressionTest extends SolrCloudTestCase {
String expr = "let(echo=true," +
" a=search("+COLLECTIONORALIAS+", q=*:*, fl=\"id, loc_p, price_i\",rows=100, sort=\"price_i asc\"),"+
- " b=locationVectors(a, field=loc_p)," +
+ " b=latlonVectors(a, field=loc_p)," +
" c=distance(array(40.7128, 74.0060), array(45.7128, 74.0060), haversineMeters()))";