Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #850 from komainu8/add_check_exist_with_section_flag
Browse files Browse the repository at this point in the history
Add check exist of "WITH SECTION" flag when a full-text search for vector column

Patch by Yasuhiro Horimoto. Thanks!!!
  • Loading branch information
kou committed Jun 25, 2018
2 parents dec278a + 08e2456 commit 8a52f23
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 125 deletions.
55 changes: 50 additions & 5 deletions lib/db.c
Expand Up @@ -8804,6 +8804,7 @@ grn_obj_set_info_source_validate(grn_ctx *ctx, grn_obj *obj, grn_obj *value)
grn_obj *lexicon_domain = NULL;
grn_bool lexicon_domain_is_table;
grn_bool lexicon_have_tokenizer;
grn_bool is_full_text_search_index;
grn_id *source_ids;
int i, n_source_ids;

Expand All @@ -8818,9 +8819,20 @@ grn_obj_set_info_source_validate(grn_ctx *ctx, grn_obj *obj, grn_obj *value)
if (!lexicon_domain) {
goto exit;
}
lexicon_domain_is_table = grn_obj_is_table(ctx, lexicon_domain);
{
grn_obj *tokenizer;
grn_table_get_info(ctx, lexicon, NULL, NULL, &tokenizer, NULL, NULL);
lexicon_have_tokenizer = (tokenizer != NULL);
}
is_full_text_search_index =
(grn_obj_is_index_column(ctx, obj) &&
(obj->header.flags & GRN_OBJ_WITH_POSITION) &&
lexicon_have_tokenizer);

source_ids = (grn_id *)GRN_BULK_HEAD(value);
n_source_ids = GRN_BULK_VSIZE(value) / sizeof(grn_id);

if (n_source_ids > 1 && !(obj->header.flags & GRN_OBJ_WITH_SECTION)) {
char index_name[GRN_TABLE_MAX_KEY_SIZE];
int index_name_size;
Expand All @@ -8833,11 +8845,44 @@ grn_obj_set_info_source_validate(grn_ctx *ctx, grn_obj *obj, grn_obj *value)
goto exit;
}

