Overview
Expressions that contain synonyms are common in real-world search scenarios. The following Chinese examples use romanizations or English glosses for readability. For example, when users search for Guangdonghua (a Chinese name for Cantonese), you may want them to also find information related to Yueyu (another Chinese name for Cantonese). When users search for Apple phone (the English gloss of a Chinese phrase), you may want content that contains iPhone to also be retrieved and displayed. In daily life, the same meaning can often be expressed by many different words, but users can rarely include all of them in a single query. Therefore, recognizing synonyms and providing synonym-based retrieval can clearly achieve a higher recall rate. The synonym feature expands query terms with their synonyms to recall more documents that are synonymous with the query terms. Example: baocai has the synonym yuanbaicai (both are common Chinese names for cabbage). If the synonym feature is disabled, a search for baocai cannot recall documents that contain only yuanbaicai. If the synonym feature is enabled, these documents can be recalled.
Procedure
1. Log on to the OpenSearch console. In the left-side navigation pane, choose Retrieval Configuration > Query Analysis Configuration. Select the application name and application type (online or offline), and click Create.
2. Enter a rule name, select an index scope, select an industry type, select Synonyms as a feature, and click OK. Specifically, in the Edit Rule dialog box that appears, configure the Target Application (engine type, application name, and application type), Rule Name, Index Scope, Industry Type (such as E-commerce Enhanced), and Query Rewrite Policy (such as AND). In the feature selection area, select Synonyms and any other features you need (such as stop words, spelling correction, term weight, and named entity recognition). Expand the synonym configuration panel, enable Use Template (the general-purpose e-commerce synonym model) and Use Dictionary (the built-in system dictionary), select an Intervention Dictionary as needed, and click OK to complete the creation.
Note: If no intervention dictionary is specified, the default system synonym dictionary is used. If bad cases occur in your actual scenarios, you can configure an intervention dictionary as described below.
3. After the rule is created, you can test the search results:
In the query analysis list, find the synonym rule that you created (such as test_tong) and click Search Test in the Actions column. Test results: On the search test page, set the query statement to default:'KFC', set the config clause to start:0,hit:10,format:fulljson, set the qp parameter to the query analysis rule that you created (such as test_tong), and click Search. The actual query shown at the bottom of the page is represented here as a JSON string (decode the Unicode escapes to obtain the original Chinese text): "(((default:'kfc') OR (default:'\u80af\u5fb7\u57fa')))", which indicates that the synonym feature automatically expanded "KFC" to "kfc" and the Chinese name for KFC. View the query analysis process: Take the query term KFC as an example. In the query analysis process dialog box, the analysis steps are, in sequence, spelling correction (-), normalization (kfc), tokenization (kfc), stop words (-), synonyms (the Chinese name for KFC and kfc), and category prediction. The final query rewrite result, in the same JSON string notation, is "(((default:'kfc') OR (default:'\u80af\u5fb7\u57fa')))", which verifies that the synonym expansion has taken effect.
4. After debugging is complete, go to the query analysis page, switch to the Index View, and set the custom query analysis rule as the default query analysis rule. To do this, find the target rule in the Index View and click the Set as Default button.
5. The page after the custom query analysis rule is set as the default:
After the setting is complete, the [Default] label is displayed in front of the name of the custom query analysis rule that is set as the default, for example, [Default]test_tong (synonyms).
Synonym intervention dictionaries
Synonyms of certain words may vary across business scenarios, and the built-in system dictionary may lack some synonyms or provide incorrect ones. Therefore, an intervention feature is provided to allow you to define custom synonyms. You can intervene in the synonym feature by creating a synonym intervention dictionary and specifying it in the synonym configuration of a query analysis rule. For details about the configuration and principles of synonym intervention dictionaries, click here.