[Groonga-commit] ranguba/groonga-client-rails at 6d87952 [master] Support pagination

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Mar 28 00:44:40 JST 2016


Kouhei Sutou	2016-03-28 00:44:40 +0900 (Mon, 28 Mar 2016)

  New Revision: 6d87952a9f3e0cf542b105a971624606c49a9eea
  https://github.com/ranguba/groonga-client-rails/commit/6d87952a9f3e0cf542b105a971624606c49a9eea

  Message:
    Support pagination

  Modified files:
    lib/groonga/client/searcher/select/request.rb
    test/apps/rails4-mongoid/Gemfile.lock
    test/apps/rails4-mongoid/test/searchers/posts_searcher_test.rb

  Modified: lib/groonga/client/searcher/select/request.rb (+16 -0)
===================================================================
--- lib/groonga/client/searcher/select/request.rb    2016-03-28 00:44:08 +0900 (90192b3)
+++ lib/groonga/client/searcher/select/request.rb    2016-03-28 00:44:40 +0900 (8440b1a)
@@ -63,6 +63,22 @@ module Groonga
           end
           alias_method :sort, :sortby
 
+          def offset(value)
+            parameter(:offset, value)
+          end
+
+          def limit(value)
+            parameter(:limit, value)
+          end
+
+          def paginate(page, per_page: 10)
+            page ||= 1
+            page = page.to_i
+            return self if page < 0
+
+            offset(per_page * page).limit(per_page)
+          end
+
           private
           def create_request(parameters)
             self.class.new(parameters)

  Modified: test/apps/rails4-mongoid/Gemfile.lock (+2 -2)
===================================================================
--- test/apps/rails4-mongoid/Gemfile.lock    2016-03-28 00:44:08 +0900 (ea4aee6)
+++ test/apps/rails4-mongoid/Gemfile.lock    2016-03-28 00:44:40 +0900 (552e4ca)
@@ -2,7 +2,7 @@ PATH
   remote: ../../../
   specs:
     groonga-client-rails (0.9.0)
-      groonga-client (>= 0.2.3)
+      groonga-client (>= 0.2.4)
       rails
 
 GEM
@@ -68,7 +68,7 @@ GEM
     globalid (0.3.6)
       activesupport (>= 4.1.0)
     gqtp (1.0.6)
-    groonga-client (0.2.3)
+    groonga-client (0.2.4)
       gqtp (>= 1.0.4)
       groonga-command (>= 1.2.0)
       hashie

  Modified: test/apps/rails4-mongoid/test/searchers/posts_searcher_test.rb (+18 -0)
===================================================================
--- test/apps/rails4-mongoid/test/searchers/posts_searcher_test.rb    2016-03-28 00:44:08 +0900 (e371dc6)
+++ test/apps/rails4-mongoid/test/searchers/posts_searcher_test.rb    2016-03-28 00:44:40 +0900 (503836e)
@@ -98,4 +98,22 @@ class PostsSearcherTest < ActionController::TestCase
                  ],
                  data)
   end
+
+  test "should support pagination" do
+    100.times do |i|
+      create(:post, body: "Hello #{i}")
+    end
+    result_set =****@searc*****(3, per_page: 5).result_set
+    data = result_set.records.collect do |record|
+      record["body"]
+    end
+    assert_equal([
+                   "Hello 15",
+                   "Hello 16",
+                   "Hello 17",
+                   "Hello 18",
+                   "Hello 19",
+                 ],
+                 data)
+  end
 end
-------------- next part --------------
HTML����������������������������...
Descargar 



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