File: math_abs.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 (78 lines) | stat: -rw-r--r-- 1,928 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
.. -*- rst -*-

.. groonga-command
.. database: math_abs

``math_abs``
===============

Summary
-------

.. versionadded:: 7.0.4

``math_abs`` returns the absolute value of value.

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

  plugin_register functions/math

Syntax
------

``math_abs`` requires one argument - ``target``.

::

  math_abs(target)

Usage
-----

Here is a schema definition and sample data.

Sample schema:

.. groonga-command
.. plugin_register functions/math
.. include:: ../../example/reference/functions/math_abs/usage_setup_schema.log
.. table_create Shops TABLE_HASH_KEY ShortText
.. column_create Shops from_station COLUMN_SCALAR Int32
.. column_create Shops from_office COLUMN_SCALAR Int32

Sample data:

.. groonga-command
.. include:: ../../example/reference/functions/math_abs/usage_setup_data.log
.. load --table Shops
.. [
.. {"_key": "Coffee Shop",         "from_station":  50},
.. {"_key": "Donut & Coffee Shop", "from_station": 400},
.. {"_key": "Cake & Coffee Shop",  "from_station": 200}
.. ]

Here is the simple usage of ``math_abs`` function which returns nearest shops from office.

To detect nearest shops, we need to calculate distance.
If the distance of your office from station is 250 meters, you can calculate it by ``math_abs(250 - from_station)``.

.. groonga-command
.. include:: ../../example/reference/functions/math_abs/nearest_shops.log
.. select Shops --filter true --output_columns '_key, from_office' --scorer 'from_office = math_abs(250 - from_station)' --sort_keys from_office

By specifying ``--sort_keys from_office``, you can show nearest shops by ascending order.

Parameters
----------

There is only one required parameter.

``target``
^^^^^^^^^^

Specifies a column of table that is specified by ``table`` parameter in ``select``.

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

``math_abs`` returns the absolute value of target column value.