You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sa...@apache.org on 2017/07/31 18:24:42 UTC

[2/3] lucene-solr:branch_7x: SOLR-10919: ord & rord functions give confusing errors with PointFields

SOLR-10919: ord & rord functions give confusing errors with PointFields


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

Branch: refs/heads/branch_7x
Commit: 5fd30f266297d0ce2694b8673b0856534eb44fe2
Parents: bbf5984
Author: Steve Rowe <sa...@apache.org>
Authored: Mon Jul 31 14:24:11 2017 -0400
Committer: Steve Rowe <sa...@apache.org>
Committed: Mon Jul 31 14:24:27 2017 -0400

----------------------------------------------------------------------
 solr/CHANGES.txt                                 |  2 ++
 .../solr/search/function/OrdFieldSource.java     |  5 +++++
 .../search/function/ReverseOrdFieldSource.java   |  5 +++++
 .../solr/search/function/TestFunctionQuery.java  | 19 +++++++++++++++++++
 4 files changed, 31 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5fd30f26/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 2232b55..98117dc 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -571,6 +571,8 @@ Other Changes
 
 * SOLR-11036: Separately report disk space metrics for solr.data.home and core root directory. (ab)
 
+* SOLR-10919: ord & rord functions give confusing errors with PointFields. (hossman, Steve Rowe)
+
 ==================  6.7.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5fd30f26/solr/core/src/java/org/apache/solr/search/function/OrdFieldSource.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/function/OrdFieldSource.java b/solr/core/src/java/org/apache/solr/search/function/OrdFieldSource.java
index 4637df6..7cd8142 100644
--- a/solr/core/src/java/org/apache/solr/search/function/OrdFieldSource.java
+++ b/solr/core/src/java/org/apache/solr/search/function/OrdFieldSource.java
@@ -33,6 +33,7 @@ import org.apache.lucene.queries.function.docvalues.IntDocValues;
 import org.apache.lucene.search.SortedSetSelector;
 import org.apache.lucene.util.mutable.MutableValue;
 import org.apache.lucene.util.mutable.MutableValueInt;
+import org.apache.solr.common.SolrException;
 import org.apache.solr.index.SlowCompositeReaderWrapper;
 import org.apache.solr.schema.SchemaField;
 import org.apache.solr.search.Insanity;
@@ -77,6 +78,10 @@ public class OrdFieldSource extends ValueSource {
     if (o instanceof SolrIndexSearcher) {
       SolrIndexSearcher is = (SolrIndexSearcher) o;
       SchemaField sf = is.getSchema().getFieldOrNull(field);
+      if (sf != null && sf.getType().isPointField()) {
+        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, 
+            "ord() is not supported over Points based field " + field);
+      }
       if (sf != null && sf.hasDocValues() == false && sf.multiValued() == false && sf.getType().getNumberType() != null) {
         // it's a single-valued numeric field: we must currently create insanity :(
         List<LeafReaderContext> leaves = is.getIndexReader().leaves();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5fd30f26/solr/core/src/java/org/apache/solr/search/function/ReverseOrdFieldSource.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/function/ReverseOrdFieldSource.java b/solr/core/src/java/org/apache/solr/search/function/ReverseOrdFieldSource.java
index f379913..0ada4d5 100644
--- a/solr/core/src/java/org/apache/solr/search/function/ReverseOrdFieldSource.java
+++ b/solr/core/src/java/org/apache/solr/search/function/ReverseOrdFieldSource.java
@@ -31,6 +31,7 @@ import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.IntDocValues;
 import org.apache.lucene.search.SortedSetSelector;
+import org.apache.solr.common.SolrException;
 import org.apache.solr.index.SlowCompositeReaderWrapper;
 import org.apache.solr.schema.SchemaField;
 import org.apache.solr.search.Insanity;
@@ -77,6 +78,10 @@ public class ReverseOrdFieldSource extends ValueSource {
     if (o instanceof SolrIndexSearcher) {
       SolrIndexSearcher is = (SolrIndexSearcher) o;
       SchemaField sf = is.getSchema().getFieldOrNull(field);
+      if (sf != null && sf.getType().isPointField()) {
+        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
+            "rord() is not supported over Points based field " + field);
+      }
       if (sf != null && sf.hasDocValues() == false && sf.multiValued() == false && sf.getType().getNumberType() != null) {
         // it's a single-valued numeric field: we must currently create insanity :(
         List<LeafReaderContext> leaves = is.getIndexReader().leaves();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5fd30f26/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java b/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java
index afc8a0d..8383a67 100644
--- a/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java
+++ b/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java
@@ -28,6 +28,7 @@ import java.util.Random;
 import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.search.similarities.TFIDFSimilarity;
 import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.SolrException;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -302,6 +303,24 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
     makeExternalFile(extField, "91=543210\n92=-8\n93=250\n=67");
     singleTest(extField,"\0",991,543210,992,-8,993,250);
   }
+  
+  @Test
+  public void testOrdAndRordOverPointsField() throws Exception {
+    assumeTrue("Skipping test when points=false", Boolean.getBoolean(NUMERIC_POINTS_SYSPROP));
+    clearIndex();
+
+    String field = "a_" + new String[] {"i","l","d","f"}[random().nextInt(4)];
+    assertU(adoc("id", "1", field, "1"));
+    assertU(commit());
+
+    Exception e = expectThrows(SolrException.class, () -> h.query(req("q", "{!func}ord(" + field + ")", "fq", "id:1")));
+    assertEquals(SolrException.ErrorCode.BAD_REQUEST.code, ((SolrException)e).code());
+    assertTrue(e.getMessage().contains("ord() is not supported over Points based field " + field));
+
+    e = expectThrows(SolrException.class, () -> h.query(req("q", "{!func}rord(" + field + ")", "fq", "id:1")));
+    assertEquals(SolrException.ErrorCode.BAD_REQUEST.code, ((SolrException)e).code());
+    assertTrue(e.getMessage().contains("rord() is not supported over Points based field " + field));
+  }
 
   @Test
   public void testGeneral() throws Exception {