CREATE TEXT SEARCH DICTIONARY
Function
CREATE TEXT SEARCH DICTIONARY creates a full-text retrieval dictionary. A full-text search dictionary is used to identify and process particular words during full-text retrieval.
Dictionaries are created by using predefined templates (defined in the PG_TS_TEMPLATE system catalog). Five types of dictionaries can be created, Simple, Ispell, Synonym, Thesaurus, and Snowball. Each type of dictionaries is used to handle different tasks.
Precautions
- A user with the SYSADMIN permission can create a dictionary. Then, the user automatically becomes the owner of the dictionary.
- A dictionary cannot be created in pg_temp mode.
- After a dictionary is created or modified, any modification to the user-defined dictionary definition file will not affect the dictionary in the database. To make such modifications take effect in the dictionary in the database, run the ALTER statement to update the definition file of the dictionary.
- The TEMPLATE parameter in a dictionary cannot be modified.
- To specify a dictionary, specify both the dictionary definition file path (FILEPATH) and the file name (the parameter varies based on dictionary types).
- The name of a dictionary definition file can contain only lowercase letters, digits, and underscores (_).
- The predefined dictionary file is stored in the $GAUSSHOME/share/postgresql/tsearch_data directory.
Syntax
1 2 3 4 |
CREATE TEXT SEARCH DICTIONARY name ( TEMPLATE = template [, option = value [, ... ]] ); |
Parameter Description
Parameter |
Description |
Value Range |
---|---|---|
name |
Specifies the name (optionally schema-qualified) of the full-text search dictionary to be created. |
A string, which must comply with the naming convention. |
template |
Specifies a template name. |
Templates (Simple, Synonym, Thesaurus, Ispell, and Snowball) defined in the PG_TS_TEMPLATE system catalog |
option |
Specifies the parameter name of a specific option for a full-text search dictionary. Each type of dictionaries has a template containing their custom parameters. Parameters function in a way irrelevant to their setting sequence. |
For details, see Table 2. |
value |
Specifies a parameter value. If the value is not an identifier or a number, enclose it with single quotation marks (''). You can also enclose identifiers and numbers with single quotation marks. |
- |
option |
Name of the option |
Description |
|
---|---|---|---|
Parameters for a Simple dictionary |
STOPWORDS |
Specifies the name of a file listing stop words. The default file name extension is .stop. For example, if the value of STOPWORDS is french, the actual file name is french.stop. In the file, each line defines a stop word. Dictionaries will ignore blank lines and spaces in the file and convert stop-word phrases into lowercase. |
|
ACCEPT |
Specifies whether to accept a non-stop word as recognized. The default value is true. If ACCEPT=true is set for a Simple dictionary, no token will be passed to subsequent dictionaries. In this case, you are advised to place the Simple dictionary at the end of the dictionary list. If ACCEPT=false is set, you are advised to place the Simple dictionary before at least one dictionary in the list. |
||
FILEPATH |
Specifies the directory for storing the stop word file. The stop word file can be stored locally or on the OBS server. If the file is stored locally, the directory format is 'file://absolute_path'. If the file is stored on the OBS server, the directory format is 'obs://bucket/path accesskey=ak secretkey=sk region=region_name'. The directory must be enclosed in single quotation marks ('). The default value is the directory where predefined dictionary files are located. Both the FILEPATH and STOPWORDS parameters need to be specified. To create a dictionary using the stop word file on the OBS server, perform the following steps:
|
||
Parameters for a Synonym dictionary |
SYNONYM |
Specifies the name of the definition file for a Synonym dictionary. The default file name extension is .syn. The file is a list of synonyms. Each line is in the format of token synonym, that is, token and its synonym separated by a space. |
|
CASESENSITIVE |
Specifies whether tokens and their synonyms are case sensitive. The default value is false, indicating that tokens and synonyms in dictionary files will be converted into lowercase. If this parameter is set to true, they will not be converted into lowercase. |
||
FILEPATH |
Specifies the directory for storing Synonym dictionary files. The directory can be a local directory or an OBS directory. The default value is the directory where predefined dictionary files are located. The directory format and the process of creating a Synonym dictionary using a file on the OBS server are the same as those of the Simple dictionary. |
||
Parameters for a Thesaurus dictionary |
DICTFILE |
Specifies the name of a dictionary definition file. The default file name extension is .ths. The file is a list of synonyms. Each line is in the format of sample words : indexed words. The colon (:) is used as a separator between a phrase and its substitute word. If multiple sample words are matched, the TZ selects the longest one. |
|
DICTIONARY |
Specifies the name of a subdictionary used for word normalization. This parameter is mandatory and only one subdictionary name can be specified. The specified subdictionary must exist. It is used to identify and normalize input text before phrase matching. If an input word cannot be recognized by the subdictionary, an error will be reported. In this case, remove the word or update the subdictionary to make the word recognizable. In addition, an asterisk (*) can be placed at the beginning of an indexed word to skip the application of a subdictionary on it, but all sample words must be recognizable by the subdictionary.
If the sample words defined in the dictionary file contain stop words defined in the subdictionary, use question marks (?) to replace them. Assume that a and the are stop words defined in the subdictionary.
? one ? two : swsw a one the two and the one a two will be matched and output as swsw. |
||
FILEPATH |
Specifies the directory for storing dictionary definition files. The directory can be a local directory or an OBS directory. The default value is the directory where predefined dictionary files are located. The directory format and the process of creating a Synonym dictionary using a file on the OBS server are the same as those of the Simple dictionary. |
||
Parameters for an Ispell dictionary |
DICTFILE |
Specifies the name of a dictionary definition file. The default file name extension is .dict. |
|
AFFFILE |
Specifies the name of an affix file. The default file name extension is .affix. |
||
STOPWORDS |
Specifies the name of a file listing stop words. The default file name extension is .stop. The file content format is the same as that of the file for a Simple dictionary. |
||
FILEPATH |
Specifies the directory for storing dictionary files. The directory can be a local directory or an OBS directory. The default value is the directory where predefined dictionary files are located. The directory format and the process of creating a Synonym dictionary using a file on the OBS server are the same as those of the Simple dictionary. |
||
Parameters for a Snowball dictionary |
LANGUAGE |
Specifies the name of a language whose stemming algorithm will be used. According to spelling rules in the language, the algorithm normalizes the variants of an input word into a basic word or a stem. |
|
STOPWORDS |
Specifies the name of a file listing stop words. The default file name extension is .stop. The file content format is the same as that of the file for a Simple dictionary. |
||
FILEPATH |
Specifies the directory for storing dictionary definition files. The directory can be a local directory or an OBS directory. The default value is the directory where predefined dictionary files are located. Both the FILEPATH and STOPWORDS parameters need to be specified. The directory format and the process of creating a Snowball dictionary using a file on the OBS server are the same as those of the Simple dictionary. |
Examples
1 2 3 4 5 6 7 |
CREATE TEXT SEARCH DICTIONARY english_ispell ( TEMPLATE = ispell, DictFile = english, AffFile = english, StopWords = english, FilePath = 'obs://bucket_name/path accesskey=ak secretkey=sk region=rg' ); |
See examples in Configuration Examples.
Helpful Links
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot