diff --git a/lib/chef/knife/search.rb b/lib/chef/knife/search.rb index 34d12168b6e..caca99b4d8b 100644 --- a/lib/chef/knife/search.rb +++ b/lib/chef/knife/search.rb @@ -53,7 +53,7 @@ class Search < Knife :short => "-R INT", :long => "--rows INT", :description => "The number of rows to return", - :default => 1000, + :default => nil, :proc => lambda { |i| i.to_i } option :run_list, @@ -92,9 +92,9 @@ def run result_count = 0 search_args = Hash.new - search_args[:sort] = config[:sort] - search_args[:start] = config[:start] - search_args[:rows] = config[:rows] + search_args[:sort] = config[:sort] if config[:sort] + search_args[:start] = config[:start] if config[:start] + search_args[:rows] = config[:rows] if config[:rows] if config[:filter_result] search_args[:filter_result] = create_result_filter(config[:filter_result]) elsif (not ui.config[:attribute].nil?) && (not ui.config[:attribute].empty?) diff --git a/lib/chef/search/query.rb b/lib/chef/search/query.rb index 7ca122c986f..b68749f1969 100644 --- a/lib/chef/search/query.rb +++ b/lib/chef/search/query.rb @@ -88,8 +88,8 @@ def search(type, query='*:*', *args, &block) if block response["rows"].each { |row| block.call(row) if row } - if response["start"] + response["rows"].size < response["total"] - start = response["start"] + rows + unless (response["start"] + response["rows"].length) >= response["total"] + args_h[:start] = response["start"] + (args_h[:rows] || 0) search(type, query, args_h, &block) end true @@ -125,7 +125,7 @@ def escape(s) end def call_rest_service(type, query:'*:*', rows:nil, start:0, sort:'X_CHEF_id_CHEF_X asc', filter_result:nil) - query_string = "search/#{type}?q=#{escape(query)}&sort=#{escape(sort)}&start=#{escape(start)}&rows=#{escape(rows)}" + query_string = "search/#{type}?q=#{escape(query)}&sort=#{escape(sort)}&start=#{escape(start)}#{"&rows=" + escape(rows) if rows}" if filter_result response = rest.post_rest(query_string, filter_result)