Kouhei Sutou
null+****@clear*****
Wed Jul 30 11:46:33 JST 2014
Kouhei Sutou 2014-07-30 11:46:33 +0900 (Wed, 30 Jul 2014) New Revision: a0aac9789f9ca3cadcbf592a97d32e429009c9fc https://github.com/groonga/groonga/commit/a0aac9789f9ca3cadcbf592a97d32e429009c9fc Message: output: support weight vector element as XML Added files: test/command/suite/select/output/value/weight_vector/reference_xml.expected test/command/suite/select/output/value/weight_vector/reference_xml.test test/command/suite/select/output/value/weight_vector/type_xml.expected test/command/suite/select/output/value/weight_vector/type_xml.test Modified files: lib/output.c Modified: lib/output.c (+27 -0) =================================================================== --- lib/output.c 2014-07-30 11:39:23 +0900 (4ef5de2) +++ lib/output.c 2014-07-30 11:46:33 +0900 (19bfd73) @@ -1456,6 +1456,8 @@ transform_xml(grn_ctx *ctx, grn_obj *output, grn_obj *transformed) int column_n = 0, column_text_n = 0, result_set_n = -1; grn_bool in_vector = GRN_FALSE; unsigned int vector_element_n = 0; + grn_bool in_weight_vector = GRN_FALSE; + unsigned int weight_vector_item_n = 0; s = GRN_TEXT_VALUE(output); e = GRN_BULK_CURR(output); @@ -1514,6 +1516,13 @@ transform_xml(grn_ctx *ctx, grn_obj *output, grn_obj *transformed) GRN_TEXT_PUTS(ctx, transformed, "<FIELD NAME=\""); GRN_TEXT_PUTS(ctx, transformed, c); GRN_TEXT_PUTS(ctx, transformed, "\">"); + } else if (EQUAL_NAME_P("WEIGHT_VECTOR")) { + char *c = transform_xml_next_column(&columns, column_n++); + in_weight_vector = GRN_TRUE; + weight_vector_item_n = 0; + GRN_TEXT_PUTS(ctx, transformed, "<FIELD NAME=\""); + GRN_TEXT_PUTS(ctx, transformed, c); + GRN_TEXT_PUTS(ctx, transformed, "\">"); } break; case XML_END_ELEMENT : @@ -1541,6 +1550,9 @@ transform_xml(grn_ctx *ctx, grn_obj *output, grn_obj *transformed) } else if (EQUAL_NAME_P("VECTOR")) { in_vector = GRN_FALSE; GRN_TEXT_PUTS(ctx, transformed, "</FIELD>\n"); + } else if (EQUAL_NAME_P("WEIGHT_VECTOR")) { + in_weight_vector = GRN_FALSE; + GRN_TEXT_PUTS(ctx, transformed, "</FIELD>\n"); } else { switch (place) { case XML_PLACE_HIT : @@ -1552,6 +1564,21 @@ transform_xml(grn_ctx *ctx, grn_obj *output, grn_obj *transformed) GRN_TEXT_PUT(ctx, transformed, GRN_TEXT_VALUE(&buf), GRN_TEXT_LEN(&buf)); vector_element_n++; + } else if (in_weight_vector) { + grn_bool is_key; + is_key = ((weight_vector_item_n % 2) == 0); + if (is_key) { + unsigned int weight_vector_key_n; + weight_vector_key_n = weight_vector_item_n / 2; + if (weight_vector_key_n > 0) { + GRN_TEXT_PUTS(ctx, transformed, ", "); + } + } else { + GRN_TEXT_PUTS(ctx, transformed, ":"); + } + GRN_TEXT_PUT(ctx, transformed, + GRN_TEXT_VALUE(&buf), GRN_TEXT_LEN(&buf)); + weight_vector_item_n++; } else { char *c = transform_xml_next_column(&columns, column_n++); GRN_TEXT_PUTS(ctx, transformed, "<FIELD NAME=\""); Added: test/command/suite/select/output/value/weight_vector/reference_xml.expected (+33 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/output/value/weight_vector/reference_xml.expected 2014-07-30 11:46:33 +0900 (f285a00) @@ -0,0 +1,33 @@ +table_create Tags TABLE_PAT_KEY ShortText +[[0,0.0,0.0],true] +table_create Memos TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Memos tags COLUMN_VECTOR|WITH_WEIGHT Tags +[[0,0.0,0.0],true] +load --table Memos +[ +{ + "_key": "Mroonga is fast", + "tags": { + "mroonga": 100, + "groonga": 10 + } +} +] +[[0,0.0,0.0],1] +select Memos --output_type xml --output_columns _key,tags +<?xml version="1.0" encoding="utf-8"?> +<SEGMENTS> +<SEGMENT> +<RESULTPAGE> +<RESULTSET OFFSET="0" LIMIT="1" NHITS="1"> +<HIT NO="1"> +<FIELD NAME="_key">Mroonga is fast</FIELD> +<FIELD NAME="tags">mroonga:100, groonga:10</FIELD> +</HIT> +</RESULTSET> +</RESULTPAGE> +</SEGMENT> +</SEGMENTS> + + Added: test/command/suite/select/output/value/weight_vector/reference_xml.test (+19 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/output/value/weight_vector/reference_xml.test 2014-07-30 11:46:33 +0900 (3a28a03) @@ -0,0 +1,19 @@ +table_create Tags TABLE_PAT_KEY ShortText + +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos tags COLUMN_VECTOR|WITH_WEIGHT Tags + +load --table Memos +[ +{ + "_key": "Mroonga is fast", + "tags": { + "mroonga": 100, + "groonga": 10 + } +} +] + +select Memos \ + --output_type xml \ + --output_columns _key,tags Added: test/command/suite/select/output/value/weight_vector/type_xml.expected (+31 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/output/value/weight_vector/type_xml.expected 2014-07-30 11:46:33 +0900 (cc83d69) @@ -0,0 +1,31 @@ +table_create Memos TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Memos tags COLUMN_VECTOR|WITH_WEIGHT ShortText +[[0,0.0,0.0],true] +load --table Memos +[ +{ + "_key": "Mroonga is fast", + "tags": { + "mroonga": 100, + "groonga": 10 + } +} +] +[[0,0.0,0.0],1] +select Memos --output_type xml --output_columns _key,tags +<?xml version="1.0" encoding="utf-8"?> +<SEGMENTS> +<SEGMENT> +<RESULTPAGE> +<RESULTSET OFFSET="0" LIMIT="1" NHITS="1"> +<HIT NO="1"> +<FIELD NAME="_key">Mroonga is fast</FIELD> +<FIELD NAME="tags">mroonga:100, groonga:10</FIELD> +</HIT> +</RESULTSET> +</RESULTPAGE> +</SEGMENT> +</SEGMENTS> + + Added: test/command/suite/select/output/value/weight_vector/type_xml.test (+17 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/output/value/weight_vector/type_xml.test 2014-07-30 11:46:33 +0900 (571751c) @@ -0,0 +1,17 @@ +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos tags COLUMN_VECTOR|WITH_WEIGHT ShortText + +load --table Memos +[ +{ + "_key": "Mroonga is fast", + "tags": { + "mroonga": 100, + "groonga": 10 + } +} +] + +select Memos \ + --output_type xml \ + --output_columns _key,tags -------------- next part -------------- HTML����������������������������... ダウンロード