Skip to content

Instantly share code, notes, and snippets.

@askdkc
Created February 17, 2023 04:59
Show Gist options
  • Save askdkc/fe992097b1c80cf1578b489b1f382c35 to your computer and use it in GitHub Desktop.
Save askdkc/fe992097b1c80cf1578b489b1f382c35 to your computer and use it in GitHub Desktop.

DB作成

createdb dougigo
psql dougigo

SQL実行

CREATE EXTENSION pgroonga;

CREATE TABLE synonyms (
  target text,
  normalized text
);

CREATE INDEX pgroonga_synonyms_index ON synonyms
 USING pgroonga (target pgroonga_text_term_search_ops_v2,
                 normalized);

INSERT INTO synonyms VALUES ('', '');
INSERT INTO synonyms VALUES ('', '');
INSERT INTO synonyms VALUES ('', '');
INSERT INTO synonyms VALUES ('', '');

CREATE TABLE names (
  name text
);
CREATE INDEX pgroonga_names_index
          ON names
       USING pgroonga (name pgroonga_text_full_text_search_ops_v2)
   WITH (normalizers='
                NormalizerNFKC130,
                NormalizerTable(
                  "normalized", "${table:pgroonga_synonyms_index}.normalized",
                  "target", "target"
                )
             ');

INSERT INTO names
  (name)
  VALUES ('斉藤さん'),('齊藤さん'),('斎藤さん'),('鈴木さん'),('田中さん'),('佐藤さん'),('高橋さん'),('髙橋さん');

検索実行

select * from names where name &~ '\A';
--    name   
-- ----------
--  斉藤さん
-- (1 row)


select * from names where name &@~ '';
--    name   
-- ----------
--  斉藤さん
--  齊藤さん
--  斎藤さん
-- (3 rows)
@kou
Copy link

kou commented Feb 17, 2023

pgroonga_text_full_text_search_ops_v2じゃなくてpgroonga_text_regexp_ops_v2を使うんですよ!

それでもなんか動かないんですけど、PGroongaのバグな気がしますね。。。

@askdkc
Copy link
Author

askdkc commented Feb 17, 2023

@kou さん

あー😵インデックス指定ミス失礼しました🙇‍♂️

そしてバグも見つけちゃったんですね、、、
不幸中の幸い?

@askdkc
Copy link
Author

askdkc commented Feb 17, 2023

とりあえずIssue建てました
pgroonga/pgroonga#293

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment