Module: Pixmatch::Client::Search

Included in:
Pixmatch::Client
Defined in:
lib/pixmatch/client/search.rb

Instance Method Summary collapse

Instance Method Details

#search(image, options = {}) ⇒ Object

Given an image, search against our collection and return any matches with corresponding scores.

Parameters:

  • image (File or String)

    The image file object that will be searched for.

  • options (Hash) (defaults to: {})

    The following options.

    • min_score [Integer] The minimum score that should be returned, defaults to 0. Should be between 0 and 100 (inclusive).

    • max_num_matches [Integer] The maximum number of matches that should be returned, defaults to 10. A value of -1 indicates no limit.

    • check_horizontal_flip [Boolean] Indicates whether the search incorporates checking for horizontal flips, defaults to true.

Returns:

  • Array of { score, filename } hashes.



11
12
13
14
15
16
17
18
# File 'lib/pixmatch/client/search.rb', line 11

def search(image, options = {})
  payload = { "image" => image.is_a?(File) ? image : File.new(image, "rb") }
  response = request(:post, 'rest', { method: 'search' }.merge(options), { payload: payload })
  result = response['result']
  raise "Missing result in response." if result.nil?
  raise "Invalid result in response (#{result.class.name})." if ! result.is_a?(Array)
  result
end