Kouhei Sutou
null+****@clear*****
Tue May 31 22:49:28 JST 2016
Kouhei Sutou 2016-05-31 22:49:28 +0900 (Tue, 31 May 2016) New Revision: b125596c4a7901972f743636e8b8069a3a51b63d https://github.com/pgroonga/pgroonga/commit/b125596c4a7901972f743636e8b8069a3a51b63d Message: Support prefix search and prefix RK search for text[] Added files: expected/term-search/text-array/combined/bitmapscan.out expected/term-search/text-array/combined/indexscan.out expected/term-search/text-array/combined/seqscan.out expected/term-search/text-array/prefix-rk/bitmapscan.out expected/term-search/text-array/prefix-rk/indexscan.out expected/term-search/text-array/prefix-rk/seqscan.out expected/term-search/text-array/prefix/bitmapscan.out expected/term-search/text-array/prefix/indexscan.out expected/term-search/text-array/prefix/seqscan.out sql/term-search/text-array/combined/bitmapscan.sql sql/term-search/text-array/combined/indexscan.sql sql/term-search/text-array/combined/seqscan.sql sql/term-search/text-array/prefix-rk/bitmapscan.sql sql/term-search/text-array/prefix-rk/indexscan.sql sql/term-search/text-array/prefix-rk/seqscan.sql sql/term-search/text-array/prefix/bitmapscan.sql sql/term-search/text-array/prefix/indexscan.sql sql/term-search/text-array/prefix/seqscan.sql Modified files: pgroonga.sql src/pgroonga.c src/pgroonga.h Added: expected/term-search/text-array/combined/bitmapscan.out (+32 -0) 100644 =================================================================== --- /dev/null +++ expected/term-search/text-array/combined/bitmapscan.out 2016-05-31 22:49:28 +0900 (e8294d9) @@ -0,0 +1,32 @@ +CREATE TABLE tags ( + id int PRIMARY KEY, + names text[], + readings text[] +); +INSERT INTO tags VALUES (1, + ARRAY['PostgreSQL', 'PG'], + ARRAY['ポストグレスキューエル', 'ポスグレ']); +INSERT INTO tags VALUES (2, + ARRAY['Groonga', 'grn'], + ARRAY['グルンガ', 'グルン']); +INSERT INTO tags VALUES (3, + ARRAY['PGroonga', 'pgrn'], + ARRAY['ピージルンガ', 'ピーグルン']); +CREATE INDEX pgrn_tags_index ON tags + USING pgroonga (id, + names pgroonga.text_array_term_search_ops_v2, + readings pgroonga.text_array_term_search_ops_v2); +SET enable_seqscan = off; +SET enable_indexscan = off; +SET enable_bitmapscan = on; +SELECT names, pgroonga.score(tags) + FROM tags + WHERE names &^ 'Groon' OR + readings &^~ 'posu'; + names | score +-----------------+------- + {PostgreSQL,PG} | 2 + {Groonga,grn} | 1 +(2 rows) + +DROP TABLE tags; Added: expected/term-search/text-array/combined/indexscan.out (+32 -0) 100644 =================================================================== --- /dev/null +++ expected/term-search/text-array/combined/indexscan.out 2016-05-31 22:49:28 +0900 (b09f461) @@ -0,0 +1,32 @@ +CREATE TABLE tags ( + id int PRIMARY KEY, + names text[], + readings text[] +); +INSERT INTO tags VALUES (1, + ARRAY['PostgreSQL', 'PG'], + ARRAY['ポストグレスキューエル', 'ポスグレ']); +INSERT INTO tags VALUES (2, + ARRAY['Groonga', 'grn'], + ARRAY['グルンガ', 'グルン']); +INSERT INTO tags VALUES (3, + ARRAY['PGroonga', 'pgrn'], + ARRAY['ピージルンガ', 'ピーグルン']); +CREATE INDEX pgrn_tags_index ON tags + USING pgroonga (id, + names pgroonga.text_array_term_search_ops_v2, + readings pgroonga.text_array_term_search_ops_v2); +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; +SELECT names, pgroonga.score(tags) + FROM tags + WHERE names &^ 'Groon' OR + readings &^~ 'posu'; + names | score +-----------------+------- + {PostgreSQL,PG} | 0 + {Groonga,grn} | 0 +(2 rows) + +DROP TABLE tags; Added: expected/term-search/text-array/combined/seqscan.out (+28 -0) 100644 =================================================================== --- /dev/null +++ expected/term-search/text-array/combined/seqscan.out 2016-05-31 22:49:28 +0900 (6c40a43) @@ -0,0 +1,28 @@ +CREATE TABLE tags ( + id int PRIMARY KEY, + names text[], + readings text[] +); +INSERT INTO tags VALUES (1, + ARRAY['PostgreSQL', 'PG'], + ARRAY['ポストグレスキューエル', 'ポスグレ']); +INSERT INTO tags VALUES (2, + ARRAY['Groonga', 'grn'], + ARRAY['グルンガ', 'グルン']); +INSERT INTO tags VALUES (3, + ARRAY['PGroonga', 'pgrn'], + ARRAY['ピージルンガ', 'ピーグルン']); +SET enable_seqscan = on; +SET enable_indexscan = off; +SET enable_bitmapscan = off; +SELECT names, pgroonga.score(tags) + FROM tags + WHERE names &^ 'Groon' OR + readings &^~ 'posu'; + names | score +-----------------+------- + {PostgreSQL,PG} | 0 + {Groonga,grn} | 0 +(2 rows) + +DROP TABLE tags; Added: expected/term-search/text-array/prefix-rk/bitmapscan.out (+21 -0) 100644 =================================================================== --- /dev/null +++ expected/term-search/text-array/prefix-rk/bitmapscan.out 2016-05-31 22:49:28 +0900 (93d4dcc) @@ -0,0 +1,21 @@ +CREATE TABLE readings ( + katakanas text[] +); +INSERT INTO readings VALUES (ARRAY['ポストグレスキューエル', 'ポスグレ']); +INSERT INTO readings VALUES (ARRAY['グルンガ', 'グルン']); +INSERT INTO readings VALUES (ARRAY['ピージールンガ', 'ピーグルン']); +CREATE INDEX pgrn_index ON readings + USING pgroonga (katakanas pgroonga.text_array_term_search_ops_v2); +SET enable_seqscan = off; +SET enable_indexscan = off; +SET enable_bitmapscan = on; +SELECT katakanas + FROM readings + WHERE katakanas &^~ 'p'; + katakanas +----------------------------------- + {ポストグレスキューエル,ポスグレ} + {ピージールンガ,ピーグルン} +(2 rows) + +DROP TABLE readings; Added: expected/term-search/text-array/prefix-rk/indexscan.out (+21 -0) 100644 =================================================================== --- /dev/null +++ expected/term-search/text-array/prefix-rk/indexscan.out 2016-05-31 22:49:28 +0900 (809724a) @@ -0,0 +1,21 @@ +CREATE TABLE readings ( + katakanas text[] +); +INSERT INTO readings VALUES (ARRAY['ポストグレスキューエル', 'ポスグレ']); +INSERT INTO readings VALUES (ARRAY['グルンガ', 'グルン']); +INSERT INTO readings VALUES (ARRAY['ピージールンガ', 'ピーグルン']); +CREATE INDEX pgrn_index ON readings + USING pgroonga (katakanas pgroonga.text_array_term_search_ops_v2); +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; +SELECT katakanas + FROM readings + WHERE katakanas &^~ 'p'; + katakanas +----------------------------------- + {ピージールンガ,ピーグルン} + {ポストグレスキューエル,ポスグレ} +(2 rows) + +DROP TABLE readings; Added: expected/term-search/text-array/prefix-rk/seqscan.out (+19 -0) 100644 =================================================================== --- /dev/null +++ expected/term-search/text-array/prefix-rk/seqscan.out 2016-05-31 22:49:28 +0900 (b0fe3e0) @@ -0,0 +1,19 @@ +CREATE TABLE readings ( + katakanas text[] +); +INSERT INTO readings VALUES (ARRAY['ポストグレスキューエル', 'ポスグレ']); +INSERT INTO readings VALUES (ARRAY['グルンガ', 'グルン']); +INSERT INTO readings VALUES (ARRAY['ピージールンガ', 'ピーグルン']); +SET enable_seqscan = on; +SET enable_indexscan = off; +SET enable_bitmapscan = off; +SELECT katakanas + FROM readings + WHERE katakanas &^~ 'p'; + katakanas +----------------------------------- + {ポストグレスキューエル,ポスグレ} + {ピージールンガ,ピーグルン} +(2 rows) + +DROP TABLE readings; Added: expected/term-search/text-array/prefix/bitmapscan.out (+21 -0) 100644 =================================================================== --- /dev/null +++ expected/term-search/text-array/prefix/bitmapscan.out 2016-05-31 22:49:28 +0900 (5314daf) @@ -0,0 +1,21 @@ +CREATE TABLE tags ( + names text[] +); +INSERT INTO tags VALUES (ARRAY['PostgreSQL', 'PG']); +INSERT INTO tags VALUES (ARRAY['Groonga', 'grn']); +INSERT INTO tags VALUES (ARRAY['PGroonga', 'pgrn']); +CREATE INDEX pgrn_index ON tags + USING pgroonga (names pgroonga.text_array_term_search_ops_v2); +SET enable_seqscan = off; +SET enable_indexscan = off; +SET enable_bitmapscan = on; +SELECT names + FROM tags + WHERE names &^ 'pG'; + names +----------------- + {PostgreSQL,PG} + {PGroonga,pgrn} +(2 rows) + +DROP TABLE tags; Added: expected/term-search/text-array/prefix/indexscan.out (+21 -0) 100644 =================================================================== --- /dev/null +++ expected/term-search/text-array/prefix/indexscan.out 2016-05-31 22:49:28 +0900 (f84a7d0) @@ -0,0 +1,21 @@ +CREATE TABLE tags ( + names text[] +); +INSERT INTO tags VALUES (ARRAY['PostgreSQL', 'PG']); +INSERT INTO tags VALUES (ARRAY['Groonga', 'grn']); +INSERT INTO tags VALUES (ARRAY['PGroonga', 'pgrn']); +CREATE INDEX pgrn_index ON tags + USING pgroonga (names pgroonga.text_array_term_search_ops_v2); +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; +SELECT names + FROM tags + WHERE names &^ 'pG'; + names +----------------- + {PGroonga,pgrn} + {PostgreSQL,PG} +(2 rows) + +DROP TABLE tags; Added: expected/term-search/text-array/prefix/seqscan.out (+19 -0) 100644 =================================================================== --- /dev/null +++ expected/term-search/text-array/prefix/seqscan.out 2016-05-31 22:49:28 +0900 (d927967) @@ -0,0 +1,19 @@ +CREATE TABLE tags ( + names text[] +); +INSERT INTO tags VALUES (ARRAY['PostgreSQL', 'PG']); +INSERT INTO tags VALUES (ARRAY['Groonga', 'grn']); +INSERT INTO tags VALUES (ARRAY['PGroonga', 'pgrn']); +SET enable_seqscan = on; +SET enable_indexscan = off; +SET enable_bitmapscan = off; +SELECT names + FROM tags + WHERE names &^ 'pG'; + names +----------------- + {PostgreSQL,PG} + {PGroonga,pgrn} +(2 rows) + +DROP TABLE tags; Modified: pgroonga.sql (+31 -0) =================================================================== --- pgroonga.sql 2016-05-27 16:12:13 +0900 (20f9068) +++ pgroonga.sql 2016-05-31 22:49:28 +0900 (3aaf01c) @@ -469,6 +469,19 @@ CREATE OPERATOR &^ ( RIGHTARG = text ); +CREATE FUNCTION pgroonga.prefix_text_array(text[], text) + RETURNS bool + AS 'MODULE_PATHNAME', 'pgroonga_prefix_text_array' + LANGUAGE C + IMMUTABLE + STRICT; + +CREATE OPERATOR &^ ( + PROCEDURE = pgroonga.prefix_text_array, + LEFTARG = text[], + RIGHTARG = text +); + CREATE FUNCTION pgroonga.prefix_rk_text(text, text) RETURNS bool AS 'MODULE_PATHNAME', 'pgroonga_prefix_rk_text' @@ -482,6 +495,19 @@ CREATE OPERATOR &^~ ( RIGHTARG = text ); +CREATE FUNCTION pgroonga.prefix_rk_text_array(text[], text) + RETURNS bool + AS 'MODULE_PATHNAME', 'pgroonga_prefix_rk_text_array' + LANGUAGE C + IMMUTABLE + STRICT; + +CREATE OPERATOR &^~ ( + PROCEDURE = pgroonga.prefix_rk_text_array, + LEFTARG = text[], + RIGHTARG = text +); + CREATE FUNCTION pgroonga.script_text(text, text) RETURNS bool AS 'MODULE_PATHNAME', 'pgroonga_script_text' @@ -536,3 +562,8 @@ CREATE OPERATOR CLASS pgroonga.text_term_search_ops_v2 FOR TYPE text USING pgroonga AS OPERATOR 16 &^, OPERATOR 17 &^~; + +CREATE OPERATOR CLASS pgroonga.text_array_term_search_ops_v2 FOR TYPE text[] + USING pgroonga AS + OPERATOR 16 &^ (text[], text), + OPERATOR 17 &^~ (text[], text); Added: sql/term-search/text-array/combined/bitmapscan.sql (+31 -0) 100644 =================================================================== --- /dev/null +++ sql/term-search/text-array/combined/bitmapscan.sql 2016-05-31 22:49:28 +0900 (9150b0c) @@ -0,0 +1,31 @@ +CREATE TABLE tags ( + id int PRIMARY KEY, + names text[], + readings text[] +); + +INSERT INTO tags VALUES (1, + ARRAY['PostgreSQL', 'PG'], + ARRAY['ポストグレスキューエル', 'ポスグレ']); +INSERT INTO tags VALUES (2, + ARRAY['Groonga', 'grn'], + ARRAY['グルンガ', 'グルン']); +INSERT INTO tags VALUES (3, + ARRAY['PGroonga', 'pgrn'], + ARRAY['ピージルンガ', 'ピーグルン']); + +CREATE INDEX pgrn_tags_index ON tags + USING pgroonga (id, + names pgroonga.text_array_term_search_ops_v2, + readings pgroonga.text_array_term_search_ops_v2); + +SET enable_seqscan = off; +SET enable_indexscan = off; +SET enable_bitmapscan = on; + +SELECT names, pgroonga.score(tags) + FROM tags + WHERE names &^ 'Groon' OR + readings &^~ 'posu'; + +DROP TABLE tags; Added: sql/term-search/text-array/combined/indexscan.sql (+31 -0) 100644 =================================================================== --- /dev/null +++ sql/term-search/text-array/combined/indexscan.sql 2016-05-31 22:49:28 +0900 (adf356c) @@ -0,0 +1,31 @@ +CREATE TABLE tags ( + id int PRIMARY KEY, + names text[], + readings text[] +); + +INSERT INTO tags VALUES (1, + ARRAY['PostgreSQL', 'PG'], + ARRAY['ポストグレスキューエル', 'ポスグレ']); +INSERT INTO tags VALUES (2, + ARRAY['Groonga', 'grn'], + ARRAY['グルンガ', 'グルン']); +INSERT INTO tags VALUES (3, + ARRAY['PGroonga', 'pgrn'], + ARRAY['ピージルンガ', 'ピーグルン']); + +CREATE INDEX pgrn_tags_index ON tags + USING pgroonga (id, + names pgroonga.text_array_term_search_ops_v2, + readings pgroonga.text_array_term_search_ops_v2); + +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; + +SELECT names, pgroonga.score(tags) + FROM tags + WHERE names &^ 'Groon' OR + readings &^~ 'posu'; + +DROP TABLE tags; Added: sql/term-search/text-array/combined/seqscan.sql (+26 -0) 100644 =================================================================== --- /dev/null +++ sql/term-search/text-array/combined/seqscan.sql 2016-05-31 22:49:28 +0900 (f30eace) @@ -0,0 +1,26 @@ +CREATE TABLE tags ( + id int PRIMARY KEY, + names text[], + readings text[] +); + +INSERT INTO tags VALUES (1, + ARRAY['PostgreSQL', 'PG'], + ARRAY['ポストグレスキューエル', 'ポスグレ']); +INSERT INTO tags VALUES (2, + ARRAY['Groonga', 'grn'], + ARRAY['グルンガ', 'グルン']); +INSERT INTO tags VALUES (3, + ARRAY['PGroonga', 'pgrn'], + ARRAY['ピージルンガ', 'ピーグルン']); + +SET enable_seqscan = on; +SET enable_indexscan = off; +SET enable_bitmapscan = off; + +SELECT names, pgroonga.score(tags) + FROM tags + WHERE names &^ 'Groon' OR + readings &^~ 'posu'; + +DROP TABLE tags; Added: sql/term-search/text-array/prefix-rk/bitmapscan.sql (+20 -0) 100644 =================================================================== --- /dev/null +++ sql/term-search/text-array/prefix-rk/bitmapscan.sql 2016-05-31 22:49:28 +0900 (4646b3e) @@ -0,0 +1,20 @@ +CREATE TABLE readings ( + katakanas text[] +); + +INSERT INTO readings VALUES (ARRAY['ポストグレスキューエル', 'ポスグレ']); +INSERT INTO readings VALUES (ARRAY['グルンガ', 'グルン']); +INSERT INTO readings VALUES (ARRAY['ピージールンガ', 'ピーグルン']); + +CREATE INDEX pgrn_index ON readings + USING pgroonga (katakanas pgroonga.text_array_term_search_ops_v2); + +SET enable_seqscan = off; +SET enable_indexscan = off; +SET enable_bitmapscan = on; + +SELECT katakanas + FROM readings + WHERE katakanas &^~ 'p'; + +DROP TABLE readings; Added: sql/term-search/text-array/prefix-rk/indexscan.sql (+20 -0) 100644 =================================================================== --- /dev/null +++ sql/term-search/text-array/prefix-rk/indexscan.sql 2016-05-31 22:49:28 +0900 (4cce51f) @@ -0,0 +1,20 @@ +CREATE TABLE readings ( + katakanas text[] +); + +INSERT INTO readings VALUES (ARRAY['ポストグレスキューエル', 'ポスグレ']); +INSERT INTO readings VALUES (ARRAY['グルンガ', 'グルン']); +INSERT INTO readings VALUES (ARRAY['ピージールンガ', 'ピーグルン']); + +CREATE INDEX pgrn_index ON readings + USING pgroonga (katakanas pgroonga.text_array_term_search_ops_v2); + +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; + +SELECT katakanas + FROM readings + WHERE katakanas &^~ 'p'; + +DROP TABLE readings; Added: sql/term-search/text-array/prefix-rk/seqscan.sql (+17 -0) 100644 =================================================================== --- /dev/null +++ sql/term-search/text-array/prefix-rk/seqscan.sql 2016-05-31 22:49:28 +0900 (63fcad9) @@ -0,0 +1,17 @@ +CREATE TABLE readings ( + katakanas text[] +); + +INSERT INTO readings VALUES (ARRAY['ポストグレスキューエル', 'ポスグレ']); +INSERT INTO readings VALUES (ARRAY['グルンガ', 'グルン']); +INSERT INTO readings VALUES (ARRAY['ピージールンガ', 'ピーグルン']); + +SET enable_seqscan = on; +SET enable_indexscan = off; +SET enable_bitmapscan = off; + +SELECT katakanas + FROM readings + WHERE katakanas &^~ 'p'; + +DROP TABLE readings; Added: sql/term-search/text-array/prefix/bitmapscan.sql (+20 -0) 100644 =================================================================== --- /dev/null +++ sql/term-search/text-array/prefix/bitmapscan.sql 2016-05-31 22:49:28 +0900 (0f7e33b) @@ -0,0 +1,20 @@ +CREATE TABLE tags ( + names text[] +); + +INSERT INTO tags VALUES (ARRAY['PostgreSQL', 'PG']); +INSERT INTO tags VALUES (ARRAY['Groonga', 'grn']); +INSERT INTO tags VALUES (ARRAY['PGroonga', 'pgrn']); + +CREATE INDEX pgrn_index ON tags + USING pgroonga (names pgroonga.text_array_term_search_ops_v2); + +SET enable_seqscan = off; +SET enable_indexscan = off; +SET enable_bitmapscan = on; + +SELECT names + FROM tags + WHERE names &^ 'pG'; + +DROP TABLE tags; Added: sql/term-search/text-array/prefix/indexscan.sql (+20 -0) 100644 =================================================================== --- /dev/null +++ sql/term-search/text-array/prefix/indexscan.sql 2016-05-31 22:49:28 +0900 (b3b5ffe) @@ -0,0 +1,20 @@ +CREATE TABLE tags ( + names text[] +); + +INSERT INTO tags VALUES (ARRAY['PostgreSQL', 'PG']); +INSERT INTO tags VALUES (ARRAY['Groonga', 'grn']); +INSERT INTO tags VALUES (ARRAY['PGroonga', 'pgrn']); + +CREATE INDEX pgrn_index ON tags + USING pgroonga (names pgroonga.text_array_term_search_ops_v2); + +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; + +SELECT names + FROM tags + WHERE names &^ 'pG'; + +DROP TABLE tags; Added: sql/term-search/text-array/prefix/seqscan.sql (+17 -0) 100644 =================================================================== --- /dev/null +++ sql/term-search/text-array/prefix/seqscan.sql 2016-05-31 22:49:28 +0900 (ac5ea89) @@ -0,0 +1,17 @@ +CREATE TABLE tags ( + names text[] +); + +INSERT INTO tags VALUES (ARRAY['PostgreSQL', 'PG']); +INSERT INTO tags VALUES (ARRAY['Groonga', 'grn']); +INSERT INTO tags VALUES (ARRAY['PGroonga', 'pgrn']); + +SET enable_seqscan = on; +SET enable_indexscan = off; +SET enable_bitmapscan = off; + +SELECT names + FROM tags + WHERE names &^ 'pG'; + +DROP TABLE tags; Modified: src/pgroonga.c (+90 -1) =================================================================== --- src/pgroonga.c 2016-05-27 16:12:13 +0900 (a665b6a) +++ src/pgroonga.c 2016-05-31 22:49:28 +0900 (49f90b2) @@ -161,7 +161,9 @@ PG_FUNCTION_INFO_V1(pgroonga_query_text); PG_FUNCTION_INFO_V1(pgroonga_similar_text); PG_FUNCTION_INFO_V1(pgroonga_script_text); PG_FUNCTION_INFO_V1(pgroonga_prefix_text); +PG_FUNCTION_INFO_V1(pgroonga_prefix_text_array); PG_FUNCTION_INFO_V1(pgroonga_prefix_rk_text); +PG_FUNCTION_INFO_V1(pgroonga_prefix_rk_text_array); PG_FUNCTION_INFO_V1(pgroonga_match_contain_text); PG_FUNCTION_INFO_V1(pgroonga_query_contain_text); @@ -751,7 +753,20 @@ PGrnIsForPrefixSearchIndex(Relation index, int nthAttribute) Oid rightType; leftType = index->rd_opcintype[nthAttribute]; - rightType = leftType; + + switch (leftType) + { + case VARCHARARRAYOID: + rightType = VARCHAROID; + break; + case TEXTARRAYOID: + rightType = TEXTOID; + break; + default: + rightType = leftType; + break; + } + prefixStrategyOID = get_opfamily_member(index->rd_opfamily[nthAttribute], leftType, rightType, @@ -1657,6 +1672,44 @@ pgroonga_prefix_text(PG_FUNCTION_ARGS) PG_RETURN_BOOL(matched); } + +/** + * pgroonga.prefix_text_array(targets text[], prefix text) : bool + */ +Datum +pgroonga_prefix_text_array(PG_FUNCTION_ARGS) +{ + ArrayType *targets = PG_GETARG_ARRAYTYPE_P(0); + text *prefix = PG_GETARG_TEXT_PP(1); + bool matched = false; + + int i, n; + + n = ARR_DIMS(targets)[0]; + for (i = 1; i <= n; i++) + { + Datum targetDatum; + text *target; + bool isNULL; + + targetDatum = array_ref(targets, 1, &i, -1, -1, false, 'i', &isNULL); + if (isNULL) + continue; + + target = DatumGetTextPP(targetDatum); + matched = pgroonga_prefix_raw(VARDATA_ANY(target), + VARSIZE_ANY_EXHDR(target), + VARDATA_ANY(prefix), + VARSIZE_ANY_EXHDR(prefix)); + if (matched) + { + break; + } + } + + PG_RETURN_BOOL(matched); +} + static grn_bool pgroonga_prefix_rk_raw(const char *text, unsigned int textSize, const char *prefix, unsigned int prefixSize) @@ -1729,6 +1782,42 @@ pgroonga_prefix_rk_text(PG_FUNCTION_ARGS) } /** + * pgroonga.prefix_rk_text_array(targets text[], prefix text) : bool + */ +Datum +pgroonga_prefix_rk_text_array(PG_FUNCTION_ARGS) +{ + ArrayType *targets = PG_GETARG_ARRAYTYPE_P(0); + text *prefix = PG_GETARG_TEXT_PP(1); + bool matched = false; + int i, n; + + n = ARR_DIMS(targets)[0]; + for (i = 1; i <= n; i++) + { + Datum targetDatum; + text *target; + bool isNULL; + + targetDatum = array_ref(targets, 1, &i, -1, -1, false, 'i', &isNULL); + if (isNULL) + continue; + + target = DatumGetTextPP(targetDatum); + matched = pgroonga_prefix_rk_raw(VARDATA_ANY(target), + VARSIZE_ANY_EXHDR(target), + VARDATA_ANY(prefix), + VARSIZE_ANY_EXHDR(prefix)); + if (matched) + { + break; + } + } + + PG_RETURN_BOOL(matched); +} + +/** * pgroonga.match_contain_text(target text, keywords text[]) : bool */ Datum Modified: src/pgroonga.h (+2 -0) =================================================================== --- src/pgroonga.h 2016-05-27 16:12:13 +0900 (fbc7a12) +++ src/pgroonga.h 2016-05-31 22:49:28 +0900 (30cb638) @@ -79,7 +79,9 @@ extern Datum PGDLLEXPORT pgroonga_query_text(PG_FUNCTION_ARGS); extern Datum PGDLLEXPORT pgroonga_similar_text(PG_FUNCTION_ARGS); extern Datum PGDLLEXPORT pgroonga_script_text(PG_FUNCTION_ARGS); extern Datum PGDLLEXPORT pgroonga_prefix_text(PG_FUNCTION_ARGS); +extern Datum PGDLLEXPORT pgroonga_prefix_text_array(PG_FUNCTION_ARGS); extern Datum PGDLLEXPORT pgroonga_prefix_rk_text(PG_FUNCTION_ARGS); +extern Datum PGDLLEXPORT pgroonga_prefix_rk_text_array(PG_FUNCTION_ARGS); extern Datum PGDLLEXPORT pgroonga_match_contain_text(PG_FUNCTION_ARGS); extern Datum PGDLLEXPORT pgroonga_query_contain_text(PG_FUNCTION_ARGS); -------------- next part -------------- HTML����������������������������... 下載