Daijiro MORI
null+****@clear*****
Sun Jun 23 18:22:59 JST 2013
Daijiro MORI 2013-06-23 18:22:59 +0900 (Sun, 23 Jun 2013) New Revision: a35e75f558673bc5217449d93c370d8635bebdda https://github.com/groonga/fluent-plugin-droonga/commit/a35e75f558673bc5217449d93c370d8635bebdda Message: Enable sub-records to be output. Modified files: lib/droonga/plugin/handler_search.rb Modified: lib/droonga/plugin/handler_search.rb (+32 -9) =================================================================== --- lib/droonga/plugin/handler_search.rb 2013-06-23 11:52:25 +0900 (67aa439) +++ lib/droonga/plugin/handler_search.rb 2013-06-23 18:22:59 +0900 (192961b) @@ -207,7 +207,7 @@ module Droonga if @query["groupBy"] if @query["groupBy"].is_a? String @result =****@resul*****(@query["groupBy"]) - elseif @query["groupBy"].is_a? Hash + elsif @query["groupBy"].is_a? Hash key = @query["groupBy"]["key"] max_n_sub_records = @query["groupBy"]["maxNumSubRecords"] @result =****@resul*****(key, :max_n_sub_records => max_n_sub_records) @@ -284,21 +284,43 @@ module Droonga end def record_value(record, attribute) - expression = attribute[:expression] - if expression - variable = attribute[:variable] - variable.value = record - expression.execute + if attribute[:source] == "_subrecs" + if @query["output"]["format"] == "complex" + record.collect do |sub_record| + target_attributes = resolve_attributes(attribute, sub_record) + complex_record(target_attributes, sub_record) + end + else + record.collect do |sub_record| + target_attributes = resolve_attributes(attribute, sub_record) + simple_record(target_attributes, sub_record) + end + end else - record[attribute[:source]] + expression = attribute[:expression] + if expression + variable = attribute[:variable] + variable.value = record + expression.execute + else + record[attribute[:source]] + end + end + end + + def resolve_attributes(attribute, record) + unless attribute[:target_attributes] + attribute[:target_attributes] = + normalize_target_attributes(attribute[:attributes], record.table) end + return attribute[:target_attributes] end def accessor_name?(source) /\A[a-zA-Z\#@$_][a-zA-Z\d\#@$_\-.]*\z/ === source end - def normalize_target_attributes(attributes) + def normalize_target_attributes(attributes, domain = @result) attributes.collect do |attribute| if attribute.is_a?(String) attribute = { @@ -311,7 +333,7 @@ module Droonga variable = nil else expression = Groonga::Expression.new(context: @context) - variable = expression.define_variable(domain: @result) + variable = expression.define_variable(domain: domain) expression.parse(source, syntax: :script) condition = expression.define_variable(name: "$condition", reference: true) @@ -323,6 +345,7 @@ module Droonga source: source, expression: expression, variable: variable, + attributes: attribute["attributes"] } end end -------------- next part -------------- HTML����������������������������...Download