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

pgroonga.query_extract_keywords function

Since 1.0.7.

Summary

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.

Syntax

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.

Usage

You can get all terms as keywords for AND only case:

SELECT pgroonga.query_extract_keywords('Groonga PostgreSQL');
--  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');
--  query_extract_keywords 
-- ------------------------
--  {PostgreSQL,Groonga}
-- (1 row)

You can use parentheses:

SELECT pgroonga.query_extract_keywords('Groonga (MySQL OR PostgreSQL)');
--    query_extract_keywords   
-- ----------------------------
--  {Groonga,PostgreSQL,MySQL}
-- (1 row)

Term for NOT condition isn't keyword:

SELECT pgroonga.query_extract_keywords('Groonga - MySQL PostgreSQL');
--  query_extract_keywords 
-- ------------------------
--  {PostgreSQL,Groonga}
-- (1 row)

See also