Debian Codegraph @

doc/source/reference/query_expanders/tsv.rst

raw
1 .. -*- rst -*-
2
3 QueryExpanderTSV
4 ================
5
6 Summary
7 -------
8
9 ``QueryExpanderTSV`` is a query expander plugin that reads synonyms
10 from TSV (Tab Separated Values) file. This plugin provides poor
11 feature than the embedded query expansion feature. For example, it
12 doesn't support word normalization. But it may be easy to use because
13 you can manage your synonyms by TSV file. You can edit your synonyms
14 by spreadsheet application such as Excel. With the embedded query
15 expansion feature, you manage your synonyms by Groonga's table.
16
17 Install
18 -------
19
20 You need to register ``query_expanders/tsv`` as a plugin before you
21 use ``QueryExpanderTSV``::
22
23 plugin_register query_expanders/tsv
24
25 Usage
26 -----
27
28 You just add ``--query_expander QueryExpanderTSV`` parameter to
29 ``select`` command::
30
31 select --query "QUERY" --query_expander QueryExpanderTSV
32
33 If ``QUERY`` has registered synonyms, they are expanded. For example,
34 there are the following synonyms.
35
36 +----------------------------+------------------------+----------------------+
37 | word | synonym 1 | synonym 2 |
38 +============================+========================+======================+
39 | groonga | groonga | Senna |
40 +----------------------------+------------------------+----------------------+
41 | mroonga | mroonga | groonga MySQL |
42 +----------------------------+------------------------+----------------------+
43
44 The table means that ``synonym 1`` and ``synonym 2`` are synonyms of
45 ``word``. For example, ``groonga`` and ``Senna`` are synonyms of
46 ``groonga``. And ``mroonga`` and ``groonga MySQL`` are synonyms of
47 ``mroonga``.
48
49 Here is an example of query expnasion that uses ``groonga`` as query::
50
51 select --query "groonga" --query_expander QueryExpanderTSV
52
53 The above command equals to the following command::
54
55 select --query "groonga OR Senna" --query_expander QueryExpanderTSV
56
57 Here is another example of query expnasion that uses ``mroonga
58 search`` as query::
59
60 select --query "mroonga search" --query_expander QueryExpanderTSV
61
62 The above command equals to the following command::
63
64 select --query "(mroonga OR (groonga MySQL)) search" --query_expander QueryExpanderTSV
65
66 It is important that registered words (``groonga`` and ``mroonga``)
67 are only expanded to synonyms and not registered words (``search``)
68 are not expanded. Query expansion isn't occurred
69 recursively. ``groonga`` is appeared in ``(mroonga OR (groonga
70 MySQL))`` as query expansion result but it isn't expanded.
71
72 Normally, you need to include ``word`` itself into synonyms. For
73 example, ``groonga`` and ``mroonga`` are included in synonyms of
74 themselves. If you want to ignore ``word`` itself, you don't include
75 ``word`` itself into synonyms. For example, if you want to use query
76 expansion as spelling correction, you should use the following
77 synonyms.
78
79 +----------------------------+------------------------+
80 | word | synonym |
81 +============================+========================+
82 | gronga | groonga |
83 +----------------------------+------------------------+
84
85 ``gronga`` in ``word`` has a typo. A ``o`` is missing. ``groonga`` in
86 ``synonym`` is the correct word.
87
88 Here is an example of using query expnasion as spelling correction::
89
90 select --query "gronga" --query_expander QueryExpanderTSV
91
92 The above command equals to the following command::
93
94 select --query "groonga" --query_expander QueryExpanderTSV
95
96 The former command has a typo in ``--query`` value but the latter
97 command doesn't have any typos.
98
99 TSV File
100 --------
101
102 Synonyms are defined in TSV format file. This section describes about
103 it.
104
105 Location
106 ^^^^^^^^
107
108 The file name should be ``synonyms.tsv`` and it is located at
109 configuration directory. For example, ``/etc/groonga/synonyms.tsv`` is
110 a TSV file location. The location is decided at build time.
111
112 You can change the location by environment variable
113 ``GRN_QUERY_EXPANDER_TSV_SYNONYMS_FILE`` at run time::
114
115 % env GRN_QUERY_EXPANDER_TSV_SYNONYMS_FILE=/tmp/synonyms.tsv groonga
116
117 With the above command, ``/tmp/synonyms.tsv`` file is used.
118
119 Format
120 ^^^^^^
121
122 You can define zero or more synonyms in a TSV file. You define a
123 ``word`` and ``synonyms`` pair by a line. ``word`` is expanded to
124 ``synonyms`` in ``--query`` value. ``Synonyms`` are combined by
125 ``OR``. For example, ``groonga`` and ``Senna`` synonyms are expanded
126 as ``groonga OR Senna``.
127
128 The first column is ``word`` and the rest columns are ``synonyms`` of
129 the ``word``. Here is a sample line for ``word`` is ``groonga`` and
130 ``synonyms`` are ``groonga`` and ``Senna``. ``(TAB)`` means a tab
131 character (``U+0009``)::
132
133 groonga(TAB)groonga(TAB)Senna
134
135 Comment line is supported. Lines that start with ``#`` are ignored.
136 Here is an example for comment line. ``groonga`` line is ignored as
137 comment line::
138
139 #groonga(TAB)groonga(TAB)Senna
140 mroonga(TAB)mroonga(TAB)groonga MySQL
141
142 Limitation
143 ----------
144
145 You need to restart groonga to reload your synonyms. TSV file is
146 loaded only at the plugin load time.
147
148 See also
149 --------
150
151 * :ref:`select-query-expander`