Skip to content

Commit

Permalink
Remaining fixes.
Browse files Browse the repository at this point in the history
* Exclude rows from query if rows are nil.
* Update defaults in knife/search to match query defaults.
* Update start when polling more rows.
  • Loading branch information
Claire McQuin committed Dec 19, 2014
1 parent 2ec9334 commit fe8ca9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/chef/knife/search.rb
Expand Up @@ -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,
Expand Down Expand Up @@ -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?)
Expand Down
6 changes: 3 additions & 3 deletions lib/chef/search/query.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fe8ca9e

Please sign in to comment.