HorimotoYasuhiro
null+****@clear*****
Wed Apr 26 15:38:44 JST 2017
HorimotoYasuhiro 2017-04-26 15:38:44 +0900 (Wed, 26 Apr 2017) New Revision: 36407eacdf541af474852389824ce9ac16a31233 https://github.com/ranguba/groonga-client/commit/36407eacdf541af474852389824ce9ac16a31233 Merged 21cf21b: Merge pull request #19 from komainu8/feature/add_geo_in_rectangle Message: Add geo_in_rectangle method in `select.rb`. Modified files: lib/groonga/client/request/select.rb test/request/select/test-filter.rb Modified: lib/groonga/client/request/select.rb (+38 -0) =================================================================== --- lib/groonga/client/request/select.rb 2017-04-27 11:48:49 +0900 (4c45db6) +++ lib/groonga/client/request/select.rb 2017-04-26 15:38:44 +0900 (17ce335) @@ -93,6 +93,11 @@ module Groonga # filter.in_values(:tags, "tag1", "tag2") # # -> --filter 'in_values(tags, "tag1", "tag2")' # + # @example: Use geo_in_rectangle function + # request. + # filter.geo_in_rectangle("50x50", "0x100", "100x0") + # # -> --filter 'geo_in_rectangle("50x50", "0x100", "100x0")' + # # @example Use geo_in_circle function # request. # filter.geo_in_circle(:location, "100x100", 300) @@ -218,6 +223,39 @@ module Groonga @request = request end + # Adds a `geo_in_rectangle` condition then return a new `select` + # request object. + # + # @see http://groonga.org/docs/reference/functions/geo_in_rectangle.html + # geo_in_rectangle function in the Groonga document + # + # @example: Basic usage + # request. + # filter.geo_in_rectangle("50x50", "0x100", "100x0"). + # # -> --filter 'in_values(50x50, 0x100, 100x0)' + # + # @param point [String] The point to be checked. + # `"#{LONGITUDE}x#{LATITUDE}"` is the point format. + # + # @param top_left [String] The top left of the condition rectangle. + # + # @param bottom_right [String] The bottom right of the condition rectangle. + # + # @return [Groonga::Client::Request::Select] + # The new request with the given condition. + # + # @since 0.5.0 + def geo_in_rectangle(point, top_left, bottom_right) + expression = "geo_in_rectangle(%{point}" + expression << ", %{top_left}" + expression << ", %{bottom_right}" + expression << ")" + @request.filter(expression, + point: point, + top_left: top_left, + bottom_right: bottom_right) + end + # Adds a `geo_in_circle` condition then returns a new `select` # request object. # Modified: test/request/select/test-filter.rb (+14 -0) =================================================================== --- test/request/select/test-filter.rb 2017-04-27 11:48:49 +0900 (d8886aa) +++ test/request/select/test-filter.rb 2017-04-26 15:38:44 +0900 (eddf374) @@ -202,6 +202,20 @@ title == "[\"He\\ llo\"]" end sub_test_case("Filter") do + sub_test_case("#geo_in_rectangle") do + def geo_in_rectangle(*args) + @request.filter.geo_in_rectangle(*args).to_parameters + end + + test("point") do + assert_equal({ + :table => "posts", + :filter => "geo_in_rectangle(\"50x50\", \"0x100\", \"100x0\")", + }, + geo_in_rectangle("50x50", "0x100", "100x0")) + end + end + sub_test_case("#geo_in_circle") do def geo_in_circle(*args) @request.filter.geo_in_circle(*args).to_parameters -------------- next part -------------- HTML����������������������������...Download