Wrong print sequence in files if spelling error

Created on 11 November 2024, 7 months ago

Problem/Motivation

In the UI, you first insert the main word and then its synonym(s): this produces row like this

jam, marmelade, preserve

All terms are equivalent.
In case of spelling error, you must insert first the correct word than one or more wrong terms, comma separated (see image). This generates a row like this:

voucher => vaucer,vaucher,vocher

But in Apache Solr documentation the terms must be in reverse order:

marmalade,mermelad,marmellade => marmelade

See Using synonyms in Solr for example.

Steps to reproduce

Install a full working Search API Solr server and index, with some field as rendered_html, title, body etc.
Install this module, than export the file created when cron runs in Solr cofiguration folder and reload the server.

Proposed resolution

The UI is correct, you must swap the order of main word token with its synonyms:

/src/Plugin/search_api_synonym/export/Solr.php >> Line 60 and 63

        $line = "{$synonyms}, {$word}";
        ...
        $line = "{$synonyms} => {$word}";
🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇮🇹Italy charly71

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @charly71
  • 🇮🇹Italy charly71

    I tried this patch and it works:

    diff --git a/modules/contrib/search_api_synonym/src/Plugin/search_api_synonym/export/Solr.php b/modules/contrib/search_api_synonym/src/Plugin/search_api_synonym/export/Solr.php
    index bf9ff4ed0..4b7a47279 100644
    --- a/modules/contrib/search_api_synonym/src/Plugin/search_api_synonym/export/Solr.php
    +++ b/modules/contrib/search_api_synonym/src/Plugin/search_api_synonym/export/Solr.php
    @@ -57,10 +57,10 @@ private function generateLine($word, $synonyms, $type) {
         switch ($type) {
           case 'synonym':
             // We force using of equivalent mappings for type = synonym.
    -        $line = "{$word}, {$synonyms}";
    +        $line = "{$synonyms}, {$word}";
             break;
           case 'spelling_error':
    -        $line = "{$word} => {$synonyms}";
    +        $line = "{$synonyms} => {$word}";
             break;
         }
         return $line;
  • 🇬🇧United Kingdom aaron.ferris

    Agreed with this, I don't think we need to change the synonym case but the spelling error does need a switch I believe.

  • Assigned to aaron.ferris
  • 🇬🇧United Kingdom aaron.ferris

    MR raised

    #
    # Synonyms file for Apache Solr generated by Search API Synonym.
    # See file https://www.drupal.org/project/search_api_synonym.
    #
    
    marmalade,mermelad,marmellade => marmelade
    search => replace
  • 🇧🇷Brazil brandonlira

    Hi @aaron, I tested this and it's working as expected.

    The export file correctly shows the spelling correction in the expected format:
    marmalade,mermelad,marmellade => marmelade

    Thanks for the fix, everything looks good!

Production build 0.71.5 2024