7.3.61. suggest#
Note
The suggest feature specification isn’t stable. The specification may be changed.
7.3.61.1. 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 Introduction about completion, correction and suggestion.
7.3.61.2. 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]
7.3.61.3. Usage#
Here are learned data for completion.
Execution example:
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"}
]
# [[0,1337566253.89858,0.000355720520019531],6]
Here are learned data for correction.
Execution example:
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"}
]
# [[0,1337566253.89858,0.000355720520019531],8]
Here are learned data for suggestion.
Execution example:
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"}
]
# [[0,1337566253.89858,0.000355720520019531],2]
Here is a completion example.
Execution example:
suggest --table item_query --column kana --types complete --frequency_threshold 1 --query en
# [
# [
# 0,
# 1337566253.89858,
# 0.000355720520019531
# ],
# {
# "complete": [
# [
# 1
# ],
# [
# [
# "_key",
# "ShortText"
# ],
# [
# "_score",
# "Int32"
# ]
# ],
# [
# "engine",
# 1
# ]
# ]
# }
# ]
Here is a correction example.
Execution example:
suggest --table item_query --column kana --types correct --frequency_threshold 1 --query saerch
# [
# [
# 0,
# 1337566253.89858,
# 0.000355720520019531
# ],
# {
# "correct": [
# [
# 1
# ],
# [
# [
# "_key",
# "ShortText"
# ],
# [
# "_score",
# "Int32"
# ]
# ],
# [
# "search",
# 1
# ]
# ]
# }
# ]
Here is a suggestion example.
Execution example:
suggest --table item_query --column kana --types suggest --frequency_threshold 1 --query search
# [
# [
# 0,
# 1337566253.89858,
# 0.000355720520019531
# ],
# {
# "suggest": [
# [
# 2
# ],
# [
# [
# "_key",
# "ShortText"
# ],
# [
# "_score",
# "Int32"
# ]
# ],
# [
# "search engine",
# 1
# ],
# [
# "web search realtime",
# 1
# ]
# ]
# }
# ]
Here is a mixed example.
Execution example:
suggest --table item_query --column kana --types complete|correct|suggest --frequency_threshold 1 --query search
# [
# [
# 0,
# 1337566253.89858,
# 0.000355720520019531
# ],
# {
# "complete": [
# [
# 2
# ],
# [
# [
# "_key",
# "ShortText"
# ],
# [
# "_score",
# "Int32"
# ]
# ],
# [
# "search",
# 2
# ],
# [
# "search engine",
# 2
# ]
# ],
# "correct": [
# [
# 1
# ],
# [
# [
# "_key",
# "ShortText"
# ],
# [
# "_score",
# "Int32"
# ]
# ],
# [
# "search",
# 2
# ]
# ],
# "suggest": [
# [
# 2
# ],
# [
# [
# "_key",
# "ShortText"
# ],
# [
# "_score",
# "Int32"
# ]
# ],
# [
# "search engine",
# 1
# ],
# [
# "web search realtime",
# 1
# ]
# ]
# }
# ]
7.3.61.4. Parameters#
typesSpecifies what types are returned by the suggest command.
Here are available types:
completeThe suggest command does completion.
correctThe suggest command does correction.
suggestThe suggest command does suggestion.
You can specify one or more types separated by
|. Here are examples:It returns correction:
correctIt returns correction and suggestion:
correct|suggest
It returns complete, correction and suggestion:
complete|correct|suggest
tableSpecifies table name that has
item_${DATA_SET_NAME}format. For example,item_queryis a table name if you created dataset by the following command:groonga-suggest-create-dataset /tmp/db-path query
columnSpecifies a column name that has furigana in Katakana in
tabletable.querySpecifies query for completion, correction and/or suggestion.
sortbySpecifies sort key.
- Default:
-_score
output_columnsSpecifies output columns.
- Default:
_key,_score
offsetSpecifies returned records offset.
- Default:
0
limitSpecifies number of returned records.
- Default:
10
frequency_thresholdSpecifies threshold for item frequency. Returned records must have
_scorethat is greater than or equal tofrequency_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
queryis occurred. Returned records must have conditional probability that is greater than or equal toconditional_probability_threshold.
- Default:
0.2
prefix_searchSpecifies whether optional prefix search is used or not in completion.
Here are available values:
yesPrefix search is always used.
noPrefix search is never used.
autoPrefix search is used only when other search can’t find any records.
- Default:
auto
similar_searchSpecifies whether optional similar search is used or not in correction.
Here are available values:
yesSimilar search is always used.
noSimilar search is never used.
autoSimilar search is used only when other search can’t find any records.
- Default:
auto
7.3.61.5. 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 byscore of candidatedescending by default.