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

&^| operator

Since 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.

Operator classes

You need to specify one of the following operator classes to use this operator:


Here are sample schema and data for examples:

  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)

See also