From d3e24200db4918568f81f2662a2fabd6af3f3857 Mon Sep 17 00:00:00 2001 From: Oliver Rice Date: Wed, 21 Aug 2024 16:00:37 -0500 Subject: [PATCH 1/2] add mecab test --- nix/tests/expected/pgroonga.out | 77 +++++++++++++++++++++++++++++++++ nix/tests/sql/pgroonga.sql | 48 ++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 nix/tests/expected/pgroonga.out create mode 100644 nix/tests/sql/pgroonga.sql diff --git a/nix/tests/expected/pgroonga.out b/nix/tests/expected/pgroonga.out new file mode 100644 index 000000000..cc3ab40e4 --- /dev/null +++ b/nix/tests/expected/pgroonga.out @@ -0,0 +1,77 @@ +create schema v; +create table v.roon( + id serial primary key, + content text +); +with tokenizers as ( + select + x + from + jsonb_array_elements( + (select pgroonga_command('tokenizer_list'))::jsonb + ) x(val) + limit + 1 + offset + 1 -- first record is unrelated and not stable +) +select + t.x::jsonb ->> 'name' +from + jsonb_array_elements((select * from tokenizers)) t(x) +order by + t.x::jsonb ->> 'name'; + ?column? +--------------------------------------------- + TokenBigram + TokenBigramIgnoreBlank + TokenBigramIgnoreBlankSplitSymbol + TokenBigramIgnoreBlankSplitSymbolAlpha + TokenBigramIgnoreBlankSplitSymbolAlphaDigit + TokenBigramSplitSymbol + TokenBigramSplitSymbolAlpha + TokenBigramSplitSymbolAlphaDigit + TokenDelimit + TokenDelimitNull + TokenDocumentVectorBM25 + TokenDocumentVectorTFIDF + TokenMecab + TokenNgram + TokenPattern + TokenRegexp + TokenTable + TokenTrigram + TokenUnigram +(19 rows) + +insert into v.roon (content) +values + ('Hello World'), + ('PostgreSQL with PGroonga is a thing'), + ('This is a full-text search test'), + ('PGroonga supports various languages'); +-- Create default index +create index pgroonga_index on v.roon using pgroonga (content); +-- Create mecab tokenizer index since we had a bug with this one once +create index pgroonga_index on v.roon using pgroonga (content) with (tokenizer='TokenMecab'); +ERROR: relation "pgroonga_index" already exists +-- Run some queries to test the index +select * from v.roon where content &@~ 'Hello'; + id | content +----+------------- + 1 | Hello World +(1 row) + +select * from v.roon where content &@~ 'powerful'; + id | content +----+--------- +(0 rows) + +select * from v.roon where content &@~ 'supports'; + id | content +----+------------------------------------- + 4 | PGroonga supports various languages +(1 row) + +drop schema v cascade; +NOTICE: drop cascades to table v.roon diff --git a/nix/tests/sql/pgroonga.sql b/nix/tests/sql/pgroonga.sql new file mode 100644 index 000000000..6be430f53 --- /dev/null +++ b/nix/tests/sql/pgroonga.sql @@ -0,0 +1,48 @@ +create schema v; + +create table v.roon( + id serial primary key, + content text +); + + +with tokenizers as ( + select + x + from + jsonb_array_elements( + (select pgroonga_command('tokenizer_list'))::jsonb + ) x(val) + limit + 1 + offset + 1 -- first record is unrelated and not stable +) +select + t.x::jsonb ->> 'name' +from + jsonb_array_elements((select * from tokenizers)) t(x) +order by + t.x::jsonb ->> 'name'; + + +insert into v.roon (content) +values + ('Hello World'), + ('PostgreSQL with PGroonga is a thing'), + ('This is a full-text search test'), + ('PGroonga supports various languages'); + +-- Create default index +create index pgroonga_index on v.roon using pgroonga (content); + +-- Create mecab tokenizer index since we had a bug with this one once +create index pgroonga_index on v.roon using pgroonga (content) with (tokenizer='TokenMecab'); + +-- Run some queries to test the index +select * from v.roon where content &@~ 'Hello'; +select * from v.roon where content &@~ 'powerful'; +select * from v.roon where content &@~ 'supports'; + + +drop schema v cascade; From 2bac7360ac980aa2c15ddb45268254c7765f0b35 Mon Sep 17 00:00:00 2001 From: Oliver Rice Date: Wed, 21 Aug 2024 16:01:57 -0500 Subject: [PATCH 2/2] add mecab test --- nix/tests/expected/pgroonga.out | 3 +-- nix/tests/sql/pgroonga.sql | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/nix/tests/expected/pgroonga.out b/nix/tests/expected/pgroonga.out index cc3ab40e4..5ceeed254 100644 --- a/nix/tests/expected/pgroonga.out +++ b/nix/tests/expected/pgroonga.out @@ -53,8 +53,7 @@ values -- Create default index create index pgroonga_index on v.roon using pgroonga (content); -- Create mecab tokenizer index since we had a bug with this one once -create index pgroonga_index on v.roon using pgroonga (content) with (tokenizer='TokenMecab'); -ERROR: relation "pgroonga_index" already exists +create index pgroonga_index_mecab on v.roon using pgroonga (content) with (tokenizer='TokenMecab'); -- Run some queries to test the index select * from v.roon where content &@~ 'Hello'; id | content diff --git a/nix/tests/sql/pgroonga.sql b/nix/tests/sql/pgroonga.sql index 6be430f53..503f2665c 100644 --- a/nix/tests/sql/pgroonga.sql +++ b/nix/tests/sql/pgroonga.sql @@ -37,7 +37,7 @@ values create index pgroonga_index on v.roon using pgroonga (content); -- Create mecab tokenizer index since we had a bug with this one once -create index pgroonga_index on v.roon using pgroonga (content) with (tokenizer='TokenMecab'); +create index pgroonga_index_mecab on v.roon using pgroonga (content) with (tokenizer='TokenMecab'); -- Run some queries to test the index select * from v.roon where content &@~ 'Hello';