バージョンごとのドキュメント一覧

F.14. dict_xsyn — 類義語の全文検索用の辞書の例 #

<title>dict_xsyn &mdash; example synonym full-text search dictionary</title>

<filename>dict_xsyn</filename> (Extended Synonym Dictionary) is an example of an add-on dictionary template for full-text search. This dictionary type replaces words with groups of their synonyms, and so makes it possible to search for a word using any of its synonyms. dict_xsyn(拡張類義語辞書)は全文検索用の辞書テンプレートの追加例です。 この種類の辞書は、単語を類義語の集まりに置き換え、その類義語のいずれかを使用して単語を検索できるようにします。

F.14.1. 設定 #

<title>Configuration</title>

A <literal>dict_xsyn</literal> dictionary accepts the following options: dict_xsyn辞書は以下のオプションを受け付けます。

  • <literal>matchorig</literal> controls whether the original word is accepted by the dictionary. Default is <literal>true</literal>. matchorigは辞書で元の単語が受け付けられるか否かを制御します。 デフォルトはtrueです。

  • <literal>matchsynonyms</literal> controls whether the synonyms are accepted by the dictionary. Default is <literal>false</literal>. matchsynonymsは類義語が辞書で受け付けられるか否かを制御します。 デフォルトはfalseです。

  • <literal>keeporig</literal> controls whether the original word is included in the dictionary's output. Default is <literal>true</literal>. keeporigは元の単語が辞書出力に含められるか否かを制御します。 デフォルトはtrueです。

  • <literal>keepsynonyms</literal> controls whether the synonyms are included in the dictionary's output. Default is <literal>true</literal>. keepsynonymsは類義語が辞書出力に含められるか否かを制御します。 デフォルトはtrueです。

  • <literal>rules</literal> is the base name of the file containing the list of synonyms. This file must be stored in <filename>$SHAREDIR/tsearch_data/</filename> (where <literal>$SHAREDIR</literal> means the <productname>PostgreSQL</productname> installation's shared-data directory). Its name must end in <literal>.rules</literal> (which is not to be included in the <literal>rules</literal> parameter). rulesは、類義語リストを含むファイルのベース名です。 このファイルは$SHAREDIR/tsearch_data/$SHAREDIRPostgreSQLインストレーションの共有データ用ディレクトリを示します)に格納しなければなりません。 この名前は.rulesで終わらなければなりません(これはrulesパラメータには含まれません)。

The rules file has the following format: rulesファイルは以下の書式です。

  • Each line represents a group of synonyms for a single word, which is given first on the line. Synonyms are separated by whitespace, thus: 各行は、行の先頭で与えられる1つの単語に対する類義語の集まりを表します。 類義語は以下のように空白文字で区切られます。

    word syn1 syn2 syn3
    

  • The sharp (<literal>#</literal>) sign is a comment delimiter. It may appear at any position in a line. The rest of the line will be skipped. シャープ記号(#)はコメント区切り記号です。 行の任意の位置に記載することができます。 行の残りの部分は飛ばされます。

Look at <filename>xsyn_sample.rules</filename>, which is installed in <filename>$SHAREDIR/tsearch_data/</filename>, for an example. 例として$SHAREDIR/tsearch_data/にインストールされるxsyn_sample.rulesを参照してください。

F.14.2. 使用方法 #

<title>Usage</title>

Installing the <literal>dict_xsyn</literal> extension creates a text search template <literal>xsyn_template</literal> and a dictionary <literal>xsyn</literal> based on it, with default parameters. You can alter the parameters, for example dict_xsyn拡張機能をインストールすると、xsyn_templateテキスト検索テンプレートが作成され、それに基づき、デフォルトのパラメータを持ったxsyn辞書が作成されます。 例えば以下のように、パラメータを変更することができます。

mydb# ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=false);
ALTER TEXT SEARCH DICTIONARY

or create new dictionaries based on the template. またこのテンプレートに基づいた新しい辞書を作成することもできます。

To test the dictionary, you can try 辞書を試験するためには以下を試してください。

mydb=# SELECT ts_lexize('xsyn', 'word');
      ts_lexize
-----------------------
 {syn1,syn2,syn3}

mydb# ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=true);
ALTER TEXT SEARCH DICTIONARY

mydb=# SELECT ts_lexize('xsyn', 'word');
      ts_lexize
-----------------------
 {word,syn1,syn2,syn3}

mydb# ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=false, MATCHSYNONYMS=true);
ALTER TEXT SEARCH DICTIONARY

mydb=# SELECT ts_lexize('xsyn', 'syn1');
      ts_lexize
-----------------------
 {syn1,syn2,syn3}

mydb# ALTER TEXT SEARCH DICTIONARY xsyn (RULES='my_rules', KEEPORIG=true, MATCHORIG=false, KEEPSYNONYMS=false);
ALTER TEXT SEARCH DICTIONARY

mydb=# SELECT ts_lexize('xsyn', 'syn1');
      ts_lexize
-----------------------
 {word}

Real-world usage will involve including it in a text search configuration as described in <xref linkend="textsearch"/>. That might look like this: 現実世界で使用する場合は、第12章で説明されるテキスト検索設定内にこれを含むようになるでしょう。 以下のようになります。

ALTER TEXT SEARCH CONFIGURATION english
    ALTER MAPPING FOR word, asciiword WITH xsyn, english_stem;