Kouhei Sutou
null+****@clear*****
Thu May 16 12:45:23 JST 2013
Kouhei Sutou 2013-05-16 12:45:23 +0900 (Thu, 16 May 2013) New Revision: d9964ff22a9a51c6883bde154fa449c0b66a0a1b https://github.com/groonga/groonga/commit/d9964ff22a9a51c6883bde154fa449c0b66a0a1b Message: Support index section by index in match_columns It supports: select Documents \ --match_columns "Lexicon.index[0] * 10 || Lexicon.index[1]" \ --query "QUERY" \ --output_columns "content, _score" # -> _score = (# of matches against section 1) * 10 + (# of matches against section 2) Added files: test/command/suite/select/match_columns/section/by_index.expected test/command/suite/select/match_columns/section/by_index.test Modified files: lib/expr.c Modified: lib/expr.c (+11 -1) =================================================================== --- lib/expr.c 2013-05-16 12:44:33 +0900 (25b1a26) +++ lib/expr.c 2013-05-16 12:45:23 +0900 (72dd84b) @@ -4063,7 +4063,17 @@ scan_info_build(grn_ctx *ctx, grn_obj *expr, int *n, } break; case GRN_COLUMN_INDEX : - scan_info_put_index(ctx, si, ec->value, 0, get_weight(ctx, ec)); + sid = 0; + index = ec->value; + if (j > 2 && + ec[1].value && + ec[1].value->header.domain == GRN_DB_UINT32 && + ec[2].op == GRN_OP_GET_MEMBER) { + sid = GRN_UINT32_VALUE(ec[1].value) + 1; + j -= 2; + ec += 2; + } + scan_info_put_index(ctx, si, index, sid, get_weight(ctx, ec)); break; } } Added: test/command/suite/select/match_columns/section/by_index.expected (+54 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/match_columns/section/by_index.expected 2013-05-16 12:45:23 +0900 (6fd9cad) @@ -0,0 +1,54 @@ +table_create Memos TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Memos title COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +column_create Memos content COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +table_create Lexicon TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram +[[0,0.0,0.0],true] +column_create Lexicon memo_index COLUMN_INDEX|WITH_POSITION|WITH_SECTION Memos title,content +[[0,0.0,0.0],true] +load --table Memos +[ +["title", "content"], +["groonga", "Start groonga!"], +["mroonga", "Start mroonga!"], +["rroonga", "Start rroonga!"], +["Ruby", "Start Ruby!"], +["learn", "Learning Ruby and groonga..."] +] +[[0,0.0,0.0],5] +select Memos --match_columns "Lexicon.memo_index[0] * 10 || Lexicon.memo_index[1]" --query rroonga --output_columns "title, content, _score" +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 1 + ], + [ + [ + "title", + "ShortText" + ], + [ + "content", + "ShortText" + ], + [ + "_score", + "Int32" + ] + ], + [ + "rroonga", + "Start rroonga!", + 11 + ] + ] + ] +] Added: test/command/suite/select/match_columns/section/by_index.test (+22 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/match_columns/section/by_index.test 2013-05-16 12:45:23 +0900 (802bd3c) @@ -0,0 +1,22 @@ +table_create Memos TABLE_NO_KEY +column_create Memos title COLUMN_SCALAR ShortText +column_create Memos content COLUMN_SCALAR ShortText + +table_create Lexicon TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram +column_create Lexicon memo_index COLUMN_INDEX|WITH_POSITION|WITH_SECTION \ + Memos title,content + +load --table Memos +[ +["title", "content"], +["groonga", "Start groonga!"], +["mroonga", "Start mroonga!"], +["rroonga", "Start rroonga!"], +["Ruby", "Start Ruby!"], +["learn", "Learning Ruby and groonga..."] +] + +select Memos \ + --match_columns "Lexicon.memo_index[0] * 10 || Lexicon.memo_index[1]" \ + --query rroonga \ + --output_columns "title, content, _score" -------------- next part -------------- HTML����������������������������...Download