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 rows 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 fields 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}";
CommentFileSizeAuthor
#9 img02.png14.2 KBbrandonlira
#9 img01.png33.32 KBbrandonlira
synonym_error.jpeg89.71 KBcharly71
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

charly71 created an issue. See original summary.

charly71’s picture

Issue summary: View changes
charly71’s picture

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;
aaron.ferris’s picture

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

aaron.ferris’s picture

Version: 2.0.0 » 3.0.x-dev
Assigned: Unassigned » aaron.ferris

aaron.ferris’s picture

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
aaron.ferris’s picture

Assigned: aaron.ferris » Unassigned
Status: Active » Needs review
brandonlira’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new33.32 KB
new14.2 KB

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!

aaron.ferris’s picture

Thanks @brandonlira!

aaron.ferris’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.