[Groonga-commit] groonga/groonga-query-log at 80303b2 [master] server-verifier: support _score sort with sign case

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Jan 16 14:53:13 JST 2014


Kouhei Sutou	2014-01-16 14:53:13 +0900 (Thu, 16 Jan 2014)

  New Revision: 80303b27bdc4740c68ecd8af0960702276c1f98b
  https://github.com/groonga/groonga-query-log/commit/80303b27bdc4740c68ecd8af0960702276c1f98b

  Message:
    server-verifier: support _score sort with sign case
    
    sortby=+_score and sortby=-_score are also score sort.

  Modified files:
    lib/groonga/query-log/response-comparer.rb
    test/test-response-comparer.rb

  Modified: lib/groonga/query-log/response-comparer.rb (+9 -2)
===================================================================
--- lib/groonga/query-log/response-comparer.rb    2014-01-15 19:11:44 +0900 (c3c8453)
+++ lib/groonga/query-log/response-comparer.rb    2014-01-16 14:53:13 +0900 (bc1b446)
@@ -55,8 +55,15 @@ module Groonga
       end
 
       def random_sort?
-        random_score? and
-          (@command.sortby || "").split(/\s*,\s*/).include?("_score")
+        random_score? and score_sort?
+      end
+
+      def score_sort?
+        sort_items = (@command.sortby || "").split(/\s*,\s*/)
+        normalized_sort_items = sort_items.collect do |item|
+          item.gsub(/\A[+-]/, "")
+        end
+        normalized_sort_items.include?("_score")
       end
     end
   end

  Modified: test/test-response-comparer.rb (+52 -0)
===================================================================
--- test/test-response-comparer.rb    2014-01-15 19:11:44 +0900 (5cb8d8a)
+++ test/test-response-comparer.rb    2014-01-16 14:53:13 +0900 (3a58898)
@@ -67,5 +67,57 @@ class ResponseComparerTest < Test::Unit::TestCase
         end
       end
     end
+
+    class SortbyTest < self
+      class DetectScoreSortTest < self
+        private
+        def score_sort?(sortby)
+          @command["sortby"] = sortby
+          comparer([], []).send(:score_sort?)
+        end
+
+        class NoScoreTest < self
+          def test_nil
+            assert_false(score_sort?(nil))
+          end
+
+          def test_empty
+            assert_false(score_sort?(""))
+          end
+        end
+
+        class ScoreOnly < self
+          def test_no_sign
+            assert_true(score_sort?("_score"))
+          end
+
+          def test_plus
+            assert_true(score_sort?("+_score"))
+          end
+
+          def test_minus
+            assert_true(score_sort?("-_score"))
+          end
+        end
+
+        class MultipleItemsTest < self
+          def test_no_space
+            assert_true(score_sort?("_id,_score,_key"))
+          end
+
+          def test_have_space
+            assert_true(score_sort?("_id, _score, _key"))
+          end
+
+          def test_plus
+            assert_true(score_sort?("_id,+_score,_key"))
+          end
+
+          def test_minus
+            assert_true(score_sort?("_id,-_score,_key"))
+          end
+        end
+      end
+    end
   end
 end
-------------- next part --------------
HTML����������������������������...
다운로드 



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