This is a document for PGroonga 2.X and 3.X. See PGroonga 1.x document when you're using old PGroonga.
&^|
operatorSince 1.2.1.
&^|
operator performs prefix search by an array of prefixes. If one or more prefixes are matched, the record is matched.
Prefix search is useful for implementing input completion.
column &^| prefixes
column
is a column to be searched. It's text
type or text[]
type.
prefixes
is an array of prefixes to be found. It's text[]
type.
The operator returns true
when the column
value starts with one or more prefixes in prefixes
.
You need to specify one of the following operator classes to use this operator:
pgroonga_text_term_search_ops_v2
: For text
pgroonga_text_array_term_search_ops_v2
: For text[]
pgroonga_varchar_term_search_ops_v2
: For varchar
Here are sample schema and data for examples:
CREATE TABLE tags (
name text PRIMARY KEY,
alias text
);
CREATE INDEX pgroonga_tag_alias_index ON tags
USING pgroonga (alias pgroonga_text_term_search_ops_v2);
INSERT INTO tags VALUES ('PostgreSQL', 'PG');
INSERT INTO tags VALUES ('Groonga', 'grn');
INSERT INTO tags VALUES ('PGroonga', 'pgrn');
INSERT INTO tags VALUES ('Mroonga', 'mrn');
You can perform prefix search with prefixes by &^|
operator:
SELECT * FROM tags WHERE alias &^| ARRAY['pg', 'mrn'];
-- name | alias
-- ------------+-------
-- PostgreSQL | PG
-- PGroonga | pgrn
-- Mroonga | mrn
-- (3 rows)
&^
operator: Prefix search
&^~
operator: Prefix RK search
!&^|
operator: NOT prefix search by an array of prefixes
&^~|
operator: Prefix RK search by an array of prefixes