Class: Exa::Services::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/exa/services/search.rb

Constant Summary collapse

VALID_SEARCH_TYPES =
["fast", "deep", "keyword", "auto"].freeze
DEFAULT_SEARCH_TYPE =
"fast"

Instance Method Summary collapse

Constructor Details

#initialize(connection, **params) ⇒ Search

Returns a new instance of Search.



11
12
13
14
15
# File 'lib/exa/services/search.rb', line 11

def initialize(connection, **params)
  @connection = connection
  @params = normalize_params(params)
  validate_search_type!
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/exa/services/search.rb', line 17

def call
  response = @connection.post("/search", ParameterConverter.convert(@params))
  body = response.body

  Resources::SearchResult.new(
    results: body["results"],
    request_id: body["requestId"],
    resolved_search_type: body["resolvedSearchType"],
    search_type: body["searchType"],
    context: body["context"],
    cost_dollars: body["costDollars"]
  )
end