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 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
|
.. -*- rst -*-
.. highlightlang:: none
.. program:: groonga-suggest-httpd
.. groonga-command
.. database: groonga-suggest-httpd
.. % killall lt-groonga-suggest-learner || :
.. % killall lt-groonga-suggest-httpd || :
``groonga-suggest-httpd``
=========================
Summary
-------
``groonga-suggest-httpd`` is a program that provides HTTP interface
for the following features:
* Returning :doc:`/reference/suggest` execution result
* Saving logs for learning
``groonga-suggest-httpd`` provides suggest feature like
:doc:`/reference/commands/suggest` command. Note that some parameter
names are different of them.
Syntax
------
``groonga-suggest-httpd`` requires database path::
groonga-suggest-httpd [options] DATABASE_PATH
Usage
-----
You need to create one or more datasets to use
``groonga-suggest-httpd``. A dataset consists of tables and
columns. You can define them by :doc:`groonga-suggest-create-dataset`.
You need to use :doc:`groonga-suggest-learner` to learn suggestion
data from user inputs. You doesn't need to use
:doc:`groonga-suggest-learner` when you create suggestion data by
hand. See :doc:`/reference/suggest` and sub documents about creating
suggestion data by hand.
You can use ``groonga-suggest-httpd`` via HTTP after you create one or
more datasets.
The following sections describes the followings:
* How to set up a dataset
* How to use ``groonga-suggest-httpd`` with :doc:`groonga-suggest-learner`
* How to use ``groonga-suggest-httpd`` for retrieving suggestions.
Setup
^^^^^
You need to create a dataset by :doc:`groonga-suggest-create-dataset`.
Here is an example that creates ``query`` dataset:
.. groonga-command
.. include:: ../../example/reference/executables/groonga-suggest-httpd/setup.log
.. % groonga-suggest-create-dataset ${DB_PATH} query
:doc:`groonga-suggest-create-dataset` outputs executed commands. You
can confirm that what tables and columns are created for the new
dataset.
Launch ``groonga-suggest-learner``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You can choose whether you use learned suggestion data immediately or
not.
There are two ways to use learned suggestion data immediately:
* Both of ``groonga-suggest-httpd`` and
:doc:`groonga-suggest-learner` use the same database
* ``groonga-suggest-httpd`` receives learned suggestion data from
:doc:`groonga-suggest-learner`
In the former case, you must run both ``groonga-suggest-httpd`` and
:doc:`groonga-suggest-learner` on the same host.
In the latter case, you can run ``groonga-suggest-httpd`` and
:doc:`groonga-suggest-learner` on different hosts.
If you don't need to use learned suggestion data immediately, you need
to apply learned suggestion data from database that is used by
:doc:`groonga-suggest-learner` to database that is used by
``groonga-suggest-httpd`` by hand. Normally, this usage is
recommended. Because learned suggestion data may have garbage data by
inputs from evil users.
In this document, learned suggestion data are used immediately by
receiving learned suggestion data from
:doc:`groonga-suggest-learner`. Both ``groonga-suggest-httpd`` and
:doc:`groonga-suggest-learner` are running on the same host. Because
it's easy to explain.
Here is an example that launches :doc:`groonga-suggest-learner`. You
need to specify database that has ``query`` dataset. This document
omits the instruction for creating ``query`` dataset:
.. groonga-command
.. database: groonga-suggest-httpd-learner
.. % groonga-suggest-create-dataset ${DB_PATH} query
.. groonga-command
.. include:: ../../example/reference/executables/groonga-suggest-httpd/launch-lerner.log
.. % groonga-suggest-learner --daemon ${DB_PATH}
The ``groonga-suggest-learner`` process opens two endpoints at
``1234`` port and ``1235`` port:
* ``1234`` port: Endpoint that accepts user input data from
``groonga-suggest-httpd``
* ``1235`` port: Endpoint that sends learned suggestion data to
``groonga-suggest-httpd``
Launch ``groonga-suggest-httpd``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You need to launch ``groonga-suggest-httpd`` for the following proposes:
* Learning suggestion data from user inputs
* Providing suggestion result to clients
Here is an example that launches ``groonga-suggest-httpd`` that
communicates :doc:`groonga-suggest-learner`:
.. groonga-command
.. database: groonga-suggest-httpd
.. groonga-command
.. include:: ../../example/reference/executables/groonga-suggest-httpd/launch.log
.. % groonga-suggest-httpd --send-endpoint 'tcp://127.0.0.1:1234' --receive-endpoint 'tcp://127.0.0.1:1235' --daemon ${DB_PATH}
The ``groonga-suggest-httpd`` process accepts HTTP requests on
``8080`` port.
If you want to save requests into log file, use
:option:`--log-base-path` option.
Here is an example to save log files under ``logs`` directory with
``log`` prefix for each file::
% groonga-suggest-httpd --log-base-path logs/log ${DB_PATH}
``groonga-suggest-httpd`` creates log files such as
``logYYYYmmddHHMMSS-00`` under ``logs`` directory.
Learn from user inputs
^^^^^^^^^^^^^^^^^^^^^^
You can learn suggestion data from user inputs.
You need to specify the following parameters to learn suggestion data:
* ``i``: The ID of the user (You may use IP address of client)
* ``l``: The dataset name
* ``s``: The timestamp of the input in seconds
* ``t``: The query type (It's optional. You must specify ``submit`` only when the user input is submitted.)
* ``q``: The user input
Here are example requests to learn user input "Groonga" in ``query``
dataset::
.. groonga-command
.. include:: ../../example/reference/executables/groonga-suggest-httpd/learn.log
.. % curl 'http://localhost:8080/?i=127.0.0.1&l=query&s=92619&q=G'
.. % curl 'http://localhost:8080/?i=127.0.0.1&l=query&s=93850&q=Gr'
.. % curl 'http://localhost:8080/?i=127.0.0.1&l=query&s=94293&q=Gro'
.. % curl 'http://localhost:8080/?i=127.0.0.1&l=query&s=94734&q=Groo'
.. % curl 'http://localhost:8080/?i=127.0.0.1&l=query&s=95147&q=Grooon'
.. % curl 'http://localhost:8080/?i=127.0.0.1&l=query&s=95553&q=Groonga'
.. % curl 'http://localhost:8080/?i=127.0.0.1&l=query&s=95959&t=submit&q=Groonga'
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.
Submitted data must use ``t=submit`` parameter.
Use suggested response
^^^^^^^^^^^^^^^^^^^^^^
You can get suggested result from ``groonga-suggest-httpd``.
You need to specify the following parameters to get suggested result:
* ``n``: The dataset name
* ``t``: The query type (``complete``, ``correct`` and/or ``suggest``)
* ``q``: The user input
You can also specify parameters for :doc:`/reference/commands/suggest` as option.
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:
.. groonga-command
.. include:: ../../example/reference/executables/groonga-suggest-httpd/complete.log
.. % curl 'http://localhost:8080/?n=query&t=complete&q=G&frequency_threshold=1'
You can combine completion and learning by specifying parameters for both:
.. groonga-command
.. include:: ../../example/reference/executables/groonga-suggest-httpd/learn-and-complete.log
.. % curl 'http://localhost:8080/?i=127.0.0.1&l=query&s=96000&q=G&n=query&t=complete&frequency_threshold=1'
Command line parameters
-----------------------
Required parameters
^^^^^^^^^^^^^^^^^^^
There is one required parameter.
``DATABASE_PATH``
"""""""""""""""""
Specifies the path to a Groonga database. This database must have one
or more datasets. Each dataset must be created by
:doc:`groonga-suggest-create-dataset`.
Optional parameters
^^^^^^^^^^^^^^^^^^^
.. option:: -p, --port
Specify HTTP server port number.
The default port number is ``8080``.
.. option:: -t, --n-threads
Specify number of threads.
This option accepts ``128`` as the max value, but use the number of
CPU cores for performance.
The default value is the number of CPU cores.
.. option:: -s, --send-endpoint
Specify endpoint URI of :doc:`groonga-suggest-learner` for sending
user inputs.
The format is ``tcp://${HOST}:${PORT}`` such as
``tcp://192.168.0.1:2929``.
The default value is none.
.. option:: -r, --receive-endpoint
Specify endpoint URI of :doc:`groonga-suggest-learner` for
receiving learned suggestion data.
The format is ``tcp://${HOST}:${PORT}`` such as
``tcp://192.168.0.1:2929``.
The default value is none.
.. option:: -l, --log-base-path
Specify path prefix of log.
The default value is none.
.. option:: --n-lines-per-log-file
Specify the max number of lines in a log file.
The default value is ``1000000``.
.. option:: -d, --daemon
Specify this option to daemonize.
Don't daemonize by default.
.. option:: --disable-max-fd-check
Specify this option to disable checking the max number of file
descriptors on start.
Check by default.
GET parameters
--------------
``groonga-suggest-httpd`` accepts some GET parameters.
There are required parameters which depend on query type.
In ``complete``, ``correct`` or ``suggest`` query type, unhandled
parameters are passed through :doc:`/reference/commands/suggest`. It
means that you can use parameters of
:doc:`/reference/commands/suggest`.
.. _groonga-suggest-httpd-required-parameters:
Required parameters
^^^^^^^^^^^^^^^^^^^
You must specify the following parameters.
.. list-table::
:header-rows: 1
* - Key
- Description
- Note
* - ``q``
- Input by user. It must be UTF-8 encoded string.
-
.. _groonga-suggest-httpd-required-parameters-learning:
Required parameters for learning
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You must specify the following parameters when you specify
:option:`--send-endpoint`.
.. list-table::
:header-rows: 1
* - Key
- Description
- Note
* - ``s``
- Elapsed time since ``1970-01-01T00:00:00Z``.
- The unit is millisecond.
* - ``i``
- Unique ID to distinct each user
- Session ID, IP address and so on will be usable
for this value.
* - ``l``
- One or more learn target dataset names. You need to use ``|``
as separator such as ``dataset1|dataset2|dataset3``.
- Dataset name is the name that you specify to
:doc:`groonga-suggest-create-dataset`.
.. _groonga-suggest-httpd-required-parameters-suggestion:
Required parameters for suggestion
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You must specify the following parameters when you specify one of
``complete``, ``correct`` and ``suggest`` to ``t`` parameter.
.. list-table::
:header-rows: 1
* - Key
- Description
- Note
* - ``n``
- The dataset name to use computing suggestion result.
- Dataset name is the name that you specify to
:doc:`groonga-suggest-create-dataset`.
* - ``t``
- The query type.
Available values are ``complete``, ``correct``, ``suggest``.
- You can specify multiple types. You need to use ``|`` as
separator such as ``complete|correct``.
.. _groonga-suggest-httpd-optional-parameters:
Optional parameters
^^^^^^^^^^^^^^^^^^^
Here are optional parameters.
.. list-table::
:header-rows: 1
* - Key
- Description
- Note
* - ``callback``
- Function name for JSONP
-
.. _groonga-suggest-httpd-optional-parameters-learning:
Optional parameters for learning
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Here are optional parameters when you specify
:option:`--send-endpoint`.
.. list-table::
:header-rows: 1
* - Key
- Description
- Note
* - ``t``
- The query type.
Available value is only ``submit``.
- You must specify ``submit`` when user submits the input
specified as ``q``.
You must not specify ``submit`` for user inputs that aren't
submitted yet. You can use suggestion by specifying
``complete``, ``correct`` and/or ``suggest`` to ``t`` when you
doesn't specify ``submit``. See
:ref:`groonga-suggest-httpd-required-parameters-suggestion` for
details about these values.
Return value
------------
``groonga-suggest-httpd`` returns the following format response. It's
the same format as body of :doc:`/reference/commands/suggest`::
{
TYPE1: [
[CANDIDATE_1, SCORE_1],
[CANDIDATE_2, SCORE_2],
...,
[CANDIDATE_N, SCORE_N]
],
TYPE2: [
[CANDIDATE_1, SCORE_1],
[CANDIDATE_2, SCORE_2],
...,
[CANDIDATE_N, SCORE_N]
],
...
}
Here is the response when ``t`` is ``submit``::
{}
``TYPE``
^^^^^^^^
One of ``complete``, ``correct`` and ``suggest``.
``CANDIDATE_N``
^^^^^^^^^^^^^^^
The string of candidate in UTF-8.
``SCORE_N``
^^^^^^^^^^^
The score of the candidate.
Candidates are sorted by score descendant.
See also
--------
* :doc:`/reference/commands/suggest`
.. groonga-command
.. % killall lt-groonga-suggest-learner || :
.. % killall lt-groonga-suggest-httpd || :
.. % killall -KILL lt-groonga-suggest-learner || :
.. % killall -KILL lt-groonga-suggest-httpd || :
|