Debian Codegraph @

doc/source/reference/tokenizers/token_pattern.rst

raw
1 .. -*- rst -*-
2
3 .. groonga-command
4 .. database: tokenizers
5
6 ``TokenPattern``
7 ================
8
9 Summary
10 -------
11
12 ``TokenPattern`` is a tokenizer which is used to extract tokens by regular expression.
13 This tokenizer extracts only token that matches the specified regular expression.
14
15 You can also specify multiple patterns of regular expression.
16
17 Syntax
18 ------
19
20 ``TokenPattern`` has optional parameter.
21
22 Specify one pattern::
23
24 TokenPattern("pattern", PATTERN)
25
26 Specify multiple patterns::
27
28 TokenPattern("pattern", PATTERN_1, "pattern", PATTERN_2, ... "pattern", PATTERN_N)
29
30
31 ``TokenPattern`` can accept multiple patterns as above.
32
33 Usage
34 -----
35
36 Here is an example of ``TokenPattern``. As ``TokenPattern`` only extracts the token which matches the specified regular expression, it is able to filter search results which only matches the extracted token.
37
38 For example, let's compare search results by specific keywords. One is listed in ``TokenPattern`` pattern, and the other is not listed in ``TokenPattern`` pattern.
39
40 There are menus which contains both of specific keywords in ``Foods`` table.
41
42 Here is the sample schema and data:
43
44 .. groonga-command
45 .. include:: ../../example/reference/tokenizers/token-pattern-schema.log
46 .. table_create Foods TABLE_NO_KEY
47 .. column_create Foods name COLUMN_SCALAR Text
48 .. table_create Keywords TABLE_PAT_KEY ShortText --default_tokenizer 'TokenPattern("pattern", "Apple|Orange")'
49 .. column_create Keywords index COLUMN_INDEX Foods name
50 .. load --table Foods
51 .. [
52 .. {"name": "Apple Pie"},
53 .. {"name": "Orange Pie"}
54 .. {"name": "Raspberry Pie"}
55 .. ]
56
57
58 Then search ``Apple Pie`` with ``--query Apple``.
59
60 .. groonga-command
61 .. include:: ../../example/reference/tokenizers/token-pattern-search-apple.log
62 .. select Foods --match_columns name --query 'Apple'
63
64 In above example, ``Apple`` matches pattern which is specified as ``TokenPattern`` pattern, ``select`` matches ``Apple Pie``.
65
66 Then search ``Raspberry Pie`` with ``--query Raspberry``.
67
68 .. groonga-command
69 .. include:: ../../example/reference/tokenizers/token-pattern-search-raspberry.log
70 .. select Foods --match_columns name --query 'Raspberry'
71
72 In above example, even though ``Foods`` table contains ``Raspberry Pie`` record, ``select`` doesn't match it because ``Raspberry`` doesn't match to ``TokenPattern`` pattern..
73
74 See also
75 ----------
76
77 * :doc:`../commands/tokenize`