Debian Codegraph @

doc/source/reference/executables/groonga-suggest-httpd.rst

raw
1 .. -*- rst -*-
2
3 .. program:: groonga-suggest-httpd
4
5 .. groonga-command
6 .. database: groonga-suggest-httpd
7 .. $ killall lt-groonga-suggest-learner || :
8 .. $ killall groonga-suggest-learner || :
9 .. $ killall lt-groonga-suggest-httpd || :
10 .. $ killall groonga-suggest-httpd || :
11
12 ``groonga-suggest-httpd``
13 =========================
14
15 Summary
16 -------
17
18 ``groonga-suggest-httpd`` is a program that provides HTTP interface
19 for the following features:
20
21 * Returning :doc:`/reference/suggest` execution result
22 * Saving logs for learning
23
24 ``groonga-suggest-httpd`` provides suggest feature like
25 :doc:`/reference/commands/suggest` command. Note that some parameter
26 names are different of them.
27
28 Syntax
29 ------
30
31 ``groonga-suggest-httpd`` requires database path::
32
33 groonga-suggest-httpd [options] DATABASE_PATH
34
35 Usage
36 -----
37
38 You need to create one or more datasets to use
39 ``groonga-suggest-httpd``. A dataset consists of tables and
40 columns. You can define them by :doc:`groonga-suggest-create-dataset`.
41
42 You need to use :doc:`groonga-suggest-learner` to learn suggestion
43 data from user inputs. You doesn't need to use
44 :doc:`groonga-suggest-learner` when you create suggestion data by
45 hand. See :doc:`/reference/suggest` and sub documents about creating
46 suggestion data by hand.
47
48 You can use ``groonga-suggest-httpd`` via HTTP after you create one or
49 more datasets.
50
51 The following sections describes the followings:
52
53 * How to set up a dataset
54 * How to use ``groonga-suggest-httpd`` with :doc:`groonga-suggest-learner`
55 * How to use ``groonga-suggest-httpd`` for retrieving suggestions.
56
57 Setup
58 ^^^^^
59
60 You need to create a dataset by :doc:`groonga-suggest-create-dataset`.
61
62 Here is an example that creates ``query`` dataset:
63
64 .. groonga-command
65 .. include:: ../../example/reference/executables/groonga-suggest-httpd/setup.log
66 .. % groonga-suggest-create-dataset ${DB_PATH} query
67
68 :doc:`groonga-suggest-create-dataset` outputs executed commands. You
69 can confirm that what tables and columns are created for the new
70 dataset.
71
72 Launch ``groonga-suggest-learner``
73 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
74
75 You can choose whether you use learned suggestion data immediately or
76 not.
77
78 There are two ways to use learned suggestion data immediately:
79
80 * Both of ``groonga-suggest-httpd`` and
81 :doc:`groonga-suggest-learner` use the same database
82 * ``groonga-suggest-httpd`` receives learned suggestion data from
83 :doc:`groonga-suggest-learner`
84
85 In the former case, you must run both ``groonga-suggest-httpd`` and
86 :doc:`groonga-suggest-learner` on the same host.
87
88 In the latter case, you can run ``groonga-suggest-httpd`` and
89 :doc:`groonga-suggest-learner` on different hosts.
90
91 If you don't need to use learned suggestion data immediately, you need
92 to apply learned suggestion data from database that is used by
93 :doc:`groonga-suggest-learner` to database that is used by
94 ``groonga-suggest-httpd`` by hand. Normally, this usage is
95 recommended. Because learned suggestion data may have garbage data by
96 inputs from evil users.
97
98 In this document, learned suggestion data are used immediately by
99 receiving learned suggestion data from
100 :doc:`groonga-suggest-learner`. Both ``groonga-suggest-httpd`` and
101 :doc:`groonga-suggest-learner` are running on the same host. Because
102 it's easy to explain.
103
104 Here is an example that launches :doc:`groonga-suggest-learner`. You
105 need to specify database that has ``query`` dataset. This document
106 omits the instruction for creating ``query`` dataset:
107
108 .. groonga-command
109 .. database: groonga-suggest-httpd-learner
110 .. % groonga-suggest-create-dataset ${DB_PATH} query
111
112 .. groonga-command
113 .. include:: ../../example/reference/executables/groonga-suggest-httpd/launch-lerner.log
114 .. % groonga-suggest-learner --daemon ${DB_PATH}
115
116 The ``groonga-suggest-learner`` process opens two endpoints at
117 ``1234`` port and ``1235`` port:
118
119 * ``1234`` port: Endpoint that accepts user input data from
120 ``groonga-suggest-httpd``
121 * ``1235`` port: Endpoint that sends learned suggestion data to
122 ``groonga-suggest-httpd``
123
124 Launch ``groonga-suggest-httpd``
125 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
126
127 You need to launch ``groonga-suggest-httpd`` for the following proposes:
128
129 * Learning suggestion data from user inputs
130 * Providing suggestion result to clients
131
132 Here is an example that launches ``groonga-suggest-httpd`` that
133 communicates :doc:`groonga-suggest-learner`:
134
135 .. groonga-command
136 .. database: groonga-suggest-httpd
137
138 .. groonga-command
139 .. include:: ../../example/reference/executables/groonga-suggest-httpd/launch.log
140 .. % groonga-suggest-httpd --send-endpoint 'tcp://127.0.0.1:1234' --receive-endpoint 'tcp://127.0.0.1:1235' --daemon ${DB_PATH}
141
142 The ``groonga-suggest-httpd`` process accepts HTTP requests on
143 ``8080`` port.
144
145 If you want to save requests into log file, use
146 :option:`--log-base-path` option.
147
148 Here is an example to save log files under ``logs`` directory with
149 ``log`` prefix for each file::
150
151 % groonga-suggest-httpd --log-base-path logs/log ${DB_PATH}
152
153 ``groonga-suggest-httpd`` creates log files such as
154 ``logYYYYmmddHHMMSS-00`` under ``logs`` directory.
155
156 Learn from user inputs
157 ^^^^^^^^^^^^^^^^^^^^^^
158
159 You can learn suggestion data from user inputs.
160
161 You need to specify the following parameters to learn suggestion data:
162
163 * ``i``: The ID of the user (You may use IP address of client)
164 * ``l``: The dataset name
165 * ``s``: The timestamp of the input in seconds
166 * ``t``: The query type (It's optional. You must specify ``submit`` only when the user input is submitted.)
167 * ``q``: The user input
168
169 Here are example requests to learn user input "Groonga" in ``query``
170 dataset::
171
172 .. groonga-command
173 .. include:: ../../example/reference/executables/groonga-suggest-httpd/learn.log
174 .. % curl 'http://localhost:8080/?i=127.0.0.1&l=query&s=92619&q=G'
175 .. % curl 'http://localhost:8080/?i=127.0.0.1&l=query&s=93850&q=Gr'
176 .. % curl 'http://localhost:8080/?i=127.0.0.1&l=query&s=94293&q=Gro'
177 .. % curl 'http://localhost:8080/?i=127.0.0.1&l=query&s=94734&q=Groo'
178 .. % curl 'http://localhost:8080/?i=127.0.0.1&l=query&s=95147&q=Grooon'
179 .. % curl 'http://localhost:8080/?i=127.0.0.1&l=query&s=95553&q=Groonga'
180 .. % curl 'http://localhost:8080/?i=127.0.0.1&l=query&s=95959&t=submit&q=Groonga'
181
182 Inputting data must not use ``t=submit`` parameter. In the above example, you just learn user inputs but you can learn and get complete candidates at once. It's described at the next section.
183
184 Submitted data must use ``t=submit`` parameter.
185
186 Use suggested response
187 ^^^^^^^^^^^^^^^^^^^^^^
188
189 You can get suggested result from ``groonga-suggest-httpd``.
190
191 You need to specify the following parameters to get suggested result:
192
193 * ``n``: The dataset name
194 * ``t``: The query type (``complete``, ``correct`` and/or ``suggest``)
195 * ``q``: The user input
196
197 You can also specify parameters for :doc:`/reference/commands/suggest` as option.
198
199 Here is an example that gets :doc:`/reference/suggest/completion` result. The result is computed by using learned data at the previous section. ``frequency_threshold=1`` parameter is used because this is an example. The parameter enables input data that are occurred one or more times. Normally, you should not use the parameter for production. The parameter will increase noises:
200
201 .. groonga-command
202 .. include:: ../../example/reference/executables/groonga-suggest-httpd/complete.log
203 .. % curl 'http://localhost:8080/?n=query&t=complete&q=G&frequency_threshold=1'
204
205 You can combine completion and learning by specifying parameters for both:
206
207 .. groonga-command
208 .. include:: ../../example/reference/executables/groonga-suggest-httpd/learn-and-complete.log
209 .. % curl 'http://localhost:8080/?i=127.0.0.1&l=query&s=96000&q=G&n=query&t=complete&frequency_threshold=1'
210
211 Command line parameters
212 -----------------------
213
214 Required parameters
215 ^^^^^^^^^^^^^^^^^^^
216
217 There is only one required parameter.
218
219 ``DATABASE_PATH``
220 """""""""""""""""
221
222 Specifies the path to a Groonga database. This database must have one
223 or more datasets. Each dataset must be created by
224 :doc:`groonga-suggest-create-dataset`.
225
226 Optional parameters
227 ^^^^^^^^^^^^^^^^^^^
228
229 .. option:: -p, --port
230
231 Specify HTTP server port number.
232
233 The default port number is ``8080``.
234
235 .. option:: -t, --n-threads
236
237 Specify number of threads.
238
239 This option accepts ``128`` as the max value, but use the number of
240 CPU cores for performance.
241
242 The default value is the number of CPU cores.
243
244 .. option:: -s, --send-endpoint
245
246 Specify endpoint URI of :doc:`groonga-suggest-learner` for sending
247 user inputs.
248
249 The format is ``tcp://${HOST}:${PORT}`` such as
250 ``tcp://192.168.0.1:2929``.
251
252 The default value is none.
253
254 .. option:: -r, --receive-endpoint
255
256 Specify endpoint URI of :doc:`groonga-suggest-learner` for
257 receiving learned suggestion data.
258
259 The format is ``tcp://${HOST}:${PORT}`` such as
260 ``tcp://192.168.0.1:2929``.
261
262 The default value is none.
263
264 .. option:: -l, --log-base-path
265
266 Specify path prefix of log.
267
268 The default value is none.
269
270 .. option:: --n-lines-per-log-file
271
272 Specify the max number of lines in a log file.
273
274 The default value is ``1000000``.
275
276 .. option:: -d, --daemon
277
278 Specify this option to daemonize.
279
280 Don't daemonize by default.
281
282 .. option:: --disable-max-fd-check
283
284 Specify this option to disable checking the max number of file
285 descriptors on start.
286
287 Check by default.
288
289 GET parameters
290 --------------
291
292 ``groonga-suggest-httpd`` accepts some GET parameters.
293
294 There are required parameters which depend on query type.
295
296 In ``complete``, ``correct`` or ``suggest`` query type, unhandled
297 parameters are passed through :doc:`/reference/commands/suggest`. It
298 means that you can use parameters of
299 :doc:`/reference/commands/suggest`.
300
301 .. _groonga-suggest-httpd-required-parameters:
302
303 Required parameters
304 ^^^^^^^^^^^^^^^^^^^
305
306 You must specify the following parameters.
307
308 .. list-table::
309 :header-rows: 1
310
311 * - Key
312 - Description
313 - Note
314 * - ``q``
315 - Input by user. It must be UTF-8 encoded string.
316 -
317
318 .. _groonga-suggest-httpd-required-parameters-learning:
319
320 Required parameters for learning
321 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
322
323 You must specify the following parameters when you specify
324 :option:`--send-endpoint`.
325
326 .. list-table::
327 :header-rows: 1
328
329 * - Key
330 - Description
331 - Note
332 * - ``s``
333 - Elapsed time since ``1970-01-01T00:00:00Z``.
334 - The unit is millisecond.
335 * - ``i``
336 - Unique ID to distinct each user
337 - Session ID, IP address and so on will be usable
338 for this value.
339 * - ``l``
340 - One or more learn target dataset names. You need to use ``|``
341 as separator such as ``dataset1|dataset2|dataset3``.
342 - Dataset name is the name that you specify to
343 :doc:`groonga-suggest-create-dataset`.
344
345 .. _groonga-suggest-httpd-required-parameters-suggestion:
346
347 Required parameters for suggestion
348 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
349
350 You must specify the following parameters when you specify one of
351 ``complete``, ``correct`` and ``suggest`` to ``t`` parameter.
352
353 .. list-table::
354 :header-rows: 1
355
356 * - Key
357 - Description
358 - Note
359 * - ``n``
360 - The dataset name to use computing suggestion result.
361 - Dataset name is the name that you specify to
362 :doc:`groonga-suggest-create-dataset`.
363 * - ``t``
364 - The query type.
365
366 Available values are ``complete``, ``correct``, ``suggest``.
367
368 - You can specify multiple types. You need to use ``|`` as
369 separator such as ``complete|correct``.
370
371 .. _groonga-suggest-httpd-optional-parameters:
372
373 Optional parameters
374 ^^^^^^^^^^^^^^^^^^^
375
376 Here are optional parameters.
377
378 .. list-table::
379 :header-rows: 1
380
381 * - Key
382 - Description
383 - Note
384 * - ``callback``
385 - Function name for JSONP
386 -
387
388 .. _groonga-suggest-httpd-optional-parameters-learning:
389
390 Optional parameters for learning
391 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
392
393 Here are optional parameters when you specify
394 :option:`--send-endpoint`.
395
396 .. list-table::
397 :header-rows: 1
398
399 * - Key
400 - Description
401 - Note
402 * - ``t``
403 - The query type.
404
405 Available value is only ``submit``.
406
407 - You must specify ``submit`` when user submits the input
408 specified as ``q``.
409
410 You must not specify ``submit`` for user inputs that aren't
411 submitted yet. You can use suggestion by specifying
412 ``complete``, ``correct`` and/or ``suggest`` to ``t`` when you
413 doesn't specify ``submit``. See
414 :ref:`groonga-suggest-httpd-required-parameters-suggestion` for
415 details about these values.
416
417
418 Return value
419 ------------
420
421 ``groonga-suggest-httpd`` returns the following format response. It's
422 the same format as body of :doc:`/reference/commands/suggest`::
423
424 {
425 TYPE1: [
426 [CANDIDATE_1, SCORE_1],
427 [CANDIDATE_2, SCORE_2],
428 ...,
429 [CANDIDATE_N, SCORE_N]
430 ],
431 TYPE2: [
432 [CANDIDATE_1, SCORE_1],
433 [CANDIDATE_2, SCORE_2],
434 ...,
435 [CANDIDATE_N, SCORE_N]
436 ],
437 ...
438 }
439
440 Here is the response when ``t`` is ``submit``::
441
442 {}
443
444 ``TYPE``
445 ^^^^^^^^
446
447 One of ``complete``, ``correct`` and ``suggest``.
448
449 ``CANDIDATE_N``
450 ^^^^^^^^^^^^^^^
451
452 The string of candidate in UTF-8.
453
454 ``SCORE_N``
455 ^^^^^^^^^^^
456
457 The score of the candidate.
458
459 Candidates are sorted by score descendant.
460
461 See also
462 --------
463
464 * :doc:`/reference/commands/suggest`
465
466 .. groonga-command
467 .. $ killall lt-groonga-suggest-learner || :
468 .. $ killall groonga-suggest-learner || :
469 .. $ killall lt-groonga-suggest-httpd || :
470 .. $ killall groonga-suggest-httpd || :
471 .. $ killall -KILL lt-groonga-suggest-learner || :
472 .. $ killall -KILL groonga-suggest-learner || :
473 .. $ killall -KILL lt-groonga-suggest-httpd || :
474 .. $ killall -KILL groonga-suggest-httpd || :