diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 2f3cc5f002c..a647d1fa417 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -207,6 +207,9 @@ Bug Fixes * SOLR-9141: Fix ClassCastException when using the /sql handler count() function with single-shard collections (Minoru Osuka via James Dyer) + +* SOLR-9165: Spellcheck does not return collations if "maxCollationTries" is used with "cursorMark". + (James Dyer) Optimizations ---------------------- diff --git a/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java b/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java index 528cdc33bf8..0738081aba6 100644 --- a/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java +++ b/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollator.java @@ -24,6 +24,7 @@ import java.util.List; import org.apache.lucene.analysis.Token; import org.apache.lucene.index.IndexReader; import org.apache.solr.common.params.CommonParams; +import org.apache.solr.common.params.CursorMarkParams; import org.apache.solr.common.params.DisMaxParams; import org.apache.solr.common.params.GroupParams; import org.apache.solr.common.params.ModifiableSolrParams; @@ -118,6 +119,8 @@ public class SpellCheckCollator { params.set(CommonParams.FL, "id"); // we'll sort by doc id to ensure no scoring is done. params.set(CommonParams.SORT, "_docid_ asc"); + // CursorMark does not like _docid_ sorting, and we don't need it. + params.remove(CursorMarkParams.CURSOR_MARK_PARAM); // If a dismax query, don't add unnecessary clauses for scoring params.remove(DisMaxParams.TIE); params.remove(DisMaxParams.PF); diff --git a/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java b/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java index 97111498928..a31a19d624b 100644 --- a/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java +++ b/solr/core/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java @@ -25,6 +25,7 @@ import org.apache.lucene.util.TestUtil; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.params.CommonParams; +import org.apache.solr.common.params.CursorMarkParams; import org.apache.solr.common.params.GroupParams; import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.SpellingParams; @@ -594,5 +595,34 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 { List collations = (List) collationList.getAll("collation"); assertTrue(collations.size() == 2); } + @Test + public void testWithCursorMark() throws Exception + { + SolrCore core = h.getCore(); + SearchComponent speller = core.getSearchComponent("spellcheck"); + assertTrue("speller is null and it shouldn't be", speller != null); + + ModifiableSolrParams params = new ModifiableSolrParams(); + params.add(SpellCheckComponent.COMPONENT_NAME, "true"); + params.add(SpellCheckComponent.SPELLCHECK_BUILD, "true"); + params.add(SpellCheckComponent.SPELLCHECK_COUNT, "10"); + params.add(SpellCheckComponent.SPELLCHECK_COLLATE, "true"); + params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATION_TRIES, "2"); + params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "1"); + params.add(CommonParams.Q, "lowerfilt:(+fauth)"); + params.add(CommonParams.SORT, "id asc"); + params.add(CursorMarkParams.CURSOR_MARK_PARAM, CursorMarkParams.CURSOR_MARK_START); + SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH"); + SolrQueryResponse rsp = new SolrQueryResponse(); + rsp.addResponseHeader(new SimpleOrderedMap()); + SolrQueryRequest req = new LocalSolrQueryRequest(core, params); + handler.handleRequest(req, rsp); + req.close(); + NamedList values = rsp.getValues(); + NamedList spellCheck = (NamedList) values.get("spellcheck"); + NamedList collationList = (NamedList) spellCheck.get("collations"); + List collations = (List) collationList.getAll("collation"); + assertTrue(collations.size() == 1); + } }