Class: Algolia::CompositionClient

Inherits:
Object
  • Object
show all
Defined in:
lib/algolia/api/composition_client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ CompositionClient

Returns a new instance of CompositionClient.



9
10
11
12
13
14
15
# File 'lib/algolia/api/composition_client.rb', line 9

def initialize(config = nil)
  raise "`config` is missing." if config.nil?
  raise "`app_id` is missing." if config.app_id.nil? || config.app_id == ""
  raise "`api_key` is missing." if config.api_key.nil? || config.api_key == ""

  @api_client = Algolia::ApiClient.new(config)
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



7
8
9
# File 'lib/algolia/api/composition_client.rb', line 7

def api_client
  @api_client
end

Class Method Details

.create(app_id, api_key, opts = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/algolia/api/composition_client.rb', line 17

def self.create(app_id, api_key, opts = {})
  hosts = []
  hosts << Transport::StatefulHost.new("#{app_id}-dsn.algolia.net", accept: CallType::READ)
  hosts << Transport::StatefulHost.new("#{app_id}.algolia.net", accept: CallType::WRITE)

  hosts += 1
    .upto(3)
    .map do |i|
      Transport::StatefulHost.new("#{app_id}-#{i}.algolianet.com", accept: CallType::READ | CallType::WRITE)
    end
    .shuffle

  config = Algolia::Configuration.new(app_id, api_key, hosts, "Composition", opts)
  create_with_config(config)
end

.create_with_config(config) ⇒ Object



33
34
35
# File 'lib/algolia/api/composition_client.rb', line 33

def self.create_with_config(config)
  new(config)
end

Instance Method Details

#add_user_agent_segment(segment, version = nil) ⇒ Object



47
48
49
50
51
# File 'lib/algolia/api/composition_client.rb', line 47

def add_user_agent_segment(segment, version = nil)
  @api_client.config.add_user_agent_segment(segment, version)

  self
end

#search(composition_id, request_body, request_options = {}) ⇒ SearchResponse

Runs a query on a single composition and returns matching results.

Required API Key ACLs:

- search

Parameters:

  • composition_id (String)

    Unique Composition ObjectID. (required)

  • request_body (RequestBody)

    (required)

  • request_options:

    The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)

Returns:

  • (SearchResponse)


101
102
103
104
# File 'lib/algolia/api/composition_client.rb', line 101

def search(composition_id, request_body, request_options = {})
  response = search_with_http_info(composition_id, request_body, request_options)
  @api_client.deserialize(response.body, request_options[:debug_return_type] || "Composition::SearchResponse")
end

#search_for_facet_values(composition_id, facet_name, search_for_facet_values_request = nil, request_options = {}) ⇒ SearchForFacetValuesResponse

Searches for values of a specified facet attribute on the composition’s main source’s index. - By default, facet values are sorted by decreasing count. You can adjust this with the ‘sortFacetValueBy` parameter. - Searching for facet values doesn’t work if you have **more than 65 searchable facets and searchable attributes combined**.

Required API Key ACLs:

- search

Parameters:

  • composition_id (String)

    Unique Composition ObjectID. (required)

  • facet_name (String)

    Facet attribute in which to search for values. This attribute must be included in the ‘attributesForFaceting` index setting with the `searchable()` modifier. (required)

  • search_for_facet_values_request (SearchForFacetValuesRequest) (defaults to: nil)
  • request_options:

    The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)

Returns:

  • (SearchForFacetValuesResponse)


160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/algolia/api/composition_client.rb', line 160

def search_for_facet_values(composition_id, facet_name, search_for_facet_values_request = nil, request_options = {})
  response = search_for_facet_values_with_http_info(
    composition_id,
    facet_name,
    search_for_facet_values_request,
    request_options
  )
  @api_client.deserialize(
    response.body,
    request_options[:debug_return_type] || "Composition::SearchForFacetValuesResponse"
  )
end

#search_for_facet_values_with_http_info(composition_id, facet_name, search_for_facet_values_request = nil, request_options = {}) ⇒ Http::Response

