Daijiro MORI
null+****@clear*****
Mon Apr 1 15:18:14 JST 2013
Daijiro MORI 2013-04-01 15:18:14 +0900 (Mon, 01 Apr 2013) New Revision: bfe07a5bc8bc9d204b4389dc2de051d77defa4df https://github.com/groonga/fluent-plugin-droonga/commit/bfe07a5bc8bc9d204b4389dc2de051d77defa4df Message: Support "output" and "attributes" parameters Modified files: lib/droonga/plugin/handler_search.rb Modified: lib/droonga/plugin/handler_search.rb (+28 -21) =================================================================== --- lib/droonga/plugin/handler_search.rb 2013-03-30 13:43:29 +0900 (7b32de8) +++ lib/droonga/plugin/handler_search.rb 2013-04-01 15:18:14 +0900 (7f8e368) @@ -68,31 +68,38 @@ module Droonga result = results[name] offset = query["offset"] || 0 limit = query["limit"] || 10 - columns = source.columns - attributes = columns.collect do |column| - { - "name" => column.local_name, - "type" => column.range.name, - "vector" => column.vector?, - } + outputs[name] = output = {} + if query["output"]["count"] + output["count"] = result.size end - column_names = columns.collect(&:local_name) - records = result.open_cursor(:offset => offset, - :limit => limit) do |cursor| - cursor.collect do |record| - column_names.collect do |name| - record[name] + if query["output"]["result"] + attributes = query["output"]["result"]["attributes"] + if attributes + attrs = attributes.map do |attr| + if attr.is_a?(String) + { label: attr, source: attr} + else + { label: attr["label"] || attr["source"], + source: attr["source"] } + end + end + output["result"] = result.open_cursor(:offset => offset, + :limit => limit) do |cursor| + cursor.collect do |record| + values = {} + attrs.collect do |attr| + $log.info attr[:source] + values[attr[:label]] = record[attr[:source]] + end + values + end end end end - elapsed_time = Time.now.to_f - start_time.to_f - outputs[name] = { - "count" => result.size, - "startTime" => start_time.iso8601, - "elapsedTime" => elapsed_time, - "attributes" => attributes, - "records" => records, - } + if query["output"]["elapsedTime"] + output["startTime"] = start_time.iso8601 + output["elapsedTime"] = Time.now.to_f - start_time.to_f + end end end -------------- next part -------------- HTML����������������������������...Download