From ecb8ca2fef7cf799e4c3921f0a8f271f5afe3c83 Mon Sep 17 00:00:00 2001 From: Jason Gerlowski Date: Fri, 4 Sep 2020 10:45:31 -0400 Subject: [PATCH] SOLR-14821: {!terms} dVTFTL supports single-valued strings Prior to this commit the docValuesTermsFilterTopLevel method of the {!terms} query parser would return zero results when run against a single-valued String. This commit fixes this by wrapping the single-valued 'SortedDocValues' in a 'SortedSetDocValues' object. --- solr/CHANGES.txt | 3 +++ .../apache/solr/search/TermsQParserPlugin.java | 4 ++-- .../solr/search/TestTermsQParserPlugin.java | 18 +++++++++--------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index ffaf08bec84..363aad5a71a 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -217,6 +217,9 @@ Bug Fixes * SOLR-14714: Solr.cmd in windows loads the incorrect jetty module when using java>=9 (Endika Posadas via Erick Erickson) +* SOLR-14821: {!terms} docValuesTermsFilterTopLevel method now works with single-valued strings (Anatolii Siuniaev + via Jason Gerlowski) + Other Changes --------------------- diff --git a/solr/core/src/java/org/apache/solr/search/TermsQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/TermsQParserPlugin.java index 9a8a12ad564..3320655e58d 100644 --- a/solr/core/src/java/org/apache/solr/search/TermsQParserPlugin.java +++ b/solr/core/src/java/org/apache/solr/search/TermsQParserPlugin.java @@ -205,8 +205,8 @@ public class TermsQParserPlugin extends QParserPlugin { if (! matchesAtLeastOneTerm) { return null; } - - SortedSetDocValues segmentDocValues = context.reader().getSortedSetDocValues(fieldName); + + SortedSetDocValues segmentDocValues = DocValues.getSortedSet(context.reader(), fieldName); if (segmentDocValues == null) { return null; } diff --git a/solr/core/src/test/org/apache/solr/search/TestTermsQParserPlugin.java b/solr/core/src/test/org/apache/solr/search/TestTermsQParserPlugin.java index bd501e93dcd..39130ae92dd 100644 --- a/solr/core/src/test/org/apache/solr/search/TestTermsQParserPlugin.java +++ b/solr/core/src/test/org/apache/solr/search/TestTermsQParserPlugin.java @@ -28,14 +28,14 @@ public class TestTermsQParserPlugin extends SolrTestCaseJ4 { public static void beforeClass() throws Exception { initCore("solrconfig.xml", "schema.xml"); - assertU(adoc("id","1", "author_s", "Lev Grossman", "t_title", "The Magicians", "cat_s", "fantasy", "pubyear_i", "2009")); - assertU(adoc("id", "2", "author_s", "Robert Jordan", "t_title", "The Eye of the World", "cat_s", "fantasy", "cat_s", "childrens", "pubyear_i", "1990")); - assertU(adoc("id", "3", "author_s", "Robert Jordan", "t_title", "The Great Hunt", "cat_s", "fantasy", "cat_s", "childrens", "pubyear_i", "1990")); - assertU(adoc("id", "4", "author_s", "N.K. Jemisin", "t_title", "The Fifth Season", "cat_s", "fantasy", "pubyear_i", "2015")); + assertU(adoc("id","1", "author_s1", "Lev Grossman", "t_title", "The Magicians", "cat_s", "fantasy", "pubyear_i", "2009")); + assertU(adoc("id", "2", "author_s1", "Robert Jordan", "t_title", "The Eye of the World", "cat_s", "fantasy", "cat_s", "childrens", "pubyear_i", "1990")); + assertU(adoc("id", "3", "author_s1", "Robert Jordan", "t_title", "The Great Hunt", "cat_s", "fantasy", "cat_s", "childrens", "pubyear_i", "1990")); + assertU(adoc("id", "4", "author_s1", "N.K. Jemisin", "t_title", "The Fifth Season", "cat_s", "fantasy", "pubyear_i", "2015")); assertU(commit()); - assertU(adoc("id", "5", "author_s", "Ursula K. Le Guin", "t_title", "The Dispossessed", "cat_s", "scifi", "pubyear_i", "1974")); - assertU(adoc("id", "6", "author_s", "Ursula K. Le Guin", "t_title", "The Left Hand of Darkness", "cat_s", "scifi", "pubyear_i", "1969")); - assertU(adoc("id", "7", "author_s", "Isaac Asimov", "t_title", "Foundation", "cat_s", "scifi", "pubyear_i", "1951")); + assertU(adoc("id", "5", "author_s1", "Ursula K. Le Guin", "t_title", "The Dispossessed", "cat_s", "scifi", "pubyear_i", "1974")); + assertU(adoc("id", "6", "author_s1", "Ursula K. Le Guin", "t_title", "The Left Hand of Darkness", "cat_s", "scifi", "pubyear_i", "1969")); + assertU(adoc("id", "7", "author_s1", "Isaac Asimov", "t_title", "Foundation", "cat_s", "scifi", "pubyear_i", "1951")); assertU(commit()); } @@ -114,7 +114,7 @@ public class TestTermsQParserPlugin extends SolrTestCaseJ4 { for (TermsParams method : methods) { // Single-valued field, single term value ModifiableSolrParams params = new ModifiableSolrParams(); - params.add("q", method.buildQuery("author_s", "Robert Jordan")); + params.add("q", method.buildQuery("author_s1", "Robert Jordan")); params.add("sort", "id asc"); assertQ(req(params, "indent", "on"), "*[count(//doc)=2]", "//result/doc[1]/str[@name='id'][.='2']", @@ -123,7 +123,7 @@ public class TestTermsQParserPlugin extends SolrTestCaseJ4 { // Single-valued field, multiple term values params = new ModifiableSolrParams(); - params.add("q", method.buildQuery("author_s", "Robert Jordan,Isaac Asimov")); + params.add("q", method.buildQuery("author_s1", "Robert Jordan,Isaac Asimov")); params.add("sort", "id asc"); assertQ(req(params, "indent", "on"), "*[count(//doc)=3]", "//result/doc[1]/str[@name='id'][.='2']",