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 for text[]
is deprecated since 1.2.1. Use &^~
operator instead.
&^~
operator performs prefix RK search. R is for Romaji. K is for Katakana.
Prefix RK search is useful for Japanese.
Prefix RK search is useful for implementing input completion.
column &^~ prefix
column
is a column to be searched. It's text
type or text[]
type.
prefix
is a prefix to be found. It's text
type.
column
values must be in Katakana. prefix
must be in Romaji, Hiragana or Katakana.
The operator returns true
when the column
value starts with prefix
.
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 tag_readings (
name text,
katakana text,
PRIMARY KEY (name, katakana)
);
CREATE INDEX pgroonga_tag_reading_katakana_index ON tag_readings
USING pgroonga (katakana pgroonga_text_term_search_ops_v2);
INSERT INTO tag_readings VALUES ('PostgreSQL', 'ポストグレスキューエル');
INSERT INTO tag_readings VALUES ('PostgreSQL', 'ポスグレ');
INSERT INTO tag_readings VALUES ('Groonga', 'グルンガ');
INSERT INTO tag_readings VALUES ('PGroonga', 'ピージールンガ');
INSERT INTO tag_readings VALUES ('pglogical', 'ピージーロジカル');
You can perform prefix RK search with prefix in Romaji by &^~
operator:
SELECT * FROM tag_readings WHERE katakana &^~ 'pi-ji-';
-- name | katakana
-- -----------+------------------
-- PGroonga | ピージールンガ
-- pglogical | ピージーロジカル
-- (2 rows)
You can also use Hiragana for prefix:
SELECT * FROM tag_readings WHERE katakana &^~ 'ぴーじー';
-- name | katakana
-- -----------+------------------
-- PGroonga | ピージールンガ
-- pglogical | ピージーロジカル
-- (2 rows)
You can also use Katakana for prefix:
SELECT * FROM tag_readings WHERE katakana &^~ 'ピージー';
-- name | katakana
-- -----------+------------------
-- PGroonga | ピージールンガ
-- pglogical | ピージーロジカル
-- (2 rows)
&^
operator: Prefix search
&^|
operator: Prefix search by an array of prefixes
!&^|
operator: NOT prefix search by an array of prefixes
&^~|
operator: Prefix RK search by an array of prefixes