Debian Codegraph @

doc/source/reference/functions/snippet_html.rst

raw
1 .. -*- rst -*-
2
3 .. groonga-command
4 .. database: functions_snippet_html
5
6 ``snippet_html``
7 ================
8
9 Summary
10 -------
11
12 This function extracts snippets of target text around search keywords
13 (``KWIC``. ``KeyWord In Context``).
14
15 The snippets are prepared for embedding HTML. Special characters such
16 as ``<`` and ``>`` are escapsed as ``&lt;`` and ``&gt;``. Keyword is
17 surrounded with ``<span class="keyword">`` and ``</span>``. For
18 example, a snippet of ``I am a groonga user. <3`` for keyword
19 ``groonga`` is ``I am a <span class="keyword">groonga</span>
20 user. &lt;3``.
21
22 This function is a HTML specific version of :doc:`snippet`. Generally,
23 this function is enough for normal Web application use.
24
25 Syntax
26 ------
27
28 ``snippet_html`` has only one parameter::
29
30 snippet_html(column)
31
32 Usage
33 -----
34
35 Here are a schema definition and sample data to show usage.
36
37 .. groonga-command
38 .. include:: ../../example/reference/functions/snippet_html/usage_setup.log
39 .. table_create Documents TABLE_NO_KEY
40 .. column_create Documents content COLUMN_SCALAR Text
41 .. table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
42 .. column_create Terms documents_content_index COLUMN_INDEX|WITH_POSITION Documents content
43 .. load --table Documents
44 .. [
45 .. ["content"],
46 .. ["Groonga is a fast and accurate full text search engine based on inverted index. One of the characteristics of groonga is that a newly registered document instantly appears in search results. Also, groonga allows updates without read locks. These characteristics result in superior performance on real-time applications."],
47 .. ["Groonga is also a column-oriented database management system (DBMS). Compared with well-known row-oriented systems, such as MySQL and PostgreSQL, column-oriented systems are more suited for aggregate queries. Due to this advantage, groonga can cover weakness of row-oriented systems."]
48 .. ]
49
50 ``snippet_html`` can be used in only ``--output_columns`` in
51 :doc:`/reference/commands/select`.
52
53 You also need to specify ``--query`` and/or ``--filter``. Keywords are
54 extracted from ``--query`` and ``--filter`` arguments.
55
56 The following example uses ``--query "fast performance"``. In this
57 case, ``fast`` and ``performance`` are used as keywords.
58
59 .. groonga-command
60 .. include:: ../../example/reference/functions/snippet_html/usage_basic.log
61 .. select Documents --output_columns "snippet_html(content)" --command_version 2 --match_columns content --query "fast performance"
62
63 ``--query "fast performance"`` matches to only the first record's
64 content. ``snippet_html(content)`` extracts two text parts that
65 include the keywords ``fast`` or ``performance`` and surrounds the
66 keywords with ``<span class="keyword">`` and ``</span>``.
67
68 The max number of text parts is 3. If there are 4 or more text parts
69 that include the keywords, only the leading 3 parts are only used.
70
71 The max size of a text part is 200byte. The unit is bytes not
72 characters. The size doesn't include inserted ``<span class="keyword">``
73 and ``</span>``.
74
75 Both the max number of text parts and the max size of a text part
76 aren't customizable.
77
78 If you want to customize them, you need to use :doc:`snippet` instead
79 of this function.
80
81 You can specify string literal instead of column.
82
83 .. groonga-command
84 .. include:: ../../example/reference/functions/snippet_html/usage_string_literal.log
85 .. select Documents --output_columns 'snippet_html("Groonga is very fast fulltext search engine.")' --command_version 2 --match_columns content --query "fast performance"
86
87 Return value
88 ------------
89
90 This function returns an array of string or ``null``. If This function
91 can't find any snippets, it returns ``null``.
92
93 An element of array is a snippet::
94
95 [SNIPPET1, SNIPPET2, SNIPPET3]
96
97 A snippet includes one or more keywords. The max byte size of a
98 snippet except open tag and close tag is 200byte. The unit isn't the
99 number of characters.
100
101 Open tag is ``<span class="keyword">`` and close tag is ``</span>``.
102
103 The array size is larger than or equal to 1 and less than or equal
104 to 3.
105
106 If you want to customize the max byte size of snippet and/or the max
107 number of snippets, use :doc:`snippet` instead.
108
109 See also
110 --------
111
112 * :doc:`snippet`
113 * :doc:`/reference/commands/select`