lexicon_domain_is_table = grn_obj_is_table(ctx, lexicon_domain);
{
grn_obj *tokenizer;
grn_table_get_info(ctx, lexicon, NULL, NULL, &tokenizer, NULL, NULL);
lexicon_have_tokenizer = (tokenizer != NULL);
if (is_full_text_search_index) {
grn_bool have_vector_source_column = GRN_FALSE;

for (i = 0; i < n_source_ids; i++) {
grn_obj *source;

source = grn_ctx_at(ctx, source_ids[i]);
if (!grn_obj_is_vector_column(ctx, source)) {
continue;
}

have_vector_source_column = GRN_TRUE;
if (!(obj->header.flags & GRN_OBJ_WITH_SECTION)) {
char index_name[GRN_TABLE_MAX_KEY_SIZE];
int index_name_size;
index_name_size = grn_obj_name(ctx, obj,
index_name, GRN_TABLE_MAX_KEY_SIZE);
ERR(GRN_INVALID_ARGUMENT,
"grn_obj_set_info(): GRN_INFO_SOURCE: "
"full text index for vector column "
"must be created with WITH_SECTION flag: <%.*s>",
index_name_size, index_name);
goto exit;
}
}

if (have_vector_source_column && n_source_ids > 1) {
char index_name[GRN_TABLE_MAX_KEY_SIZE];
int index_name_size;
index_name_size = grn_obj_name(ctx, obj,
index_name, GRN_TABLE_MAX_KEY_SIZE);
ERR(GRN_INVALID_ARGUMENT,
"grn_obj_set_info(): GRN_INFO_SOURCE: "
"multi column full text index with vector column isn't supported yet: "
"<%.*s>",
index_name_size, index_name);
goto exit;
}
}

for (i = 0; i < n_source_ids; i++) {
Expand Down
@@ -0,0 +1,23 @@
plugin_register functions/index_column
[[0,0.0,0.0],true]
table_create Docs TABLE_NO_KEY
[[0,0.0,0.0],true]
column_create Docs title COLUMN_SCALAR ShortText
[[0,0.0,0.0],true]
column_create Docs sentences COLUMN_VECTOR Text
[[0,0.0,0.0],true]
table_create Words TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram
[[0,0.0,0.0],true]
column_create Words docs_content COLUMN_INDEX|WITH_SECTION|WITH_POSITION Docs title,sentences
[
[
[
-22,
0.0,
0.0
],
"grn_obj_set_info(): GRN_INFO_SOURCE: multi column full text index with vector column isn't supported yet: <Words.docs_content>"
],
false
]
#|e| grn_obj_set_info(): GRN_INFO_SOURCE: multi column full text index with vector column isn't supported yet: <Words.docs_content>
@@ -0,0 +1,9 @@
plugin_register functions/index_column

table_create Docs TABLE_NO_KEY
column_create Docs title COLUMN_SCALAR ShortText
column_create Docs sentences COLUMN_VECTOR Text

table_create Words TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram
column_create Words docs_content \
COLUMN_INDEX|WITH_SECTION|WITH_POSITION Docs title,sentences
@@ -0,0 +1,10 @@
plugin_register functions/index_column
[[0,0.0,0.0],true]
table_create Docs TABLE_NO_KEY
[[0,0.0,0.0],true]
column_create Docs sentences COLUMN_VECTOR Text
[[0,0.0,0.0],true]
table_create Words TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram
[[0,0.0,0.0],true]
column_create Words docs_sentences COLUMN_INDEX|WITH_SECTION|WITH_POSITION Docs sentences
[[0,0.0,0.0],true]
@@ -0,0 +1,7 @@
plugin_register functions/index_column

table_create Docs TABLE_NO_KEY
column_create Docs sentences COLUMN_VECTOR Text

table_create Words TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram
column_create Words docs_sentences COLUMN_INDEX|WITH_SECTION|WITH_POSITION Docs sentences
@@ -0,0 +1,21 @@
plugin_register functions/index_column
[[0,0.0,0.0],true]
table_create Docs TABLE_NO_KEY
[[0,0.0,0.0],true]
column_create Docs sentences COLUMN_VECTOR Text
[[0,0.0,0.0],true]
table_create Words TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram
[[0,0.0,0.0],true]
column_create Words docs_sentences COLUMN_INDEX|WITH_POSITION Docs sentences
[
[
[
-22,
0.0,
0.0
],
"grn_obj_set_info(): GRN_INFO_SOURCE: full text index for vector column must be created with WITH_SECTION flag: <Words.docs_sent"
],
false
]
#|e| grn_obj_set_info(): GRN_INFO_SOURCE: full text index for vector column must be created with WITH_SECTION flag: <Words.docs_sentences>
Expand Up @@ -3,15 +3,5 @@ plugin_register functions/index_column
table_create Docs TABLE_NO_KEY
column_create Docs sentences COLUMN_VECTOR Text

load --table Docs
[
{"sentences": ["-", "-", "-"]}
]

table_create Words TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram
column_create Words docs_sentences COLUMN_INDEX|WITH_POSITION Docs sentences

select Words \
--limit -1 \
--sort_keys _key \
--output_columns '_key, index_column_source_records("docs_sentences")'

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion test/unit/core/test-command-select.c
Expand Up @@ -162,7 +162,7 @@ test_vector_text(void)
"TABLE_PAT_KEY|KEY_NORMALIZE ShortText "
"--default_tokenizer TokenBigram");
assert_send_command("column_create Terms Blogs_articles "
"COLUMN_INDEX|WITH_POSITION Blogs articles");
"COLUMN_INDEX|WITH_POSITION|WITH_SECTION Blogs articles");

assert_send_command("load --table Blogs --columns '_key, articles' \n"
"[\n"
Expand Down

0 comments on commit 8a52f23

Please sign in to comment.