Debian Codegraph @

doc/source/reference/suggest/suggestion.rst

raw
1 .. -*- rst -*-
2
3 .. groonga-command
4 .. database: suggestion
5 .. $ groonga-suggest-create-dataset ${DB_PATH} query
6
7 Suggestion
8 ==========
9
10 This section describes about the following completion
11 features:
12
13 * How it works
14 * How to use
15 * How to learn
16
17 How it works
18 ------------
19
20 The suggestion feature uses a search to compute suggested
21 words:
22
23 1. Cooccurrence search against learned data.
24
25 Cooccurrence search
26 ^^^^^^^^^^^^^^^^^^^
27
28 Cooccurrence search can find related words from user's
29 input. It uses user submissions that will be learned
30 from query logs, access logs and so on.
31
32 For example, there are the following user submissions:
33
34 +----------------------+
35 | query |
36 +======================+
37 | search engine |
38 +----------------------+
39 | web search realtime |
40 +----------------------+
41
42 Groonga creates the following suggestion pairs:
43
44 +----------+------------------------------------+
45 | input | suggested words |
46 +==========+====================================+
47 |search |search engine |
48 +----------+------------------------------------+
49 |engine |search engine |
50 +----------+------------------------------------+
51 |web |web search realtime |
52 +----------+------------------------------------+
53 |search |web search realtime |
54 +----------+------------------------------------+
55 |realtime |web search realtime |
56 +----------+------------------------------------+
57
58 Those pairs are created by the following steps:
59
60 1. Tokenizes user input query by TokenDelimit tokenizer
61 that uses a space as token delimiter. (e.g. "search
62 engine" is tokenized to two tokens "search" and
63 "engine".)
64 2. Creates a pair that is consists of a token and original
65 query for each token.
66
67 If an user inputs "search" and cooccurrence search returns
68 "search engine" and "web search realtime" because "search" is
69 in two input columns and corresponding suggested word
70 columns have "search engine" and "web search realtime".
71
72 How to use
73 ----------
74
75 .. groonga-command
76 .. load --table event_query --each 'suggest_preparer(_id, type, item, sequence, time, pair_query)'
77 .. [
78 .. {"sequence": "1", "time": 1312950803.86057, "item": "search engine", "type": "submit"},
79 .. {"sequence": "1", "time": 1312950808.86057, "item": "web search realtime", "type": "submit"}
80 .. ]
81
82 Groonga provides :doc:`/reference/commands/suggest` command to use
83 suggestion. `--type suggest` option requests suggestion
84
85 For example, here is an command to get suggestion results by
86 "search":
87
88 .. groonga-command
89 .. include:: ../../example/reference/suggest/suggest/select.log
90 .. suggest --table item_query --column kana --types suggest --frequency_threshold 1 --query search
91
92 How it learns
93 -------------
94
95 Cooccurrence search uses learned data. They are based on
96 query logs, access logs and so on. To create learned data,
97 groonga needs user input sequence with time stamp and user
98 submit input with time stamp.
99
100 For example, an user wants to search by "engine". The user
101 inputs the query with the following sequence:
102
103 1. 2011-08-10T13:33:23+09:00: search engine (submit)
104 2. 2011-08-10T13:33:28+09:00: web search realtime (submit)
105
106 Groonga can be learned from the submissions by the
107 following command::
108
109 load --table event_query --each 'suggest_preparer(_id, type, item, sequence, time, pair_query)'
110 [
111 {"sequence": "1", "time": 1312950803.86057, "item": "search engine", "type": "submit"},
112 {"sequence": "1", "time": 1312950808.86057, "item": "web search realtime", "type": "submit"}
113 ]
114
115 How to extract learning data
116 ----------------------------
117
118 The learning data is stored into ``item_DATASET`` and ``pair_DATASET`` tables.
119 By using select command for such tables, you can all extract learning data.
120
121 Here is the query to extract all learning data::
122
123 select item_DATASET --limit -1
124 select pair_DATASET --filter 'freq0 > 0 || freq1 > 0 || freq2 > 0' --limit -1
125
126 Without '--limit -1', you can't get all data.
127 In pair table, the valid value of ``freq0``, ``freq1`` and ``freq2`` column must be larger than 0.
128
129 Don't execute above query via HTTP request because enormous number of records are fetched.