Kouhei Sutou
null+****@clear*****
Tue Dec 25 17:14:12 JST 2012
Kouhei Sutou 2012-12-25 17:14:12 +0900 (Tue, 25 Dec 2012) New Revision: 2074e39dae88859714b91e627efc93945ca3b92a https://github.com/groonga/groonga/commit/2074e39dae88859714b91e627efc93945ca3b92a Log: Support key support tables for nested index Key suppport tables are hash table, patricia trie and double array trie. Added files: test/command/suite/select/index/nested/double_array_tire.expected test/command/suite/select/index/nested/double_array_tire.test test/command/suite/select/index/nested/hash.expected test/command/suite/select/index/nested/hash.test test/command/suite/select/index/nested/patricia_trie.expected test/command/suite/select/index/nested/patricia_trie.test Modified files: lib/db.c Modified: lib/db.c (+16 -3) =================================================================== --- lib/db.c 2012-12-25 16:57:30 +0900 (6c385de) +++ lib/db.c 2012-12-25 17:14:12 +0900 (9acd8be) @@ -2905,7 +2905,8 @@ grn_obj_search_accessor(grn_ctx *ctx, grn_obj *obj, grn_obj *query, break; } } else { - grn_id *tid; + grn_obj *tid; + grn_obj *domain; grn_obj *next_res; grn_operator next_op; grn_search_optarg next_optarg = *optarg; @@ -2926,13 +2927,25 @@ grn_obj_search_accessor(grn_ctx *ctx, grn_obj *obj, grn_obj *query, next_op = GRN_OP_OR; } next_optarg.mode = GRN_OP_EXACT; + domain = grn_ctx_at(ctx, index->header.domain); GRN_HASH_EACH(ctx, (grn_hash *)current_res, id, &tid, NULL, NULL, { - rc = grn_ii_sel(ctx, (grn_ii *)index, (const char *)tid, sizeof(grn_id), - (grn_hash *)next_res, next_op, &next_optarg); + if (domain->header.type == GRN_TABLE_NO_KEY) { + rc = grn_ii_sel(ctx, (grn_ii *)index, + (const char *)tid, sizeof(grn_id), + (grn_hash *)next_res, next_op, &next_optarg); + } else { + char key[GRN_TABLE_MAX_KEY_SIZE]; + int key_len; + key_len = grn_table_get_key(ctx, domain, id, + key, GRN_TABLE_MAX_KEY_SIZE); + rc = grn_ii_sel(ctx, (grn_ii *)index, key, key_len, + (grn_hash *)next_res, next_op, &next_optarg); + } if (rc != GRN_SUCCESS) { break; } }); + grn_obj_unlink(ctx, domain); grn_obj_unlink(ctx, current_res); if (rc != GRN_SUCCESS) { if (res != next_res) { Added: test/command/suite/select/index/nested/double_array_tire.expected (+72 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/index/nested/double_array_tire.expected 2012-12-25 17:14:12 +0900 (8fb726f) @@ -0,0 +1,72 @@ +table_create Comments TABLE_DAT_KEY ShortText +[[0,0.0,0.0],true] +column_create Comments content COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +table_create Articles TABLE_DAT_KEY ShortText +[[0,0.0,0.0],true] +column_create Articles content COLUMN_SCALAR Text +[[0,0.0,0.0],true] +column_create Articles comment COLUMN_SCALAR Comments +[[0,0.0,0.0],true] +table_create Lexicon TABLE_PAT_KEY|KEY_NORMALIZE ShortText --default_tokenizer TokenBigram +[[0,0.0,0.0],true] +column_create Lexicon articles_content COLUMN_INDEX|WITH_POSITION Articles content +[[0,0.0,0.0],true] +column_create Lexicon comments_content COLUMN_INDEX|WITH_POSITION Comments content +[[0,0.0,0.0],true] +column_create Comments article COLUMN_INDEX Articles comment +[[0,0.0,0.0],true] +load --table Comments +[ +{"_key": "1-1", "content": "I'm using groonga too!"}, +{"_key": "2-1", "content": "I'm using groonga and mroonga!"}, +{"_key": "1-2", "content": "I'm using mroonga too!"} +] +[[0,0.0,0.0],3] +load --table Articles +[ +["_key", "content", "comment"], +["groonga-is-fast", "Groonga is fast!", "1-1"], +["groonga-is-useful", "Groonga is useful!"], +["mroonga-is-fast", "Mroonga is fast!", "1-2"] +] +[[0,0.0,0.0],2] +select Articles --match_columns comment.content --query groonga --output_columns "_id, _score, *" +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 1 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_score", + "Int32" + ], + [ + "comment", + "Comments" + ], + [ + "content", + "Text" + ] + ], + [ + 1, + 1, + "1-1", + "Groonga is fast!" + ] + ] + ] +] Added: test/command/suite/select/index/nested/double_array_tire.test (+33 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/index/nested/double_array_tire.test 2012-12-25 17:14:12 +0900 (c626f0b) @@ -0,0 +1,33 @@ +table_create Comments TABLE_DAT_KEY ShortText +column_create Comments content COLUMN_SCALAR ShortText + +table_create Articles TABLE_DAT_KEY ShortText +column_create Articles content COLUMN_SCALAR Text +column_create Articles comment COLUMN_SCALAR Comments + +table_create Lexicon TABLE_PAT_KEY|KEY_NORMALIZE ShortText \ + --default_tokenizer TokenBigram +column_create Lexicon articles_content COLUMN_INDEX|WITH_POSITION \ + Articles content +column_create Lexicon comments_content COLUMN_INDEX|WITH_POSITION \ + Comments content + +column_create Comments article COLUMN_INDEX Articles comment + +load --table Comments +[ +{"_key": "1-1", "content": "I'm using groonga too!"}, +{"_key": "2-1", "content": "I'm using groonga and mroonga!"}, +{"_key": "1-2", "content": "I'm using mroonga too!"} +] + +load --table Articles +[ +["_key", "content", "comment"], +["groonga-is-fast", "Groonga is fast!", "1-1"], +["groonga-is-useful", "Groonga is useful!"], +["mroonga-is-fast", "Mroonga is fast!", "1-2"] +] + +select Articles --match_columns comment.content --query groonga \ + --output_columns "_id, _score, *" Added: test/command/suite/select/index/nested/hash.expected (+72 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/index/nested/hash.expected 2012-12-25 17:14:12 +0900 (dcf6534) @@ -0,0 +1,72 @@ +table_create Comments TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Comments content COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +table_create Articles TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Articles content COLUMN_SCALAR Text +[[0,0.0,0.0],true] +column_create Articles comment COLUMN_SCALAR Comments +[[0,0.0,0.0],true] +table_create Lexicon TABLE_PAT_KEY|KEY_NORMALIZE ShortText --default_tokenizer TokenBigram +[[0,0.0,0.0],true] +column_create Lexicon articles_content COLUMN_INDEX|WITH_POSITION Articles content +[[0,0.0,0.0],true] +column_create Lexicon comments_content COLUMN_INDEX|WITH_POSITION Comments content +[[0,0.0,0.0],true] +column_create Comments article COLUMN_INDEX Articles comment +[[0,0.0,0.0],true] +load --table Comments +[ +{"_key": "1-1", "content": "I'm using groonga too!"}, +{"_key": "2-1", "content": "I'm using groonga and mroonga!"}, +{"_key": "1-2", "content": "I'm using mroonga too!"} +] +[[0,0.0,0.0],3] +load --table Articles +[ +["_key", "content", "comment"], +["groonga-is-fast", "Groonga is fast!", "1-1"], +["groonga-is-useful", "Groonga is useful!"], +["mroonga-is-fast", "Mroonga is fast!", "1-2"] +] +[[0,0.0,0.0],2] +select Articles --match_columns comment.content --query groonga --output_columns "_id, _score, *" +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 1 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_score", + "Int32" + ], + [ + "comment", + "Comments" + ], + [ + "content", + "Text" + ] + ], + [ + 1, + 1, + "1-1", + "Groonga is fast!" + ] + ] + ] +] Added: test/command/suite/select/index/nested/hash.test (+33 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/index/nested/hash.test 2012-12-25 17:14:12 +0900 (6a7553b) @@ -0,0 +1,33 @@ +table_create Comments TABLE_HASH_KEY ShortText +column_create Comments content COLUMN_SCALAR ShortText + +table_create Articles TABLE_HASH_KEY ShortText +column_create Articles content COLUMN_SCALAR Text +column_create Articles comment COLUMN_SCALAR Comments + +table_create Lexicon TABLE_PAT_KEY|KEY_NORMALIZE ShortText \ + --default_tokenizer TokenBigram +column_create Lexicon articles_content COLUMN_INDEX|WITH_POSITION \ + Articles content +column_create Lexicon comments_content COLUMN_INDEX|WITH_POSITION \ + Comments content + +column_create Comments article COLUMN_INDEX Articles comment + +load --table Comments +[ +{"_key": "1-1", "content": "I'm using groonga too!"}, +{"_key": "2-1", "content": "I'm using groonga and mroonga!"}, +{"_key": "1-2", "content": "I'm using mroonga too!"} +] + +load --table Articles +[ +["_key", "content", "comment"], +["groonga-is-fast", "Groonga is fast!", "1-1"], +["groonga-is-useful", "Groonga is useful!"], +["mroonga-is-fast", "Mroonga is fast!", "1-2"] +] + +select Articles --match_columns comment.content --query groonga \ + --output_columns "_id, _score, *" Added: test/command/suite/select/index/nested/patricia_trie.expected (+72 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/index/nested/patricia_trie.expected 2012-12-25 17:14:12 +0900 (94f51bd) @@ -0,0 +1,72 @@ +table_create Comments TABLE_PAT_KEY ShortText +[[0,0.0,0.0],true] +column_create Comments content COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +table_create Articles TABLE_PAT_KEY ShortText +[[0,0.0,0.0],true] +column_create Articles content COLUMN_SCALAR Text +[[0,0.0,0.0],true] +column_create Articles comment COLUMN_SCALAR Comments +[[0,0.0,0.0],true] +table_create Lexicon TABLE_PAT_KEY|KEY_NORMALIZE ShortText --default_tokenizer TokenBigram +[[0,0.0,0.0],true] +column_create Lexicon articles_content COLUMN_INDEX|WITH_POSITION Articles content +[[0,0.0,0.0],true] +column_create Lexicon comments_content COLUMN_INDEX|WITH_POSITION Comments content +[[0,0.0,0.0],true] +column_create Comments article COLUMN_INDEX Articles comment +[[0,0.0,0.0],true] +load --table Comments +[ +{"_key": "1-1", "content": "I'm using groonga too!"}, +{"_key": "2-1", "content": "I'm using groonga and mroonga!"}, +{"_key": "1-2", "content": "I'm using mroonga too!"} +] +[[0,0.0,0.0],3] +load --table Articles +[ +["_key", "content", "comment"], +["groonga-is-fast", "Groonga is fast!", "1-1"], +["groonga-is-useful", "Groonga is useful!"], +["mroonga-is-fast", "Mroonga is fast!", "1-2"] +] +[[0,0.0,0.0],2] +select Articles --match_columns comment.content --query groonga --output_columns "_id, _score, *" +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 1 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_score", + "Int32" + ], + [ + "comment", + "Comments" + ], + [ + "content", + "Text" + ] + ], + [ + 1, + 1, + "1-1", + "Groonga is fast!" + ] + ] + ] +] Added: test/command/suite/select/index/nested/patricia_trie.test (+33 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/index/nested/patricia_trie.test 2012-12-25 17:14:12 +0900 (a84dc16) @@ -0,0 +1,33 @@ +table_create Comments TABLE_PAT_KEY ShortText +column_create Comments content COLUMN_SCALAR ShortText + +table_create Articles TABLE_PAT_KEY ShortText +column_create Articles content COLUMN_SCALAR Text +column_create Articles comment COLUMN_SCALAR Comments + +table_create Lexicon TABLE_PAT_KEY|KEY_NORMALIZE ShortText \ + --default_tokenizer TokenBigram +column_create Lexicon articles_content COLUMN_INDEX|WITH_POSITION \ + Articles content +column_create Lexicon comments_content COLUMN_INDEX|WITH_POSITION \ + Comments content + +column_create Comments article COLUMN_INDEX Articles comment + +load --table Comments +[ +{"_key": "1-1", "content": "I'm using groonga too!"}, +{"_key": "2-1", "content": "I'm using groonga and mroonga!"}, +{"_key": "1-2", "content": "I'm using mroonga too!"} +] + +load --table Articles +[ +["_key", "content", "comment"], +["groonga-is-fast", "Groonga is fast!", "1-1"], +["groonga-is-useful", "Groonga is useful!"], +["mroonga-is-fast", "Mroonga is fast!", "1-2"] +] + +select Articles --match_columns comment.content --query groonga \ + --output_columns "_id, _score, *" -------------- next part -------------- HTML����������������������������...Download