diff options
author | Nathan L Smith <smith@chef.io> | 2016-12-04 23:41:56 -0600 |
---|---|---|
committer | Nathan L Smith <smith@chef.io> | 2016-12-04 23:41:56 -0600 |
commit | 78a11d032d641fda1a4702abc3535b80bb2f0bda (patch) | |
tree | 487d40907b5e0d953a1cc2b1270682d4dde7144e /lib/chef_zero | |
parent | 1c172661f6d6ddf9bf37cda4f7b9651adbc2eb53 (diff) | |
download | chef-zero-78a11d032d641fda1a4702abc3535b80bb2f0bda.tar.gz |
Handle the start and rows parameters correctlynls/SPOOL-436/toomanyrows
Chef Zero would, on a search request using the "start" or "rows"
parameters, always return all rows.
This change makes it so only the correct number of rows are returned or
the results start at the correct index.
This change will make the tests added in oc-chef-pedant in
chef/chef-server#1028 pass.
Also update the Gemfile to use HTTPS URLs for Git sources, remove unused
comments, and use the Chef Gem from RubyGems as the previous comment
suggested.
Signed-off-by: Nathan L Smith <smith@chef.io>
Diffstat (limited to 'lib/chef_zero')
-rw-r--r-- | lib/chef_zero/endpoints/search_endpoint.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/chef_zero/endpoints/search_endpoint.rb b/lib/chef_zero/endpoints/search_endpoint.rb index 1e20025..16da462 100644 --- a/lib/chef_zero/endpoints/search_endpoint.rb +++ b/lib/chef_zero/endpoints/search_endpoint.rb @@ -12,7 +12,19 @@ module ChefZero def get(request) orgname = request.rest_path[1] results = search(request, orgname) + results["rows"] = results["rows"].map { |name, uri, value, search_value| value } + + # Slice the array based on the value of the "rows" query parameter. If + # this is a positive integer, we'll get the number of rows asked for. + # If it's nil, we'll get -1, which gives us all of the elements. + # + # Do the same for "start", which will start at 0 if that value is not + # given. + results["rows"] = + results["rows"][request.query_params["start"].to_i.. + (request.query_params["rows"].to_i - 1)] + json_response(200, results) rescue ChefZero::Solr::ParseError bad_search_request(request) |