Skip to content

Commit

Permalink
SOLR-17197: Fix getting fieldType by its name in FileBasedSpellChecker (
Browse files Browse the repository at this point in the history
apache#2329)

* fix getting fieldType by its name in FileBasedSpellChecker
* add _version_ field because solrconfig has updateLog enabled

---------

Co-authored-by: Andrey Bozhko <[email protected]>
Co-authored-by: Eric Pugh <[email protected]>
  • Loading branch information
3 people authored Mar 4, 2024
1 parent 602ba18 commit c6f9e62
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
5 changes: 3 additions & 2 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Optimizations

Bug Fixes
---------------------
(No changes)

Deprecation Removals
----------------------
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit c6f9e62

Please sign in to comment.