Kouhei Sutou
null+****@clear*****
Wed Apr 26 17:13:59 JST 2017
Kouhei Sutou 2017-04-26 17:13:59 +0900 (Wed, 26 Apr 2017) New Revision: 59562374d54207d02dd872dc16d81e8f769ff613 https://github.com/pgroonga/pgroonga/commit/59562374d54207d02dd872dc16d81e8f769ff613 Message: Add "plugins" CREATE INDEX option Added files: expected/full-text-search/text/options/plugins/one.out expected/full-text-search/text/options/token-filters/custom.out expected/full-text-search/text/options/token-filters/empty.out expected/full-text-search/text/options/token-filters/none.out sql/full-text-search/text/options/plugins/one.sql sql/full-text-search/text/options/token-filters/custom.sql sql/full-text-search/text/options/token-filters/empty.sql sql/full-text-search/text/options/token-filters/none.sql Modified files: src/pgrn-options.c Added: expected/full-text-search/text/options/plugins/one.out (+14 -0) 100644 =================================================================== --- /dev/null +++ expected/full-text-search/text/options/plugins/one.out 2017-04-26 17:13:59 +0900 (4db5be0) @@ -0,0 +1,14 @@ +CREATE TABLE memos ( + id integer, + content text +); +CREATE INDEX pgrn_index ON memos + USING pgroonga (content) + WITH (plugins = 'query_expanders/tsv'); +SELECT pgroonga.command('object_exist QueryExpanderTSV')::json->>1; + ?column? +---------- + true +(1 row) + +DROP TABLE memos; Added: expected/full-text-search/text/options/token-filters/custom.out (+45 -0) 100644 =================================================================== --- /dev/null +++ expected/full-text-search/text/options/token-filters/custom.out 2017-04-26 17:13:59 +0900 (59e605a) @@ -0,0 +1,45 @@ +CREATE TABLE memos ( + id integer, + content text +); +INSERT INTO memos VALUES (1, 'It works.'); +INSERT INTO memos VALUES (2, 'I work.'); +INSERT INTO memos VALUES (3, 'I worked.'); +CREATE INDEX pgrn_index ON memos + USING pgroonga (content) + WITH (plugins = 'token_filters/stem', + token_filters = 'TokenFilterStem'); +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; +SELECT id, content + FROM memos + WHERE content %% 'works'; + id | content +----+----------- + 1 | It works. + 2 | I work. + 3 | I worked. +(3 rows) + +SELECT id, content + FROM memos + WHERE content %% 'work'; + id | content +----+----------- + 1 | It works. + 2 | I work. + 3 | I worked. +(3 rows) + +SELECT id, content + FROM memos + WHERE content %% 'worked'; + id | content +----+----------- + 1 | It works. + 2 | I work. + 3 | I worked. +(3 rows) + +DROP TABLE memos; Added: expected/full-text-search/text/options/token-filters/empty.out (+38 -0) 100644 =================================================================== --- /dev/null +++ expected/full-text-search/text/options/token-filters/empty.out 2017-04-26 17:13:59 +0900 (8baec3e) @@ -0,0 +1,38 @@ +CREATE TABLE memos ( + id integer, + content text +); +INSERT INTO memos VALUES (1, 'It works.'); +INSERT INTO memos VALUES (2, 'I work.'); +INSERT INTO memos VALUES (3, 'I worked.'); +CREATE INDEX pgrn_index ON memos + USING pgroonga (content) + WITH (token_filters = ''); +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; +SELECT id, content + FROM memos + WHERE content %% 'works'; + id | content +----+----------- + 1 | It works. +(1 row) + +SELECT id, content + FROM memos + WHERE content %% 'work'; + id | content +----+--------- + 2 | I work. +(1 row) + +SELECT id, content + FROM memos + WHERE content %% 'worked'; + id | content +----+----------- + 3 | I worked. +(1 row) + +DROP TABLE memos; Added: expected/full-text-search/text/options/token-filters/none.out (+38 -0) 100644 =================================================================== --- /dev/null +++ expected/full-text-search/text/options/token-filters/none.out 2017-04-26 17:13:59 +0900 (7203864) @@ -0,0 +1,38 @@ +CREATE TABLE memos ( + id integer, + content text +); +INSERT INTO memos VALUES (1, 'It works.'); +INSERT INTO memos VALUES (2, 'I work.'); +INSERT INTO memos VALUES (3, 'I worked.'); +CREATE INDEX pgrn_index ON memos + USING pgroonga (content) + WITH (token_filters = 'none'); +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; +SELECT id, content + FROM memos + WHERE content %% 'works'; + id | content +----+----------- + 1 | It works. +(1 row) + +SELECT id, content + FROM memos + WHERE content %% 'work'; + id | content +----+--------- + 2 | I work. +(1 row) + +SELECT id, content + FROM memos + WHERE content %% 'worked'; + id | content +----+----------- + 3 | I worked. +(1 row) + +DROP TABLE memos; Added: sql/full-text-search/text/options/plugins/one.sql (+12 -0) 100644 =================================================================== --- /dev/null +++ sql/full-text-search/text/options/plugins/one.sql 2017-04-26 17:13:59 +0900 (6cb230c) @@ -0,0 +1,12 @@ +CREATE TABLE memos ( + id integer, + content text +); + +CREATE INDEX pgrn_index ON memos + USING pgroonga (content) + WITH (plugins = 'query_expanders/tsv'); + +SELECT pgroonga.command('object_exist QueryExpanderTSV')::json->>1; + +DROP TABLE memos; Added: sql/full-text-search/text/options/token-filters/custom.sql (+31 -0) 100644 =================================================================== --- /dev/null +++ sql/full-text-search/text/options/token-filters/custom.sql 2017-04-26 17:13:59 +0900 (06e8a89) @@ -0,0 +1,31 @@ +CREATE TABLE memos ( + id integer, + content text +); + +INSERT INTO memos VALUES (1, 'It works.'); +INSERT INTO memos VALUES (2, 'I work.'); +INSERT INTO memos VALUES (3, 'I worked.'); + +CREATE INDEX pgrn_index ON memos + USING pgroonga (content) + WITH (plugins = 'token_filters/stem', + token_filters = 'TokenFilterStem'); + +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; + +SELECT id, content + FROM memos + WHERE content %% 'works'; + +SELECT id, content + FROM memos + WHERE content %% 'work'; + +SELECT id, content + FROM memos + WHERE content %% 'worked'; + +DROP TABLE memos; Added: sql/full-text-search/text/options/token-filters/empty.sql (+30 -0) 100644 =================================================================== --- /dev/null +++ sql/full-text-search/text/options/token-filters/empty.sql 2017-04-26 17:13:59 +0900 (66ee2f8) @@ -0,0 +1,30 @@ +CREATE TABLE memos ( + id integer, + content text +); + +INSERT INTO memos VALUES (1, 'It works.'); +INSERT INTO memos VALUES (2, 'I work.'); +INSERT INTO memos VALUES (3, 'I worked.'); + +CREATE INDEX pgrn_index ON memos + USING pgroonga (content) + WITH (token_filters = ''); + +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; + +SELECT id, content + FROM memos + WHERE content %% 'works'; + +SELECT id, content + FROM memos + WHERE content %% 'work'; + +SELECT id, content + FROM memos + WHERE content %% 'worked'; + +DROP TABLE memos; Added: sql/full-text-search/text/options/token-filters/none.sql (+30 -0) 100644 =================================================================== --- /dev/null +++ sql/full-text-search/text/options/token-filters/none.sql 2017-04-26 17:13:59 +0900 (45b5515) @@ -0,0 +1,30 @@ +CREATE TABLE memos ( + id integer, + content text +); + +INSERT INTO memos VALUES (1, 'It works.'); +INSERT INTO memos VALUES (2, 'I work.'); +INSERT INTO memos VALUES (3, 'I worked.'); + +CREATE INDEX pgrn_index ON memos + USING pgroonga (content) + WITH (token_filters = 'none'); + +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; + +SELECT id, content + FROM memos + WHERE content %% 'works'; + +SELECT id, content + FROM memos + WHERE content %% 'work'; + +SELECT id, content + FROM memos + WHERE content %% 'worked'; + +DROP TABLE memos; Modified: src/pgrn-options.c (+72 -36) =================================================================== --- src/pgrn-options.c 2017-04-13 20:54:20 +0900 (24925ca) +++ src/pgrn-options.c 2017-04-26 17:13:59 +0900 (1b0e022) @@ -17,6 +17,7 @@ typedef struct PGrnOptions int tokenizerOffset; int normalizerOffset; int tokenFiltersOffset; + int pluginsOffset; } PGrnOptions; static relopt_kind PGrnReloptionKind; @@ -25,6 +26,42 @@ static grn_ctx *ctx = &PGrnContext; PGRN_FUNCTION_INFO_V1(pgroonga_options); +typedef void (*PGrnOptionNameFunction)(const char *name, + size_t nameSize, + void *data); + +static void +PGrnOptionParseNames(const char *names, + PGrnOptionNameFunction function, + void *data) +{ + const char *start; + const char *current; + + if (PGrnIsNoneValue(names)) + return; + + for (start = current = names; current[0]; current++) + { + switch (current[0]) + { + case ' ': + start = current + 1; + break; + case ',': + function(start, current - start, data); + start = current + 1; + break; + default: + break; + } + } + + if (current > start) { + function(start, current - start, data); + } +} + static bool PGrnIsTokenizer(grn_obj *object) { @@ -137,48 +174,40 @@ PGrnOptionValidateTokenFilter(const char *name, size_t nameSize, void *data) } } -typedef void (*PGrnOptionTokenFilterNameFunction)(const char *name, - size_t nameSize, - void *data); - static void -PGrnOptionParseTokenFilterNames(const char *names, - PGrnOptionTokenFilterNameFunction function, - void *data) +PGrnOptionValidateTokenFilters(char *names) { - const char *start; - const char *current; + PGrnOptionParseNames(names, + PGrnOptionValidateTokenFilter, + NULL); +} - if (PGrnIsNoneValue(names)) - return; +static void +PGrnOptionValidatePlugin(const char *name, + size_t nameSize, + void *data) +{ + char pluginName[MAXPGPATH]; - for (start = current = names; current[0]; current++) + grn_strncpy(pluginName, MAXPGPATH, name, nameSize); + pluginName[nameSize] = '\0'; + grn_plugin_register(ctx, pluginName); + if (ctx->rc != GRN_SUCCESS) { - switch (current[0]) - { - case ' ': - start = current + 1; - break; - case ',': - function(start, current - start, data); - start = current + 1; - break; - default: - break; - } - } - - if (current > start) { - function(start, current - start, data); + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("pgroonga: failed to register plugin: <%.*s>: %s", + (int)nameSize, name, + ctx->errbuf))); } } static void -PGrnOptionValidateTokenFilters(char *names) +PGrnOptionValidatePlugins(char *names) { - PGrnOptionParseTokenFilterNames(names, - PGrnOptionValidateTokenFilter, - NULL); + PGrnOptionParseNames(names, + PGrnOptionValidatePlugin, + NULL); } #endif @@ -204,6 +233,11 @@ PGrnInitializeOptions(void) "to be used for full-text search", "", PGrnOptionValidateTokenFilters); + add_string_reloption(PGrnReloptionKind, + "plugins", + "Plugin names separated by \",\" to be installed", + "", + PGrnOptionValidatePlugins); #endif } @@ -287,9 +321,9 @@ PGrnApplyOptionValues(Relation index, *normalizer = PGrnLookup(normalizerName, ERROR); } - PGrnOptionParseTokenFilterNames(tokenFilterNames, - PGrnOptionCollectTokenFilter, - tokenFilters); + PGrnOptionParseNames(tokenFilterNames, + PGrnOptionCollectTokenFilter, + tokenFilters); #endif } @@ -307,7 +341,9 @@ pgroonga_options_raw(Datum reloptions, {"normalizer", RELOPT_TYPE_STRING, offsetof(PGrnOptions, normalizerOffset)}, {"token_filters", RELOPT_TYPE_STRING, - offsetof(PGrnOptions, tokenFiltersOffset)} + offsetof(PGrnOptions, tokenFiltersOffset)}, + {"plugins", RELOPT_TYPE_STRING, + offsetof(PGrnOptions, pluginsOffset)} }; options = parseRelOptions(reloptions, validate, PGrnReloptionKind, -------------- next part -------------- HTML����������������������������... Download