You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ep...@apache.org on 2024/03/04 21:57:08 UTC
(solr) branch branch_9x updated: SOLR-17197: Fix getting fieldType by its name in FileBasedSpellChecker (#2329)
This is an automated email from the ASF dual-hosted git repository.
epugh pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new 8d3fe8f1c17 SOLR-17197: Fix getting fieldType by its name in FileBasedSpellChecker (#2329)
8d3fe8f1c17 is described below
commit 8d3fe8f1c17bec933c16c5ac6b55b8f979edacd1
Author: Andrey Bozhko <an...@gmail.com>
AuthorDate: Mon Mar 4 15:54:41 2024 -0600
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 <ab...@apple.com>
Co-authored-by: Eric Pugh <ep...@opensourceconnections.com>
---
solr/CHANGES.txt | 2 ++
.../org/apache/solr/spelling/FileBasedSpellChecker.java | 6 +++---
.../solr/collection1/conf/schema-spellchecker.xml | 16 ++++++++++++++++
.../apache/solr/spelling/FileBasedSpellCheckerTest.java | 6 +++---
4 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 441512e1f63..8028f36517d 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -51,6 +51,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 @@ 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 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 @@
</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.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 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();