Apache Solr open-source search software
SOLR-17197: Fix getting fieldType by its name in FileBasedSpellChecker (#2329)
Andrey Bozhkoc6f9e6238de9
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex e52b79e87a9..c2e872d2dbc 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -27,7 +27,6 @@ OptimizationsBug 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 tosimulate 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.javaindex 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 @@ public class FileBasedSpellChecker extends AbstractLuceneSpellChecker {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 analyzerDirectory 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.xmlindex 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 @@</analyzer></fieldType>+ <fieldType name="teststop_type" class="solr.TextField">+ <analyzer type="index">+ <tokenizer class="solr.LetterTokenizerFactory"/>+ <filter class="solr.LowerCaseFilterFactory"/>+ <filter class="solr.StopFilterFactory" words="stopwords.txt"/>+ </analyzer>+ <analyzer type="query">+ <tokenizer class="solr.LetterTokenizerFactory"/>+ <filter class="solr.LowerCaseFilterFactory"/>+ </analyzer>+ </fieldType>++ <fieldType name="long" class="solr.LongPointField"/>+<field name="id" type="string" indexed="true" stored="true"/><field name="spell" type="spellText" indexed="true" stored="true"/><field name="suggest" type="spellText" indexed="true" stored="true"/>+ <field name="teststop" type="teststop_type" indexed="true" stored="true"/><field name="text" type="text" indexed="true" stored="false" multiValued="true"/>+ <field name="_version_" type="long" indexed="false" stored="false" docValues="true"/><copyField source="text" dest="spell"/><copyField source="text" dest="suggest"/>diff --git a/solr/core/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.java b/solr/core/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.javaindex 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 {@BeforeClasspublic static void beforeClass() throws Exception {- initCore("solrconfig.xml", "schema.xml");+ initCore("solrconfig.xml", "schema-spellchecker.xml");// Index something with a titleassertNull(h.validateUpdate(adoc("id", "0", "teststop", "This is a title")));assertNull(@@ -120,7 +120,7 @@ public class FileBasedSpellCheckerTest extends SolrTestCaseJ4 {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 class FileBasedSpellCheckerTest extends SolrTestCaseJ4 {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();