Debian Codegraph @

doc/source/reference/functions/math_abs.rst

raw
1 .. -*- rst -*-
2
3 .. groonga-command
4 .. database: math_abs
5
6 ``math_abs``
7 ===============
8
9 Summary
10 -------
11
12 .. versionadded:: 7.0.4
13
14 ``math_abs`` returns the absolute value of value.
15
16 To enable this function, register ``functions/math`` plugin by following the command::
17
18 plugin_register functions/math
19
20 Syntax
21 ------
22
23 ``math_abs`` requires one argument - ``target``.
24
25 ::
26
27 math_abs(target)
28
29 Usage
30 -----
31
32 Here is a schema definition and sample data.
33
34 Sample schema:
35
36 .. groonga-command
37 .. plugin_register functions/math
38 .. include:: ../../example/reference/functions/math_abs/usage_setup_schema.log
39 .. table_create Shops TABLE_HASH_KEY ShortText
40 .. column_create Shops from_station COLUMN_SCALAR Int32
41 .. column_create Shops from_office COLUMN_SCALAR Int32
42
43 Sample data:
44
45 .. groonga-command
46 .. include:: ../../example/reference/functions/math_abs/usage_setup_data.log
47 .. load --table Shops
48 .. [
49 .. {"_key": "Coffee Shop", "from_station": 50},
50 .. {"_key": "Donut & Coffee Shop", "from_station": 400},
51 .. {"_key": "Cake & Coffee Shop", "from_station": 200}
52 .. ]
53
54 Here is the simple usage of ``math_abs`` function which returns nearest shops from office.
55
56 To detect nearest shops, we need to calculate distance.
57 If the distance of your office from station is 250 meters, you can calculate it by ``math_abs(250 - from_station)``.
58
59 .. groonga-command
60 .. include:: ../../example/reference/functions/math_abs/nearest_shops.log
61 .. select Shops --filter true --output_columns '_key, from_office' --scorer 'from_office = math_abs(250 - from_station)' --sort_keys from_office
62
63 By specifying ``--sort_keys from_office``, you can show nearest shops by ascending order.
64
65 Parameters
66 ----------
67
68 There is only one required parameter.
69
70 ``target``
71 ^^^^^^^^^^
72
73 Specifies a column of table that is specified by ``table`` parameter in ``select``.
74
75 Return value
76 ------------
77
78 ``math_abs`` returns the absolute value of target column value.