File: suggest.rst

package info (click to toggle)
groonga 15.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 163,080 kB
  • sloc: ansic: 770,564; cpp: 48,925; ruby: 40,447; javascript: 10,250; yacc: 7,045; sh: 5,602; python: 2,821; makefile: 1,672
file content (271 lines) | stat: -rw-r--r-- 6,848 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
.. -*- rst -*-

.. groonga-command
.. database: suggest
.. $ groonga-suggest-create-dataset ${DB_PATH} query

``suggest``
===========

.. note::

   The suggest feature specification isn't stable. The
   specification may be changed.

Summary
-------

suggest - returns completion, correction and/or suggestion for a query.

The suggest command returns completion, correction and/or
suggestion for a specified query.

See :doc:`/reference/suggest/introduction` about completion,
correction and suggestion.

Syntax
------
::

 suggest types
         table
         column
         query
         [sortby=-_score]
         [output_columns=_key,_score]
         [offset=0]
         [limit=10]
         [frequency_threshold=100]
         [conditional_probability_threshold=0.2]
         [prefix_search=auto]

Usage
-----

Here are learned data for completion.

.. groonga-command
.. include:: ../../example/reference/commands/suggest-learn-completion.log
.. load --table event_query --each 'suggest_preparer(_id, type, item, sequence, time, pair_query)'
.. [
.. {"sequence": "1", "time": 1312950803.86057, "item": "e"},
.. {"sequence": "1", "time": 1312950803.96857, "item": "en"},
.. {"sequence": "1", "time": 1312950804.26057, "item": "eng"},
.. {"sequence": "1", "time": 1312950804.56057, "item": "engi"},
.. {"sequence": "1", "time": 1312950804.76057, "item": "engin"},
.. {"sequence": "1", "time": 1312950805.86057, "item": "engine", "type": "submit"}
.. ]

Here are learned data for correction.

.. groonga-command
.. include:: ../../example/reference/commands/suggest-learn-correction.log
.. load --table event_query --each 'suggest_preparer(_id, type, item, sequence, time, pair_query)'
.. [
.. {"sequence": "2", "time": 1312950803.86057, "item": "s"},
.. {"sequence": "2", "time": 1312950803.96857, "item": "sa"},
.. {"sequence": "2", "time": 1312950804.26057, "item": "sae"},
.. {"sequence": "2", "time": 1312950804.56057, "item": "saer"},
.. {"sequence": "2", "time": 1312950804.76057, "item": "saerc"},
.. {"sequence": "2", "time": 1312950805.76057, "item": "saerch", "type": "submit"},
.. {"sequence": "2", "time": 1312950809.76057, "item": "serch"},
.. {"sequence": "2", "time": 1312950810.86057, "item": "search", "type": "submit"}
.. ]

Here are learned data for suggestion.

.. groonga-command
.. include:: ../../example/reference/commands/suggest-learn-suggestion.log
.. load --table event_query --each 'suggest_preparer(_id, type, item, sequence, time, pair_query)'
.. [
.. {"sequence": "3", "time": 1312950803.86057, "item": "search engine", "type": "submit"},
.. {"sequence": "3", "time": 1312950808.86057, "item": "web search realtime", "type": "submit"}
.. ]

Here is a completion example.

.. groonga-command
.. include:: ../../example/reference/commands/suggest-completion.log
.. suggest --table item_query --column kana --types complete --frequency_threshold 1 --query en

Here is a correction example.

.. groonga-command
.. include:: ../../example/reference/commands/suggest-correction.log
.. suggest --table item_query --column kana --types correct --frequency_threshold 1 --query saerch

Here is a suggestion example.

.. groonga-command
.. include:: ../../example/reference/commands/suggest-suggestion.log
.. suggest --table item_query --column kana --types suggest --frequency_threshold 1 --query search

Here is a mixed example.

.. groonga-command
.. include:: ../../example/reference/commands/suggest-mixed.log
.. suggest --table item_query --column kana --types complete|correct|suggest --frequency_threshold 1 --query search

Parameters
----------

``types``
  Specifies what types are returned by the suggest
  command.

  Here are available types:

    ``complete``
      The suggest command does completion.

    ``correct``
      The suggest command does correction.

    ``suggest``
      The suggest command does suggestion.

  You can specify one or more types separated by ``|``.
  Here are examples:

    It returns correction::

      correct

    It returns correction and suggestion::

      correct|suggest

    It returns complete, correction and suggestion::

      complete|correct|suggest

``table``
  Specifies table name that has ``item_${DATA_SET_NAME}`` format.
  For example, ``item_query`` is a table name if you created
  dataset by the following command::

    groonga-suggest-create-dataset /tmp/db-path query

``column``
  Specifies a column name that has furigana in
  Katakana in ``table`` table.

``query``
  Specifies query for completion, correction and/or
  suggestion.

``sortby``
  Specifies sort key.

  Default:
    ``-_score``

``output_columns``
  Specifies output columns.

  Default:
    ``_key,_score``

``offset``
  Specifies returned records offset.

  Default:
    ``0``

``limit``
  Specifies number of returned records.

  Default:
    ``10``

``frequency_threshold``
  Specifies threshold for item frequency. Returned records must have
  ``_score`` that is greater than or equal to ``frequency_threshold``.

  Default:
    ``100``

``conditional_probability_threshold``

  Specifies threshold for conditional
  probability. Conditional probability is used for learned
  data. It is probability of query submission when ``query``
  is occurred. Returned records must have conditional
  probability that is greater than or equal to
  ``conditional_probability_threshold``.

  Default:
    ``0.2``

``prefix_search``
  Specifies whether optional prefix search is used or not
  in completion.

  Here are available values:

    ``yes``
      Prefix search is always used.

    ``no``
      Prefix search is never used.

    ``auto``
      Prefix search is used only when other search can't
      find any records.

  Default:
    ``auto``

``similar_search``
  Specifies whether optional similar search is used or not
  in correction.

  Here are available values:

    ``yes``
      Similar search is always used.

    ``no``
      Similar search is never used.

    ``auto``
      Similar search is used only when other search can't
      find any records.

  Default:
    ``auto``

Return value
------------

Here is a returned JSON format::

 {"type1": [["candidate1", score of candidate1],
            ["candidate2", score of candidate2],
            ...],
  "type2": [["candidate1", score of candidate1],
            ["candidate2", score of candidate2],
            ...],
  ...}

``type``

  A type specified by ``types``.

``candidate``

  A candidate for completion, correction or suggestion.

``score of candidate``

  A score of corresponding ``candidate``. It means that
  higher score candidate is more likely candidate for
  completion, correction or suggestion. Returned candidates
  are sorted by ``score of candidate`` descending by
  default.

See also
--------

* :doc:`/reference/suggest`
* :doc:`/reference/executables/groonga-suggest-create-dataset`