Skip to content

Commit bf6c370

Browse files
oliricesamrose
authored andcommitted
pgroonga mecab test (#1156)
* add mecab test * add mecab test
1 parent d12615e commit bf6c370

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

nix/tests/expected/pgroonga.out

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
create schema v;
2+
create table v.roon(
3+
id serial primary key,
4+
content text
5+
);
6+
with tokenizers as (
7+
select
8+
x
9+
from
10+
jsonb_array_elements(
11+
(select pgroonga_command('tokenizer_list'))::jsonb
12+
) x(val)
13+
limit
14+
1
15+
offset
16+
1 -- first record is unrelated and not stable
17+
)
18+
select
19+
t.x::jsonb ->> 'name'
20+
from
21+
jsonb_array_elements((select * from tokenizers)) t(x)
22+
order by
23+
t.x::jsonb ->> 'name';
24+
?column?
25+
---------------------------------------------
26+
TokenBigram
27+
TokenBigramIgnoreBlank
28+
TokenBigramIgnoreBlankSplitSymbol
29+
TokenBigramIgnoreBlankSplitSymbolAlpha
30+
TokenBigramIgnoreBlankSplitSymbolAlphaDigit
31+
TokenBigramSplitSymbol
32+
TokenBigramSplitSymbolAlpha
33+
TokenBigramSplitSymbolAlphaDigit
34+
TokenDelimit
35+
TokenDelimitNull
36+
TokenDocumentVectorBM25
37+
TokenDocumentVectorTFIDF
38+
TokenMecab
39+
TokenNgram
40+
TokenPattern
41+
TokenRegexp
42+
TokenTable
43+
TokenTrigram
44+
TokenUnigram
45+
(19 rows)
46+
47+
insert into v.roon (content)
48+
values
49+
('Hello World'),
50+
('PostgreSQL with PGroonga is a thing'),
51+
('This is a full-text search test'),
52+
('PGroonga supports various languages');
53+
-- Create default index
54+
create index pgroonga_index on v.roon using pgroonga (content);
55+
-- Create mecab tokenizer index since we had a bug with this one once
56+
create index pgroonga_index_mecab on v.roon using pgroonga (content) with (tokenizer='TokenMecab');
57+
-- Run some queries to test the index
58+
select * from v.roon where content &@~ 'Hello';
59+
id | content
60+
----+-------------
61+
1 | Hello World
62+
(1 row)
63+
64+
select * from v.roon where content &@~ 'powerful';
65+
id | content
66+
----+---------
67+
(0 rows)
68+
69+
select * from v.roon where content &@~ 'supports';
70+
id | content
71+
----+-------------------------------------
72+
4 | PGroonga supports various languages
73+
(1 row)
74+
75+
drop schema v cascade;
76+
NOTICE: drop cascades to table v.roon

nix/tests/sql/pgroonga.sql

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
create schema v;
2+
3+
create table v.roon(
4+
id serial primary key,
5+
content text
6+
);
7+
8+
9+
with tokenizers as (
10+
select
11+
x
12+
from
13+
jsonb_array_elements(
14+
(select pgroonga_command('tokenizer_list'))::jsonb
15+
) x(val)
16+
limit
17+
1
18+
offset
19+
1 -- first record is unrelated and not stable
20+
)
21+
select
22+
t.x::jsonb ->> 'name'
23+
from
24+
jsonb_array_elements((select * from tokenizers)) t(x)
25+
order by
26+
t.x::jsonb ->> 'name';
27+
28+
29+
insert into v.roon (content)
30+
values
31+
('Hello World'),
32+
('PostgreSQL with PGroonga is a thing'),
33+
('This is a full-text search test'),
34+
('PGroonga supports various languages');
35+
36+
-- Create default index
37+
create index pgroonga_index on v.roon using pgroonga (content);
38+
39+
-- Create mecab tokenizer index since we had a bug with this one once
40+
create index pgroonga_index_mecab on v.roon using pgroonga (content) with (tokenizer='TokenMecab');
41+
42+
-- Run some queries to test the index
43+
select * from v.roon where content &@~ 'Hello';
44+
select * from v.roon where content &@~ 'powerful';
45+
select * from v.roon where content &@~ 'supports';
46+
47+
48+
drop schema v cascade;

0 commit comments

Comments
 (0)