This is a document for PGroonga 2.X. See PGroonga 1.x document when you're using old PGroonga.
pgroonga_query_extract_keywords
functionSince 1.0.7.
pgroonga_query_extract_keywords
function extract keywords from text that uses query syntax. Query syntax is used by &@~
operator, &@~|
operator and so on.
Extracting keywords from query helps you to use pgroonga_snippet_html
function, pgroonga_highlight_html
function and so on. They require keywords as an argument. Normally, the keywords must be keywords in query.
Here is the syntax of this function:
text[] pgroonga_query_extract_keywords(query)
query
is a text
type value. It uses query syntax.
pgroonga_query_extract_keywords
returns an array of keywords.
Search terms for AND condition and OR condition are keywords. Search terms for NOT condition aren't keywords. For example, A
, B
and C
are keywords and D
isn't keyword in "A (B OR C) - D"
. -
is NOT operator.
You can get all terms as keywords for AND only case:
SELECT pgroonga_query_extract_keywords('Groonga PostgreSQL') AS query_extract_keywords;
-- query_extract_keywords
-- ------------------------
-- {PostgreSQL,Groonga}
-- (1 row)
You can get all terms as keywords for OR only case:
SELECT pgroonga_query_extract_keywords('Groonga OR PostgreSQL') AS query_extract_keywords;
-- query_extract_keywords
-- ------------------------
-- {PostgreSQL,Groonga}
-- (1 row)
You can use parentheses:
SELECT pgroonga_query_extract_keywords('Groonga (MySQL OR PostgreSQL)') AS query_extract_keywords;
-- query_extract_keywords
-- ----------------------------
-- {Groonga,PostgreSQL,MySQL}
-- (1 row)
Term for NOT condition isn't keyword:
SELECT pgroonga_query_extract_keywords('Groonga - MySQL PostgreSQL') AS query_extract_keywords;
-- query_extract_keywords
-- ------------------------
-- {PostgreSQL,Groonga}
-- (1 row)