This is a document for PGroonga 1.X. See PGroonga 2.x document when you're using recent PGroonga.

pgroonga.match_positions_byte function

Since 1.0.7.

Summary

pgroonga.match_positions_byte function returns positions of the specified keywords in the specified text. The unit of position is byte. If you want to highlight keywords for HTML output, pgroonga.snippet_html function or pgroonga.highlight_html function will be suitable. pgroonga.match_positions_byte function is for advanced use.

If you want in character version, see pgroonga.match_positions_character instead.

Syntax

Here is the syntax of this function:

integer[2][] pgroonga.match_positions_byte(target, ARRAY[keyword1, keyword2, ...])

target is a text to be searched. It's text type.

keyword1, keyword2, ... are keywords to be found. They're an array of text type. You must specify one or more keywords.

pgroonga.match_positions_byte returns an array of positions.

Position consists of offset and length. Offset is the start byte from the beginning. Length is the number of bytes of matched text. Length may be different size with the length of keyword. Because keyword and matched text are normalized.

Usage

You need to specify at least one keyword:

SELECT pgroonga.match_positions_byte('PGroonga is a PostgreSQL extension.',
                                     ARRAY['PostgreSQL']);
--  match_positions_byte 
-- ----------------------
--  {{14,10}}
-- (1 row)

You can specify multiple keywords:

SELECT pgroonga.match_positions_byte('PGroonga is a PostgreSQL extension.',
                                     ARRAY['Groonga', 'PostgreSQL']);
--  match_positions_byte 
-- ----------------------
--  {{1,7},{14,10}}
-- (1 row)

You can extract keywords from query by pgroonga.query_extract_keywords function:

SELECT pgroonga.match_positions_byte('PGroonga is a PostgreSQL extension.',
                                     pgroonga.query_extract_keywords('Groonga PostgreSQL -extension'));
--  match_positions_byte 
-- ----------------------
--  {{1,7},{14,10}}
-- (1 row)

Characters are normalized:

SELECT pgroonga.match_positions_byte('PGroonga + pglogical = replicatable!',
                                     ARRAY['Pg']);
--  match_positions_byte 
-- ----------------------
--  {{0,2},{11,2}}
-- (1 row)

Multibyte characters are also supported:

SELECT pgroonga.match_positions_byte('10㌖先にある100キログラムの米',
                                     ARRAY['キロ']);
--  match_positions_byte 
-- ----------------------
--  {{2,3},{20,6}}
-- (1 row)

See also