From c6f9e6238de9f578a5781dd8f2843bf51dea5f52 Mon Sep 17 00:00:00 2001 From: Andrey Bozhko Date: Mon, 4 Mar 2024 15:54:41 -0600 Subject: [PATCH] SOLR-17197: Fix getting fieldType by its name in FileBasedSpellChecker (#2329) * fix getting fieldType by its name in FileBasedSpellChecker * add _version_ field because solrconfig has updateLog enabled --------- Co-authored-by: Andrey Bozhko Co-authored-by: Eric Pugh --- solr/CHANGES.txt | 5 +++-- .../solr/spelling/FileBasedSpellChecker.java | 6 +++--- .../collection1/conf/schema-spellchecker.xml | 16 ++++++++++++++++ .../solr/spelling/FileBasedSpellCheckerTest.java | 6 +++--- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index e52b79e87a9..c2e872d2dbc 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -27,7 +27,6 @@ Optimizations Bug Fixes --------------------- -(No changes) Deprecation Removals ---------------------- @@ -106,7 +105,7 @@ Improvements * SOLR-17145: The INSTALLSHARDDATA API now includes a 'requestid' field when run asynchronously (Jason Gerlowski) -* SOLR-17159: bin/solr post now has proper unit testing. Users can specify a --dry-run option to +* SOLR-17159: bin/solr post now has proper unit testing. Users can specify a --dry-run option to simulate posting documents without sending them to Solr. (Eric Pugh) * SOLR-17058: Add 'distrib.statsCache' parameter to disable distributed stats requests at query time. (Wei Wang, Mikhail Khludnev) @@ -131,6 +130,8 @@ Bug Fixes * SOLR-17186: Streaming query breaks if token contains backtick (Rahul Goswami via Eric Pugh) +* SOLR-17197: Fix getting fieldType by its name in FileBasedSpellChecker (Andrey Bozhko via Eric Pugh) + Dependency Upgrades --------------------- (No changes) diff --git a/solr/core/src/java/org/apache/solr/spelling/FileBasedSpellChecker.java b/solr/core/src/java/org/apache/solr/spelling/FileBasedSpellChecker.java index 26d127d675d..2300f0a8dca 100644 --- a/solr/core/src/java/org/apache/solr/spelling/FileBasedSpellChecker.java +++ b/solr/core/src/java/org/apache/solr/spelling/FileBasedSpellChecker.java @@ -81,9 +81,9 @@ protected IndexReader determineReader(IndexReader reader) { private void loadExternalFileDictionary(SolrCore core, SolrIndexSearcher searcher) { try { IndexSchema schema = null == searcher ? core.getLatestSchema() : searcher.getSchema(); - // Get the field's analyzer - if (fieldTypeName != null && schema.getFieldTypeNoEx(fieldTypeName) != null) { - FieldType fieldType = schema.getFieldTypes().get(fieldTypeName); + // Get the fieldType's analyzer + if (fieldTypeName != null && schema.getFieldTypeByName(fieldTypeName) != null) { + FieldType fieldType = schema.getFieldTypeByName(fieldTypeName); // Do index-time analysis using the given fieldType's analyzer Directory ramDir = new ByteBuffersDirectory(); diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-spellchecker.xml b/solr/core/src/test-files/solr/collection1/conf/schema-spellchecker.xml index d5286ab72f9..8026721b089 100644 --- a/solr/core/src/test-files/solr/collection1/conf/schema-spellchecker.xml +++ b/solr/core/src/test-files/solr/collection1/conf/schema-spellchecker.xml @@ -49,10 +49,26 @@ + + + + + + + + + + + + + + + + diff --git a/solr/core/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.java b/solr/core/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.java index 3f6c5381150..c4d33b77912 100644 --- a/solr/core/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.java +++ b/solr/core/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.java @@ -40,7 +40,7 @@ public class FileBasedSpellCheckerTest extends SolrTestCaseJ4 { @BeforeClass public static void beforeClass() throws Exception { - initCore("solrconfig.xml", "schema.xml"); + initCore("solrconfig.xml", "schema-spellchecker.xml"); // Index something with a title assertNull(h.validateUpdate(adoc("id", "0", "teststop", "This is a title"))); assertNull( @@ -120,7 +120,7 @@ public void testFieldType() throws Exception { File indexDir = createTempDir().toFile(); indexDir.mkdirs(); spellchecker.add(AbstractLuceneSpellChecker.INDEX_DIR, indexDir.getAbsolutePath()); - spellchecker.add(SolrSpellChecker.FIELD_TYPE, "teststop"); + spellchecker.add(SolrSpellChecker.FIELD_TYPE, "teststop_type"); SolrCore core = h.getCore(); String dictName = checker.init(spellchecker, core); assertEquals(dictName + " is not equal to " + "external", "external", dictName); @@ -168,7 +168,7 @@ public void testRAMDirectory() throws Exception { spellchecker.add(AbstractLuceneSpellChecker.LOCATION, "spellings.txt"); spellchecker.add(FileBasedSpellChecker.SOURCE_FILE_CHAR_ENCODING, "UTF-8"); spellchecker.add(AbstractLuceneSpellChecker.FIELD, "teststop"); - spellchecker.add(SolrSpellChecker.FIELD_TYPE, "teststop"); + spellchecker.add(SolrSpellChecker.FIELD_TYPE, "teststop_type"); spellchecker.add(AbstractLuceneSpellChecker.SPELLCHECKER_ARG_NAME, spellchecker); SolrCore core = h.getCore();