All pages
Powered by GitBook
1 of 9

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

mroonga_command

Execute raw Groonga commands directly from MariaDB using this UDF, allowing for advanced administration and inspection of the Groonga database.

Syntax

mroonga_command (command)

Description

mroonga_command is a (UDF) included with the . It passes a command to Groonga for execution. See for details on creating this UDF if required.

  • command - string, required parameter specifying the command to pass that are executed by Groonga. See for a list of commands.

Returns the result of the Groonga command.

Example

See Also

This page is licensed: CC BY-SA / Gnu FDL

user-defined function
Mroonga storage engine
Creating Mroonga User-Defined Functions
the Groonga reference
Creating Mroonga User-Defined Functions
SELECT mroonga_command('status');
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| mroonga_command('status')                                                                                                                                                                                      |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| {"alloc_count":593,"starttime":1512022368,"start_time":1512022368,"uptime":13510,"version":"7.0.7","n_queries":0,"cache_hit_rate":0.0,"command_version":1,"default_command_version":1,"max_command_version":3} |

Mroonga User-Defined Functions

Extend Mroonga's functionality in MariaDB Server with user-defined functions. Learn how to create custom functions to enhance full-text search and data processing capabilities.

last_insert_grn_id

This UDF returns the unique ID assigned by Groonga for the last inserted record, useful for tracking internal record identifiers.

Syntax

last_insert_grn_id()

Description

last_insert_grn_id is a (UDF) included with the . It returns the unique Groonga id of the last-inserted record. See for details on creating this UDF if required.

Examples

See Also

This page is licensed: CC BY-SA / Gnu FDL

SELECT last_insert_grn_id();
+----------------------+
| last_insert_grn_id() |
+----------------------+
|                    3 |
+----------------------+
user-defined function
Mroonga storage engine
Creating Mroonga User-Defined Functions
Creating Mroonga User-Defined Functions

mroonga_escape

This function escapes special characters in a string to make it safe for use in Mroonga full-text search queries.

Syntax

mroonga_escape (string [,special_characters])
  • string - required parameter specifying the text you want to escape

  • special_characters - optional parameter specifying the characters to escape

Description

mroonga_escape is a (UDF) included with the , used for escaping a string. See for details on creating this UDF if required.

If no special_characters parameter is provided, by default +-<>*()": are escaped.

Returns the escaped string.

Example

See Also

This page is licensed: CC BY-SA / Gnu FDL

user-defined function
Mroonga storage engine
Creating Mroonga User-Defined Functions
Creating Mroonga User-Defined Functions

mroonga_snippet_html

Similar to mroonga_snippet, this function generates HTML-formatted snippets, automatically wrapping matched keywords in tags for web display.

Description

mroonga_snippet_html is a user-defined function (UDF) included with the Mroonga storage engine. It provides a keyword with surrounding text, or the keyword in context. It is still considered experimental. See Creating Mroonga User-Defined Functions for details on creating this UDF if required.

See Also

This page is licensed: CC BY-SA / Gnu FDL

mroonga_highlight_html

Highlight keywords within a text string using HTML tags, making it easy to display search results with matched terms emphasized.

Syntax

mroonga_highlight_html(text[[, query AS query]])

mroonga_highlight_html(text[[, keyword1, ..., keywordN]])

Description

mroonga_highlight_html is a (UDF) included with the . It highlights the specified keywords in the target text. See for details on creating this UDF if required.

The optional parameter can either be one or more keywords, or a Groonga query.

The function highlights the specified keywords in the target text by surrounding each keyword with <span class="keyword">...</span>, and escaping special HTML characters such as < and >.

Returns highlighted HTML.

Examples

Highlighting the words MariaDB and Mroonga in a given text:

The same outcome, formulated as a Groonga query:

See Also

This page is licensed: CC BY-SA / Gnu FDL

Creating Mroonga User-Defined Functions

Instructions on how to manually create Mroonga's UDFs if they were not automatically installed, ensuring full functionality.

The Mroonga storage engine includes a number of user-defined functions that need to be created before they can be used. If these are not created already during Mroonga setup, you will need to do so yourself. The full list of available functions and the statements to create them are found in share/mroonga/install.sql, for example, as of Mroonga 7.07 running on Linux:

DROP FUNCTION IF EXISTS last_insert_grn_id;
CREATE FUNCTION last_insert_grn_id RETURNS INTEGER
  SONAME 'ha_mroonga.so';

DROP FUNCTION IF EXISTS mroonga_snippet;
CREATE FUNCTION mroonga_snippet RETURNS STRING
  SONAME 'ha_mroonga.so';

DROP FUNCTION IF EXISTS mroonga_command;
CREATE FUNCTION mroonga_command RETURNS STRING
  SONAME 'ha_mroonga.so';

