Class: Marqo::Search

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

Constant Summary collapse

SEARCH_METHOD_TENSOR =
'TENSOR'
SEARCH_METHOD_LEXICAL =
'LEXICAL'

Class Method Summary collapse

Class Method Details

.run(endpoint, index_name, query, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/marqo/search.rb', line 9

def self.run(endpoint, index_name, query, options = {})
  # # possible options
  # filter - https://docs.marqo.ai/1.2.0/API-Reference/search/#filter
  # searchableAttributes - https://docs.marqo.ai/1.2.0/API-Reference/search/#searchable-attributes
  # reRanker - https://docs.marqo.ai/1.2.0/API-Reference/search/#reranker
  # boost - https://docs.marqo.ai/1.2.0/API-Reference/search/#boost
  # context - https://docs.marqo.ai/1.2.0/API-Reference/search/#context
  # score_modifiers - https://docs.marqo.ai/1.2.0/API-Reference/search/#score-modifiers
  # modelAuth - https://docs.marqo.ai/1.2.0/API-Reference/search/#model-auth

  url = Marqo::UrlHelpers.search_endpoint(endpoint, index_name)

  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = url.scheme == "https"
  request = Net::HTTP::Post.new(url)
  request['Content-type'] = 'application/json'

  payload = Marqo::RequestHelpers.generate_search_payload(query, options)

  request.body = JSON.dump(payload)

  http.request(request)
end