Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

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

Steve Rowe88614dd15f80
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 2c4e436c896..ed4d1e467fd 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -588,6 +588,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.
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 4637df64517..7cd81426c11 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();
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 f379913184b..0ada4d5aba1 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();
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 afc8a0dc5a0..8383a673b8c 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 {