Debian Codegraph @

doc/source/tutorial/patricia_trie.rst

raw
1 .. -*- rst -*-
2
3 .. groonga-command
4 .. database: tutorial-patricia-trie
5
6 Prefix search with patricia trie
7 ================================
8
9 Groonga supports to create a table with patricia trie option.
10 By specifying it, You can do prefix search.
11
12 And more, you can do suffix search against primary key by specifying additional option.
13
14 Prefix search by primary key
15 ----------------------------
16
17 table_create command which uses TABLE_PAT_KEY for flags option supports prefix search by primary key.
18
19 .. groonga-command
20 .. include:: ../example/tutorial/patricia_trie_prefix_search.log
21 ..
22 .. table_create --name PatPrefix --flags TABLE_PAT_KEY --key_type ShortText
23 .. load --table PatPrefix
24 .. [
25 .. {"_key":"James"}
26 .. {"_key":"Jason"}
27 .. {"_key":"Jennifer"},
28 .. {"_key":"Jeff"},
29 .. {"_key":"John"},
30 .. {"_key":"Joseph"},
31 .. ]
32 .. select --table PatPrefix --query _key:^Je
33
34 Suffix search by primary key
35 ----------------------------
36
37 table_create command which uses TABLE_PAT_KEY and KEY_WITH_SIS for flags option supports prefix search and suffix search by primary key.
38
39 If you set KEY_WITH_SIS flag, suffix search records also are added when you add the data. So if you search simply, the automatically added records are hit in addition to the original records. In order to search only the original records, you need a plan.
40
41 For example, in order to make this distinction between the original records and automatically added records, add the original column indicating that it is the original record, and add original column is ``true`` to the search condition. For attention, use ``--filter`` option because ``--query`` option is not specify ``Bool`` type value intuitively.
42
43 .. groonga-command
44 .. include:: ../example/tutorial/patricia_trie-2.log
45 ..
46 .. table_create --name PatSuffix --flags TABLE_PAT_KEY|KEY_WITH_SIS --key_type ShortText
47 .. column_create --table PatSuffix --name original --type Bool
48 .. load --table PatSuffix
49 .. [
50 .. {"_key":"ひろゆき","original":true},
51 .. {"_key":"まろゆき","original":true},
52 .. {"_key":"ひろあき","original":true},
53 .. {"_key":"ゆきひろ","original":true}
54 .. ]
55 .. select --table PatSuffix --query _key:$ゆき
56 .. select --table PatSuffix --filter '_key @$ "ゆき" && original == true'