File: vector_find.rst

package info (click to toggle)
groonga 15.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 163,080 kB
  • sloc: ansic: 770,564; cpp: 48,925; ruby: 40,447; javascript: 10,250; yacc: 7,045; sh: 5,602; python: 2,821; makefile: 1,672
file content (156 lines) | stat: -rw-r--r-- 3,967 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
.. -*- rst -*-

.. groonga-command
.. database: functions_vector_find

``vector_find``
===============

Summary
-------

.. versionadded:: 8.0.4

It returns the first element that matches the given condition from the
given vector. If no element is found, it returns ``null``.

You can use not only equal condition but also less than condition,
prefix equal condition and so on.

To enable this function, register ``functions/vector`` plugin by
the following command::

  plugin_register functions/vector

.. _vector-find-syntax:

Syntax
------

``vector_find`` has two or three parameters::

  vector_find(vector, value)
  vector_find(vector, value, mode)

If you omit the third argument, each element in the ``vector`` is
compared with ``value`` by equality comparison.

.. _vector-find-usage:

Usage
-----

You need to register ``functions/vector`` plugin at first:

.. groonga-command
.. include:: ../../example/reference/functions/vector_find/usage_register.log
.. plugin_register functions/vector

Here is a schema definition and sample data.

Sample schema:

.. groonga-command
.. include:: ../../example/reference/functions/vector_find/usage_setup_schema.log
.. table_create  Memos TABLE_HASH_KEY ShortText
.. column_create Memos tags COLUMN_VECTOR ShortText

Sample data:

.. groonga-command
.. include:: ../../example/reference/functions/vector_find/usage_setup_data.log
.. load --table Memos
.. [
.. {"_key": "Groonga is fast",          "tags": ["groonga"]},
.. {"_key": "Mroonga is fast",          "tags": ["mroonga", "groonga"]},
.. {"_key": "Groonga is very good!",    "tags": ["groonga"]},
.. {"_key": "Droonga is fast",          "tags": ["droonga", "groonga"]},
.. {"_key": "Groonga is a HTTP server", "tags": ["groonga", "http"]}
.. ]

Here is a simple usage of ``vector_find`` that searches an element in
``tags`` column and returns the first found element:

.. groonga-command
.. include:: ../../example/reference/functions/vector_find/usage_find.log
.. select \
..   --table Memos \
..   --output_columns 'tags, vector_find(tags, "mroonga")'

It returns ``"mroonga"`` when the ``tags`` column value includes
``"mroonga"`` element. It returns ``null`` otherwise.

You can customize how to compare with each value by the third
argument. Here is a usage to use full text search to find an element:

.. groonga-command
.. include:: ../../example/reference/functions/vector_find/usage_find_mode.log
.. select \
..   --table Memos \
..   --output_columns 'tags, vector_find(tags, "roonga", "@")'

It returns ``"groonga"``, ``"mroonga"`` or ``"droonga"`` when the
``tags`` column value includes one of them. The returned value is the
first found element. For example, ``"droonga"`` is returned for
``["droonga", "groonga"]``. ``"groonga"`` isn't returned because the
first element ``"droonga"`` is found before the second element
``"groonga"`` is searched.

It returns ``null`` when ``tags`` column value doesn't include them.

.. _vector-find-parameters:

Parameters
----------

It requires two parameters.

There is an optional parameter.

.. _vector-find-required-parameters:

Required parameters
^^^^^^^^^^^^^^^^^^^

``vector`` and ``value`` are required.

.. _vector-find-vector:

``vector``
""""""""""

Specifies a vector value to be searched an element.

.. _vector-find-value:

``value``
"""""""""

Specifies a value to be compared.

.. _vector-find-optional-parameters:

Optional parameters
^^^^^^^^^^^^^^^^^^^

``mode`` is optional.

.. _vector-find-mode:

``mode``
""""""""

Specifies a mode that specifies how to compare each element with
:ref:`vector-find-value`.

See :ref:`query-default-mode` for available mode names. All mode names
except ``"NEAR"``, ``"SIMILAR"`` and ``"SUFFIX"`` are supported.

The default mode is ``"EQUAL"``. Note that :ref:`query-default-mode`
says the default mode is ``"MATCH"`` but the default mode of
``vector_find`` is ``"EQUAL"``.

Return value
------------

The matched element on match, ``null`` otherwise.