Searches for values of a specified facet attribute on the composition’s main source’s index. - By default, facet values are sorted by decreasing count. You can adjust this with the ‘sortFacetValueBy` parameter. - Searching for facet values doesn’t work if you have **more than 65 searchable facets and searchable attributes combined**.

Required API Key ACLs:

- search

Parameters:

  • composition_id (String)

    Unique Composition ObjectID. (required)

  • facet_name (String)

    Facet attribute in which to search for values. This attribute must be included in the ‘attributesForFaceting` index setting with the `searchable()` modifier. (required)

  • search_for_facet_values_request (SearchForFacetValuesRequest) (defaults to: nil)
  • request_options:

    The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)

Returns:



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/algolia/api/composition_client.rb', line 115

def search_for_facet_values_with_http_info(
  composition_id,
  facet_name,
  search_for_facet_values_request = nil,
  request_options = {}
)
  # verify the required parameter 'composition_id' is set
  if @api_client.config.client_side_validation && composition_id.nil?
    raise ArgumentError, "Parameter `composition_id` is required when calling `search_for_facet_values`."
  end
  # verify the required parameter 'facet_name' is set
  if @api_client.config.client_side_validation && facet_name.nil?
    raise ArgumentError, "Parameter `facet_name` is required when calling `search_for_facet_values`."
  end

  path = "/1/compositions/{compositionID}/facets/{facetName}/query"
    .sub("{" + "compositionID" + "}", Transport.encode_uri(composition_id.to_s))
    .sub("{" + "facetName" + "}", Transport.encode_uri(facet_name.to_s))
  query_params = {}
  query_params = query_params.merge(request_options[:query_params]) unless request_options[:query_params].nil?
  header_params = {}
  header_params = header_params.merge(request_options[:header_params]) unless request_options[:header_params].nil?

  post_body = request_options[:debug_body] || @api_client.object_to_http_body(search_for_facet_values_request)

  new_options = request_options.merge(
    :operation => :"CompositionClient.search_for_facet_values",
    :header_params => header_params,
    :query_params => query_params,
    :body => post_body,
    :use_read_transporter => true
  )

  @api_client.call_api(:POST, path, new_options)
end

#search_with_http_info(composition_id, request_body, request_options = {}) ⇒ Http::Response

Runs a query on a single composition and returns matching results.

Required API Key ACLs:

- search

Parameters:

  • composition_id (String)

    Unique Composition ObjectID. (required)

  • request_body (RequestBody)

    (required)

  • request_options:

    The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/algolia/api/composition_client.rb', line 61

def search_with_http_info(composition_id, request_body, request_options = {})
  # verify the required parameter 'composition_id' is set
  if @api_client.config.client_side_validation && composition_id.nil?
    raise ArgumentError, "Parameter `composition_id` is required when calling `search`."
  end
  # verify the required parameter 'request_body' is set
  if @api_client.config.client_side_validation && request_body.nil?
    raise ArgumentError, "Parameter `request_body` is required when calling `search`."
  end

  path = "/1/compositions/{compositionID}/run".sub(
    "{" + "compositionID" + "}",
    Transport.encode_uri(composition_id.to_s)
  )
  query_params = {}
  query_params = query_params.merge(request_options[:query_params]) unless request_options[:query_params].nil?
  header_params = {}
  header_params = header_params.merge(request_options[:header_params]) unless request_options[:header_params].nil?

  post_body = request_options[:debug_body] || @api_client.object_to_http_body(request_body)

  new_options = request_options.merge(
    :operation => :"CompositionClient.search",
    :header_params => header_params,
    :query_params => query_params,
    :body => post_body,
    :use_read_transporter => true
  )

  @api_client.call_api(:POST, path, new_options)
end

#set_client_api_key(api_key) ⇒ void

This method returns an undefined value.

Helper method to switch the API key used to authenticate the requests.

Parameters:

  • api_key (String)

    the new API key to use.



41
42
43
44
45
# File 'lib/algolia/api/composition_client.rb', line 41

def set_client_api_key(api_key)
  @api_client.set_client_api_key(api_key)

  self
end