Synonyms

更新时间:
复制 MD 格式

Overview

In real-world search scenarios, queries often contain synonymous terms. For example, you may want users who search for Cantonese to also find information related to Yue Chinese. Similarly, a search for Apple phone should retrieve content that includes iPhone. In practice, many words can express the same meaning, but users rarely include all of them in a single query. By expanding queries to include synonyms, you can significantly improve recall rates. The synonym configuration feature expands query terms to include their synonyms and retrieves documents that contain any of the equivalent terms. Example: The word "sofa" has a synonym "couch". Without synonym configuration, a search for "sofa" does not retrieve documents that only contain "couch". With this feature enabled, the search also retrieves these documents.

Procedure

1. In the OpenSearch console, go to the left-side navigation pane. Under Retrieval Configuration, click Query Analysis Rule Configuration. Select the desired application name and type (online/offline), and then click Create.

2. In the Create Rule dialog box that appears, set the target application (engine type, application name, and application type), enter a rule name, select an index range, choose an industry type (such as E-commerce Enhanced), and specify a query rewrite strategy (such as AND). In the feature selection area, check synonym configuration and other required features (such as stop word, spelling correction, term weight, and entity recognition). Expand the synonym configuration panel, enable Template Usage (E-commerce General Synonym Model) and Dictionary Usage (built-in dictionary), select an intervention dictionary as needed, and then click OK to create the rule.

Note: If you do not set an intervention dictionary, the system uses its default synonym dictionary. If you encounter incorrect results in your specific use case, you can configure an intervention dictionary as described in the following section.

3. After you create the rule, test its effect:

In the query analysis list, find the synonym rule that you created (for example, test_tong) and click Search Test in its Actions column. On the Search Test page, set the query to default:'KFC', the config clause to start:0,hit:10,format:fulljson, and the qp parameter to the query analysis rule that you created (for example, test_tong). Then, click Search. At the bottom of the page, the actual query is displayed as (((default:'kfc') OR (default:'kendeji'))). This indicates that the synonym feature has automatically expanded "KFC" to "kfc" and "kendeji". To view the query analysis process for the query term KFC, check the Query Analysis Process dialog box. The analysis steps are performed in the following order: Spelling Correction (-), Normalization (kfc), Tokenization (kfc), Stop Word (-), Synonyms (kendeji kfc), and Category Prediction. The final rewritten query is (((default:'kfc') OR (default:'kendeji'))), which confirms that the synonym expansion has taken effect.

4. After confirming the rule works as expected, go to the query analysis page, switch to the Index Orientation view, find the target rule, and click the Set as Default button. This sets it as the default query analysis rule.

5. After you set a rule as the default, the interface updates as follows:

A [Default] tag appears before the rule name, for example, [Default]test_tong (synonym configuration).

Synonym intervention dictionaries

Synonyms can vary across different business scenarios. The built-in dictionary may lack certain synonyms or contain incorrect ones for your use case. To address this, OpenSearch provides an intervention feature that allows you to customize synonyms. You can create an intervention dictionary and associate it with a query analysis rule to control how synonyms are expanded. For more information about how to configure and use an intervention dictionary, click here.