
Tip
|
Since 2.1.5 & 2.2.1 SearchServices |
Synonym functionality offered by search providers allows you to define equivalent words or phrases to improve search recall and user experience. This helps improve the relevance of search results by ensuring that a search query for one term, such as "TV," also returns documents that contain its synonym, "television". The feature is configured using a filter in a Solr schema’s field type. You can view and manage Solr Search Synonyms in the BLC Admin with some configuration on both the application and supporting artifacts.
For configuration properties, please see Property Configuration for Stopwords, Synonyms, and Spellchecks
Tip
|
Although these steps show the managed synonyms working with our Heat Clinic demo data, you can follow these steps and adjust for your own data and Solr configuration. |
With the following properties, you can enable synonyms and create a new data record to hold your synonyms in Solr.
broadleaf:
search:
feature:
synonym:
enabled: true
config:
- aliases:
- "catalog_alias_1"
- "catalog_alias_2"
synonym-file: "synonyms.txt" # path to a synonyms.txt if you have one
language: en # Language should match a managed language defined below.
managed-languages:
- label: English (Product Description) # Label shown in admin when managing synonyms
language: en # Matches a managed language name in Solr Schema
indexable-types:
- PRODUCT
Update catalog’s schema.xml to add the following to any analyzer with an existing solr.SynonymGraphFilterFactory
filter: <filter class="solr.ManagedSynonymGraphFilterFactory" managed="en"/>
Tip
|
Even though they can work together, Solr best practice recommendation is to define your synonyms either via the static (file based) OR the dynamic (managed) solution, but not both at the same time. |
Using heat clinic demo data, we’ll add a new synonym. First, go to the heat clinic storefront and verify that searching for "lime" has no results.
Go back to the synonyms view for the managed language in the admin and add a new synonym for lime to green. This only works one way, where "Word" field is the query term you search for, and "Synonyms" look to match against indexed results. So in this case, "Word"="lime" and "Synonyms"="green".
Navigate to storefront and search for "lime". You’ll now see the "Green Ghost" product in the results.
Managed synonyms can be found in Solr admin, i.e. http://localhost:8983/solr/#/catalog_alias_1/files?file=_schema_analysis_synonyms_en.json
Locally, if you restart your Solr docker container, you will lose any synonyms that were added via the admin
You’ll want to configure your deployed environments such that this configuration is persisted in Solr (or Zookeeper) across restarts.
If you get a 403 error on microservices flex package start up when connecting to Solr with the above properties set, make sure that Solr security.json (i.e. in the Solr docker image var/keys/solr-security.json) contains an entry for "schema-edit" that includes roles "indexer" and "admin"