[Groonga-commit] droonga/fluent-plugin-droonga at f9f9dfb [master] Add sort attributes to the list of attributes for distributed search requests

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Nov 28 15:32:40 JST 2013


YUKI Hiroshi	2013-11-28 15:32:40 +0900 (Thu, 28 Nov 2013)

  New Revision: f9f9dfb67bd8b1ce008e54dc6c840d0e02da9c46
  https://github.com/droonga/fluent-plugin-droonga/commit/f9f9dfb67bd8b1ce008e54dc6c840d0e02da9c46

  Message:
    Add sort attributes to the list of attributes for distributed search requests

  Modified files:
    lib/droonga/plugin/collector/basic.rb
    lib/droonga/plugin/distributor/search.rb

  Modified: lib/droonga/plugin/collector/basic.rb (+11 -0)
===================================================================
--- lib/droonga/plugin/collector/basic.rb    2013-11-28 15:05:51 +0900 (d01a10b)
+++ lib/droonga/plugin/collector/basic.rb    2013-11-28 15:32:40 +0900 (3e64c86)
@@ -30,6 +30,7 @@ module Droonga
         element = output["element"]
         if element
           result[element] = apply_output_range(result[element], output)
+          result[element] = apply_output_attributes(result[element], output)
           result[element] = apply_output_format(result[element], output)
         end
         output = output["source"]
@@ -52,6 +53,16 @@ module Droonga
       items
     end
 
+    def apply_output_attributes(items, output)
+      attributes = output["attributes"]
+      if attributes
+        items.collect! do |item|
+          item[0..attributes.size]
+        end
+      end
+      items
+    end
+
     def apply_output_format(items, output)
       format = output["format"]
       attributes = output["attributes"]

  Modified: lib/droonga/plugin/distributor/search.rb (+48 -17)
===================================================================
--- lib/droonga/plugin/distributor/search.rb    2013-11-28 15:05:51 +0900 (d34fc16)
+++ lib/droonga/plugin/distributor/search.rb    2013-11-28 15:32:40 +0900 (8b01ea7)
@@ -55,20 +55,10 @@ module Droonga
           when "records"
             next if final_limit.zero?
             # TODO: must take "sortBy" section into account.
-            final_attributes = output["attributes"] || []
-            if final_attributes.is_a?(Hash)
-              final_attributes = final_attributes.keys
-            else
-              final_attributes.collect! do |attribute|
-                if attribute.is_a?(Hash)
-                  attribute["label"] || attribute["source"]
-                else
-                  attribute
-                end
-              end
-            end
-            elements[element] = sort_reducer(:attributes => output["attributes"],
-                                             :sort_keys => query["sortBy"])
+            final_attributes = collect_output_attributes(output["attributes"])
+            output["attributes"] ||= []
+            output["attributes"] += collect_sort_attributes(output["attributes"], query["sortBy"])
+            elements[element] = sort_reducer(output["attributes"], query["sortBy"])
             elements[element]["limit"] = output["limit"]
             output_mapper[output_name]["element"] = element
             output_mapper[output_name]["offset"] = final_offset
@@ -167,9 +157,50 @@ module Droonga
       [final_offset, final_limit]
     end
 
-    def sort_reducer(params)
-      attributes = params[:attributes]
-      sort_keys = params[:sort_keys]
+    def collect_output_attributes(attributes=[])
+      if attributes.is_a?(Hash)
+        attributes.keys
+      else
+        attributes.collect do |attribute|
+          if attribute.is_a?(Hash)
+            attribute["label"] || attribute["source"]
+          else
+            attribute
+          end
+        end
+      end
+    end
+
+    def collect_sort_attributes(attributes, sort_keys)
+      sort_keys = sort_keys["keys"] if sort_keys.is_a?(Hash)
+
+      if attributes.is_a?(Hash)
+        attributes_hash = attributes
+        attributes = []
+        attributes_hash.each |key, attribute|
+          attributes << attribute["source"] || key
+        end
+      else
+        attributes.collect! do |attribute|
+          if attribute.is_a?(Hash)
+            attribute["source"] || attribute["label"]
+          else
+            attribute
+          end
+        end
+      end
+
+      sort_attributes = sort_keys.collect do |key|
+        key = key[1..-1] if key[0] == "-"
+        key
+      end
+      sort_attributes.reject! do |attribute|
+        attributes.include?(attribute)
+      end
+      sort_attributes      
+    end
+
+    def sort_reducer(attributes, sort_keys)
       sort_keys = sort_keys["keys"] if sort_keys.is_a?(Hash)
 
       order = []
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index