Class: MeiliSearch::Index
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#add_documents(documents, primary_key = nil) ⇒ Object
(also: #replace_documents, #add_or_replace_documents)
-
#attributes_for_faceting ⇒ Object
(also: #get_attributes_for_faceting)
SETTINGS - ATTRIBUTES FOR FACETING.
-
#delete ⇒ Object
(also: #delete_index)
-
#delete_all_documents ⇒ Object
-
#delete_document(document_id) ⇒ Object
(also: #delete_one_document)
-
#delete_documents(documents_ids) ⇒ Object
(also: #delete_multiple_documents)
-
#displayed_attributes ⇒ Object
(also: #get_displayed_attributes)
SETTINGS - DISPLAYED ATTRIBUTES.
-
#distinct_attribute ⇒ Object
(also: #get_distinct_attribute)
SETTINGS - DINSTINCT ATTRIBUTE.
-
#document(document_id) ⇒ Object
(also: #get_document, #get_one_document)
-
#documents(options = {}) ⇒ Object
(also: #get_documents)
-
#fetch_info ⇒ Object
-
#fetch_primary_key ⇒ Object
(also: #get_primary_key)
-
#fields_distribution ⇒ Object
-
#get_all_update_status ⇒ Object
-
#get_update_status(update_id) ⇒ Object
-
#indexing? ⇒ Boolean
-
#initialize(index_uid, url, api_key = nil, primary_key = nil) ⇒ Index
constructor
-
#last_update ⇒ Object
-
#number_of_documents ⇒ Object
-
#ranking_rules ⇒ Object
(also: #get_ranking_rules)
SETTINGS - RANKING RULES.
-
#reset_attributes_for_faceting ⇒ Object
-
#reset_displayed_attributes ⇒ Object
-
#reset_distinct_attribute ⇒ Object
-
#reset_ranking_rules ⇒ Object
-
#reset_searchable_attributes ⇒ Object
-
#reset_settings ⇒ Object
-
#reset_stop_words ⇒ Object
-
#reset_synonyms ⇒ Object
-
#search(query, options = {}) ⇒ Object
-
#searchable_attributes ⇒ Object
(also: #get_searchable_attributes)
SETTINGS - SEARCHABLE ATTRIBUTES.
-
#settings ⇒ Object
(also: #get_settings)
-
#stats ⇒ Object
-
#stop_words ⇒ Object
(also: #get_stop_words)
-
#synonyms ⇒ Object
(also: #get_synonyms)
-
#update(body) ⇒ Object
(also: #update_index)
-
#update_attributes_for_faceting(attributes_for_faceting) ⇒ Object
(also: #attributes_for_faceting=)
-
#update_displayed_attributes(displayed_attributes) ⇒ Object
(also: #displayed_attributes=)
-
#update_distinct_attribute(distinct_attribute) ⇒ Object
(also: #distinct_attribute=)
-
#update_documents(documents, primary_key = nil) ⇒ Object
(also: #add_or_update_documents)
-
#update_ranking_rules(ranking_rules) ⇒ Object
(also: #ranking_rules=)
-
#update_searchable_attributes(searchable_attributes) ⇒ Object
(also: #searchable_attributes=)
-
#update_settings(settings) ⇒ Object
(also: #settings=)
-
#update_stop_words(stop_words) ⇒ Object
(also: #stop_words=)
-
#update_synonyms(synonyms) ⇒ Object
(also: #synonyms=)
-
#wait_for_pending_update(update_id, timeout_in_ms = 5000, interval_in_ms = 50) ⇒ Object
Methods inherited from HTTPRequest
#http_delete, #http_get, #http_post, #http_put
Constructor Details
#initialize(index_uid, url, api_key = nil, primary_key = nil) ⇒ Index
Returns a new instance of Index.
10
11
12
13
14
|
# File 'lib/meilisearch/index.rb', line 10
def initialize(index_uid, url, api_key = nil, primary_key = nil)
@uid = index_uid
@primary_key = primary_key
super(url, api_key)
end
|
Instance Attribute Details
#primary_key ⇒ Object
Returns the value of attribute primary_key.
8
9
10
|
# File 'lib/meilisearch/index.rb', line 8
def primary_key
@primary_key
end
|
#uid ⇒ Object
Returns the value of attribute uid.
8
9
10
|
# File 'lib/meilisearch/index.rb', line 8
def uid
@uid
end
|
Instance Method Details
#add_documents(documents, primary_key = nil) ⇒ Object
Also known as:
replace_documents, add_or_replace_documents
53
54
55
56
|
# File 'lib/meilisearch/index.rb', line 53
def add_documents(documents, primary_key = nil)
documents = [documents] if documents.is_a?(Hash)
http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact
end
|
#attributes_for_faceting ⇒ Object
Also known as:
get_attributes_for_faceting
SETTINGS - ATTRIBUTES FOR FACETING
252
253
254
|
# File 'lib/meilisearch/index.rb', line 252
def attributes_for_faceting
http_get "/indexes/#{@uid}/settings/attributes-for-faceting"
end
|
#delete ⇒ Object
Also known as:
delete_index
29
30
31
|
# File 'lib/meilisearch/index.rb', line 29
def delete
http_delete "/indexes/#{@uid}"
end
|
#delete_all_documents ⇒ Object
81
82
83
|
# File 'lib/meilisearch/index.rb', line 81
def delete_all_documents
http_delete "/indexes/#{@uid}/documents"
end
|
#delete_document(document_id) ⇒ Object
Also known as:
delete_one_document
75
76
77
78
|
# File 'lib/meilisearch/index.rb', line 75
def delete_document(document_id)
encode_document = URI.encode_www_form_component(document_id)
http_delete "/indexes/#{@uid}/documents/#{encode_document}"
end
|
#delete_documents(documents_ids) ⇒ Object
Also known as:
delete_multiple_documents
66
67
68
69
70
71
72
|
# File 'lib/meilisearch/index.rb', line 66
def delete_documents(documents_ids)
if documents_ids.is_a?(Array)
http_post "/indexes/#{@uid}/documents/delete-batch", documents_ids
else
delete_document(documents_ids)
end
end
|
#displayed_attributes ⇒ Object
Also known as:
get_displayed_attributes
SETTINGS - DISPLAYED ATTRIBUTES
236
237
238
|
# File 'lib/meilisearch/index.rb', line 236
def displayed_attributes
http_get "/indexes/#{@uid}/settings/displayed-attributes"
end
|
#distinct_attribute ⇒ Object
Also known as:
get_distinct_attribute
SETTINGS - DINSTINCT ATTRIBUTE
204
205
206
|
# File 'lib/meilisearch/index.rb', line 204
def distinct_attribute
http_get "/indexes/#{@uid}/settings/distinct-attribute"
end
|
#document(document_id) ⇒ Object
Also known as:
get_document, get_one_document
41
42
43
44
|
# File 'lib/meilisearch/index.rb', line 41
def document(document_id)
encode_document = URI.encode_www_form_component(document_id)
http_get "/indexes/#{@uid}/documents/#{encode_document}"
end
|
#documents(options = {}) ⇒ Object
Also known as:
get_documents
48
49
50
|
# File 'lib/meilisearch/index.rb', line 48
def documents(options = {})
http_get "/indexes/#{@uid}/documents", options
end
|
#fetch_info ⇒ Object
16
17
18
19
20
|
# File 'lib/meilisearch/index.rb', line 16
def fetch_info
index_hash = http_get "/indexes/#{@uid}"
@primary_key = index_hash['primaryKey']
self
end
|
#fetch_primary_key ⇒ Object
Also known as:
get_primary_key
34
35
36
|
# File 'lib/meilisearch/index.rb', line 34
def fetch_primary_key
fetch_info.primary_key
end
|
#fields_distribution ⇒ Object
133
134
135
|
# File 'lib/meilisearch/index.rb', line 133
def fields_distribution
stats['fieldsDistribution']
end
|
#get_all_update_status ⇒ Object
98
99
100
|
# File 'lib/meilisearch/index.rb', line 98
def get_all_update_status
http_get "/indexes/#{@uid}/updates"
end
|
#get_update_status(update_id) ⇒ Object
94
95
96
|
# File 'lib/meilisearch/index.rb', line 94
def get_update_status(update_id)
http_get "/indexes/#{@uid}/updates/#{update_id}"
end
|
#indexing? ⇒ Boolean
125
126
127
|
# File 'lib/meilisearch/index.rb', line 125
def indexing?
stats['isIndexing']
end
|
#last_update ⇒ Object
129
130
131
|
# File 'lib/meilisearch/index.rb', line 129
def last_update
stats['lastUpdate']
end
|
#number_of_documents ⇒ Object
121
122
123
|
# File 'lib/meilisearch/index.rb', line 121
def number_of_documents
stats['numberOfDocuments']
end
|
#ranking_rules ⇒ Object
Also known as:
get_ranking_rules
155
156
157
|
# File 'lib/meilisearch/index.rb', line 155
def ranking_rules
http_get "/indexes/#{@uid}/settings/ranking-rules"
end
|
#reset_attributes_for_faceting ⇒ Object
262
263
264
|
# File 'lib/meilisearch/index.rb', line 262
def reset_attributes_for_faceting
http_delete "/indexes/#{@uid}/settings/attributes-for-faceting"
end
|
#reset_displayed_attributes ⇒ Object
246
247
248
|
# File 'lib/meilisearch/index.rb', line 246
def reset_displayed_attributes
http_delete "/indexes/#{@uid}/settings/displayed-attributes"
end
|
#reset_distinct_attribute ⇒ Object
214
215
216
|
# File 'lib/meilisearch/index.rb', line 214
def reset_distinct_attribute
http_delete "/indexes/#{@uid}/settings/distinct-attribute"
end
|
#reset_ranking_rules ⇒ Object
165
166
167
|
# File 'lib/meilisearch/index.rb', line 165
def reset_ranking_rules
http_delete "/indexes/#{@uid}/settings/ranking-rules"
end
|
#reset_searchable_attributes ⇒ Object
230
231
232
|
# File 'lib/meilisearch/index.rb', line 230
def reset_searchable_attributes
http_delete "/indexes/#{@uid}/settings/searchable-attributes"
end
|
#reset_settings ⇒ Object
149
150
151
|
# File 'lib/meilisearch/index.rb', line 149
def reset_settings
http_delete "/indexes/#{@uid}/settings"
end
|
#reset_stop_words ⇒ Object
198
199
200
|
# File 'lib/meilisearch/index.rb', line 198
def reset_stop_words
http_delete "/indexes/#{@uid}/settings/stop-words"
end
|
#reset_synonyms ⇒ Object
181
182
183
|
# File 'lib/meilisearch/index.rb', line 181
def reset_synonyms
http_delete "/indexes/#{@uid}/settings/synonyms"
end
|
#search(query, options = {}) ⇒ Object
87
88
89
90
|
# File 'lib/meilisearch/index.rb', line 87
def search(query, options = {})
parsed_options = options.compact
http_post "/indexes/#{@uid}/search", { q: query }.merge(parsed_options)
end
|
#searchable_attributes ⇒ Object
Also known as:
get_searchable_attributes
SETTINGS - SEARCHABLE ATTRIBUTES
220
221
222
|
# File 'lib/meilisearch/index.rb', line 220
def searchable_attributes
http_get "/indexes/#{@uid}/settings/searchable-attributes"
end
|
#settings ⇒ Object
Also known as:
get_settings
139
140
141
|
# File 'lib/meilisearch/index.rb', line 139
def settings
http_get "/indexes/#{@uid}/settings"
end
|
#stats ⇒ Object
117
118
119
|
# File 'lib/meilisearch/index.rb', line 117
def stats
http_get "/indexes/#{@uid}/stats"
end
|
#stop_words ⇒ Object
Also known as:
get_stop_words
187
188
189
|
# File 'lib/meilisearch/index.rb', line 187
def stop_words
http_get "/indexes/#{@uid}/settings/stop-words"
end
|
#synonyms ⇒ Object
Also known as:
get_synonyms
171
172
173
|
# File 'lib/meilisearch/index.rb', line 171
def synonyms
http_get "/indexes/#{@uid}/settings/synonyms"
end
|
#update(body) ⇒ Object
Also known as:
update_index
22
23
24
25
26
|
# File 'lib/meilisearch/index.rb', line 22
def update(body)
index_hash = http_put "/indexes/#{@uid}", body
@primary_key = index_hash['primaryKey']
self
end
|
#update_attributes_for_faceting(attributes_for_faceting) ⇒ Object
Also known as:
attributes_for_faceting=
257
258
259
|
# File 'lib/meilisearch/index.rb', line 257
def update_attributes_for_faceting(attributes_for_faceting)
http_post "/indexes/#{@uid}/settings/attributes-for-faceting", attributes_for_faceting
end
|
#update_displayed_attributes(displayed_attributes) ⇒ Object
Also known as:
displayed_attributes=
241
242
243
|
# File 'lib/meilisearch/index.rb', line 241
def update_displayed_attributes(displayed_attributes)
http_post "/indexes/#{@uid}/settings/displayed-attributes", displayed_attributes
end
|
#update_distinct_attribute(distinct_attribute) ⇒ Object
Also known as:
distinct_attribute=
209
210
211
|
# File 'lib/meilisearch/index.rb', line 209
def update_distinct_attribute(distinct_attribute)
http_post "/indexes/#{@uid}/settings/distinct-attribute", distinct_attribute
end
|
#update_documents(documents, primary_key = nil) ⇒ Object
Also known as:
add_or_update_documents
60
61
62
63
|
# File 'lib/meilisearch/index.rb', line 60
def update_documents(documents, primary_key = nil)
documents = [documents] if documents.is_a?(Hash)
http_put "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact
end
|
#update_ranking_rules(ranking_rules) ⇒ Object
Also known as:
ranking_rules=
160
161
162
|
# File 'lib/meilisearch/index.rb', line 160
def update_ranking_rules(ranking_rules)
http_post "/indexes/#{@uid}/settings/ranking-rules", ranking_rules
end
|
#update_searchable_attributes(searchable_attributes) ⇒ Object
Also known as:
searchable_attributes=
225
226
227
|
# File 'lib/meilisearch/index.rb', line 225
def update_searchable_attributes(searchable_attributes)
http_post "/indexes/#{@uid}/settings/searchable-attributes", searchable_attributes
end
|
#update_settings(settings) ⇒ Object
Also known as:
settings=
144
145
146
|
# File 'lib/meilisearch/index.rb', line 144
def update_settings(settings)
http_post "/indexes/#{@uid}/settings", settings
end
|
#update_stop_words(stop_words) ⇒ Object
Also known as:
stop_words=
192
193
194
195
|
# File 'lib/meilisearch/index.rb', line 192
def update_stop_words(stop_words)
body = stop_words.is_a?(Array) ? stop_words : [stop_words]
http_post "/indexes/#{@uid}/settings/stop-words", body
end
|
#update_synonyms(synonyms) ⇒ Object
Also known as:
synonyms=
176
177
178
|
# File 'lib/meilisearch/index.rb', line 176
def update_synonyms(synonyms)
http_post "/indexes/#{@uid}/settings/synonyms", synonyms
end
|
#wait_for_pending_update(update_id, timeout_in_ms = 5000, interval_in_ms = 50) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/meilisearch/index.rb', line 102
def wait_for_pending_update(update_id, timeout_in_ms = 5000, interval_in_ms = 50)
Timeout.timeout(timeout_in_ms.to_f / 1000) do
loop do
get_update = get_update_status(update_id)
return get_update if get_update['status'] != 'enqueued'
sleep interval_in_ms.to_f / 1000
end
end
rescue Timeout::Error
raise MeiliSearch::TimeoutError
end
|