DROP FUNCTION IF EXISTS mroonga_escape;
CREATE FUNCTION mroonga_escape RETURNS STRING
  SONAME 'ha_mroonga.so';

DROP FUNCTION IF EXISTS mroonga_snippet_html;
CREATE FUNCTION mroonga_snippet_html RETURNS STRING
  SONAME 'ha_mroonga.so';

DROP FUNCTION IF EXISTS mroonga_normalize;
CREATE FUNCTION mroonga_normalize RETURNS STRING
  SONAME 'ha_mroonga.so';

DROP FUNCTION IF EXISTS mroonga_highlight_html;
CREATE FUNCTION mroonga_highlight_html RETURNS STRING
  SONAME 'ha_mroonga.so';

DROP FUNCTION IF EXISTS mroonga_query_expand;
CREATE FUNCTION mroonga_query_expand RETURNS STRING
  SONAME 'ha_mroonga.so';

This page is licensed: CC BY-SA / Gnu FDL

mroonga_snippet

This function extracts a snippet of text surrounding a keyword from a document, providing necessary context for search result displays.

Syntax

Description

mroonga_snippet

SELECT mroonga_escape("+-<>~*()\"\:");
'\\+\\-\\<\\>\\~\\*\\(\\)\\"\\:
is a
(UDF) included with the
. It provides a keyword with surrounding text, or the keyword in context. See
for details on creating this UDF if required.

The required parameters include:

  • document - Column name or string value.

  • max_length - Maximum length of the snippet, in bytes.

  • max_count - Maximum snippet elements (N word).

  • encoding - Encoding of the document, for example cp932_japanese_ci

  • skip_leading_spaces - 1 to skip leading spaces, 0 to not skip.

  • html_escape = 1 to enable HTML espape, 0 to disable.

  • prefix - Snippet start text.

  • suffix - Snippet end text.

The optional parameters include:

  • wordN - A word.

  • wordN_prefix - wordN start text.

  • wordN_suffix - wordN end text

It can be used in both storage and wrapper mode.

Returns the snippet string.

Example

See Also

  • Creating Mroonga User-Defined Functions

This page is licensed: CC BY-SA / Gnu FDL

user-defined function
Mroonga storage engine
Creating Mroonga User-Defined Functions
user-defined function
Mroonga storage engine
Creating Mroonga User-Defined Functions
Creating Mroonga User-Defined Functions
Creating Mroonga User-Defined Functions
mroonga_snippet
mroonga_snippet document,
                max_length,
                max_count,
                encoding,
                skip_leading_spaces,
                html_escape,
                snippet_prefix,
                snippet_suffix,
                word1, word1_prefix, word1_suffix
                ...
                [wordN wordN_prefix wordN_suffix]
SELECT mroonga_highlight_html('<p>MariaDB includes the Mroonga storage engine</p>.') 
  AS highlighted_html;
+-----------------------------------------------------------------+
| highlighted_html                                                |
+-----------------------------------------------------------------+
| &lt;p&gt;MariaDB includes the Mroonga storage engine&lt;/p&gt;. |
+-----------------------------------------------------------------+
SELECT mroonga_highlight_html('MariaDB includes the Mroonga storage engine.', 'MariaDB', 'Mroonga') 
  AS highlighted_html;
+--------------------------------------------------------------------------------------------------------+
| highlighted_html                                                                                       |
+--------------------------------------------------------------------------------------------------------+
| <span class="keyword">MariaDB</span> includes the <span class="keyword">Mroonga</span> storage engine. |
+--------------------------------------------------------------------------------------------------------+
SELECT mroonga_highlight_html('MariaDB includes the Mroonga storage engine.', 'MariaDB OR Mroonga' 
  AS query) AS highlighted_text;
+--------------------------------------------------------------------------------------------------------+
| highlighted_text                                                                                       |
+--------------------------------------------------------------------------------------------------------+
| <span class="keyword">MariaDB</span> includes the <span class="keyword">Mroonga</span> storage engine. |
+--------------------------------------------------------------------------------------------------------+

mroonga_normalize

This UDF normalizes a given string using Groonga's normalizers, ensuring consistent text processing for accurate indexing and searching.

Syntax

mroonga_normalize(string[, normalizer_name])

Description

mroonga_normalize is a (UDF) included with the . It uses Groonga's normalizer to normalize text. See for details on creating this UDF if required.

Given a string, returns the normalized text.

See the for details on the Groonga normalizers. The default if no normalizer is provided is NormalizerAuto.

Examples

See Also

This page is licensed: CC BY-SA / Gnu FDL

user-defined function
Mroonga storage engine
Creating Mroonga User-Defined Functions
Groonga Normalizer Reference
Creating Mroonga User-Defined Functions
SELECT mroonga_normalize("ABぃ㍑");
+-------------------------------+
| mroonga_normalize("ABぃ㍑")   |
+-------------------------------+
| abぃリットル                  |
+-------------------------------+