Skip to content

Commit 00ce6b0

Browse files
authored
Merge branch 'main' into change-indexes-method
2 parents b287218 + 8e54bd1 commit 00ce6b0

33 files changed

+1048
-1264
lines changed

.code-samples.meilisearch.yaml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ get_one_index_1: |-
88
list_all_indexes_1: |-
99
client.indexes
1010
create_an_index_1: |-
11-
client.create_index('movies', primaryKey: 'movie_id')
11+
client.create_index('movies', primary_key: 'movie_id')
1212
update_an_index_1: |-
13-
client.index('movies').update(primaryKey: 'movie_id')
13+
client.index('movies').update(primary_key: 'movie_id')
1414
delete_an_index_1: |-
1515
client.delete_index('movies')
1616
get_one_document_1: |-
@@ -53,7 +53,7 @@ get_settings_1: |-
5353
client.index('movies').settings
5454
update_settings_1: |-
5555
client.index('movies').update_settings({
56-
rankingRules: [
56+
ranking_rules: [
5757
'words',
5858
'typo',
5959
'proximity',
@@ -63,24 +63,24 @@ update_settings_1: |-
6363
'release_date:desc',
6464
'rank:desc'
6565
],
66-
distinctAttribute: 'movie_id',
67-
searchableAttributes: [
66+
distinct_attribute: 'movie_id',
67+
searchable_attributes: [
6868
'title',
6969
'description',
7070
'genre'
7171
],
72-
displayedAttributes: [
72+
displayed_attributes: [
7373
'title',
7474
'description',
7575
'genre',
7676
'release_date'
7777
],
78-
stopWords: [
78+
stop_words: [
7979
'the',
8080
'a',
8181
'an'
8282
],
83-
sortableAttributes: [
83+
sortable_attributes: [
8484
'title',
8585
'release_date'
8686
],
@@ -123,11 +123,11 @@ update_ranking_rules_1: |-
123123
reset_ranking_rules_1: |-
124124
client.index('movies').reset_ranking_rules
125125
get_distinct_attribute_1: |-
126-
client.index('movies').distinct_attribute
126+
client.index('shoes').distinct_attribute
127127
update_distinct_attribute_1: |-
128-
client.index('movies').update_distinct_attribute('movie_id')
128+
client.index('shoes').update_distinct_attribute('skuid')
129129
reset_distinct_attribute_1: |-
130-
client.index('movies').reset_distinct_attribute
130+
client.index('shoes').reset_distinct_attribute
131131
get_searchable_attributes_1: |-
132132
client.index('movies').searchable_attributes
133133
update_searchable_attributes_1: |-
@@ -176,7 +176,7 @@ field_properties_guide_searchable_1: |-
176176
])
177177
field_properties_guide_displayed_1: |-
178178
client.index('movies').update_settings({
179-
displayedAttributes: [
179+
displayed_attributes: [
180180
'title',
181181
'description',
182182
'genre',
@@ -207,16 +207,16 @@ search_parameter_guide_limit_1: |-
207207
})
208208
search_parameter_guide_retrieve_1: |-
209209
client.index('movies').search('shifu', {
210-
attributesToRetrieve: ['overview', 'title']
210+
attributes_to_retrieve: ['overview', 'title']
211211
})
212212
search_parameter_guide_crop_1: |-
213213
client.index('movies').search('shifu', {
214-
attributesToCrop: ['overview'],
214+
attributes_to_crop: ['overview'],
215215
cropLength: 10
216216
})
217217
search_parameter_guide_highlight_1: |-
218218
client.index('movies').search('winter feast', {
219-
attributesToHighlight: ['overview']
219+
attributes_to_highlight: ['overview']
220220
})
221221
search_parameter_guide_matches_1: |-
222222
client.index('movies').search('winter feast', {
@@ -239,15 +239,15 @@ settings_guide_synonyms_1: |-
239239
})
240240
settings_guide_stop_words_1: |-
241241
client.index('movies').update_settings({
242-
stopWords: [
242+
stop_words: [
243243
'the',
244244
'a',
245245
'an'
246246
]
247247
})
248248
settings_guide_ranking_rules_1: |-
249249
client.index('movies').update_settings({
250-
rankingRules: [
250+
ranking_rules: [
251251
'words',
252252
'typo',
253253
'proximity',
@@ -262,15 +262,15 @@ settings_guide_distinct_1: |-
262262
client.index('jackets').update_distinct_attribute('product_id')
263263
settings_guide_searchable_1: |-
264264
client.index('movies').update_settings({
265-
searchableAttributes: [
265+
searchable_attributes: [
266266
'title',
267267
'description',
268268
'genre'
269269
]
270270
})
271271
settings_guide_displayed_1: |-
272272
client.index('movies').update_settings({
273-
displayedAttributes: [
273+
displayed_attributes: [
274274
'title',
275275
'description',
276276
'genre',
@@ -332,7 +332,7 @@ faceted_search_filter_1: |-
332332
})
333333
faceted_search_facets_distribution_1: |-
334334
client.index('movies').search('Batman', {
335-
facetsDistribution: ['genres']
335+
facets_distribution: ['genres']
336336
})
337337
faceted_search_walkthrough_filterable_attributes_1: |-
338338
client.index('movies').update_filterable_attributes([
@@ -347,7 +347,7 @@ faceted_search_walkthrough_filter_1: |-
347347
})
348348
faceted_search_walkthrough_facets_distribution_1: |-
349349
client.index('movies').search('Batman', {
350-
facetsDistribution: ['genres']
350+
facets_distribution: ['genres']
351351
})
352352
post_dump_1: |-
353353
client.create_dump

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@
4545
# lock
4646
Gemfile.lock
4747

48-
# VScode
48+
# Local editor configurations
4949
.vscode/
50+
.idea/

.rubocop_todo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Metrics/BlockLength:
2323
# Offense count: 1
2424
# Configuration parameters: CountComments, CountAsOne.
2525
Metrics/ClassLength:
26-
Max: 256
26+
Max: 260
2727

2828
# Offense count: 1
2929
Naming/AccessorMethodName:

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ Each PR should pass the tests to be accepted.
5353

5454
```bash
5555
# Tests
56-
docker pull getmeili/meilisearch:latest # Fetch the latest version of MeiliSearch image from Docker Hub
57-
docker run -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey --no-analytics=true
56+
curl -L https://install.meilisearch.com | sh # download MeiliSearch
57+
./meilisearch --master-key=masterKey --no-analytics=true # run MeiliSearch
5858
bundle exec rspec
5959
```
6060

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,17 @@ gem 'meilisearch'
5959

6060
There are many easy ways to [download and run a MeiliSearch instance](https://docs.meilisearch.com/reference/features/installation.html#download-and-launch).
6161

62-
For example, if you use Docker:
62+
For example, using the `curl` command in your [Terminal](https://itconnect.uw.edu/learn/workshops/online-tutorials/web-publishing/what-is-a-terminal/):
6363

64-
```bash
65-
docker pull getmeili/meilisearch:latest # Fetch the latest version of MeiliSearch image from Docker Hub
66-
docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey
64+
```sh
65+
#Install MeiliSearch
66+
curl -L https://install.meilisearch.com | sh
67+
68+
# Launch MeiliSearch
69+
./meilisearch --master-key=masterKey
6770
```
6871

69-
NB: you can also download MeiliSearch from **Homebrew** or **APT**.
72+
NB: you can also download MeiliSearch from **Homebrew** or **APT** or even run it using **Docker**.
7073

7174
## 🚀 Getting Started
7275

@@ -124,7 +127,7 @@ All the supported options are described in the [search parameters](https://docs.
124127
```ruby
125128
index.search(
126129
'wonder',
127-
attributesToHighlight: ['*']
130+
attributes_to_highlight: ['*']
128131
)
129132
```
130133

lib/meilisearch/error.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ def get_meilisearch_error_info(http_body)
3333
@ms_message = @http_body['message']
3434
@ms_type = @http_body['errorType']
3535
@ms_link = @http_body['errorLink']
36+
rescue JSON::ParserError
37+
# We might receive a JSON::ParserError when, for example, MeiliSearch is running behind
38+
# some proxy (ELB or Nginx, for example), and the request timeouts, returning us
39+
# a raw HTML body instead of a JSON as we were expecting
40+
@ms_message = "The server has not returned a valid JSON HTTP body: #{http_body}"
3641
end
3742

3843
def details

lib/meilisearch/http_request.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def http_delete(relative_path = '')
5454

5555
private
5656

57+
SNAKE_CASE = /[^a-zA-Z0-9]+(.)/.freeze
58+
5759
def send_request(http_method, relative_path, query_params = nil, body = nil)
5860
config = http_config(query_params, body)
5961
begin
@@ -65,7 +67,8 @@ def send_request(http_method, relative_path, query_params = nil, body = nil)
6567
end
6668

6769
def http_config(query_params, body)
68-
body = body.to_json
70+
body = transform_attributes(body).to_json
71+
6972
{
7073
headers: @headers,
7174
query: query_params,
@@ -75,6 +78,25 @@ def http_config(query_params, body)
7578
}.compact
7679
end
7780

81+
def transform_attributes(body)
82+
case body
83+
when Array
84+
body.map { |item| transform_attributes(item) }
85+
when Hash
86+
parse(body)
87+
else
88+
body
89+
end
90+
end
91+
92+
def parse(body)
93+
body
94+
.transform_keys(&:to_s)
95+
.transform_keys do |key|
96+
key.include?('_') ? key.downcase.gsub(SNAKE_CASE, &:upcase).gsub('_', '') : key
97+
end
98+
end
99+
78100
def validate(response)
79101
raise ApiError.new(response.code, response.message, response.body) unless response.success?
80102

lib/meilisearch/index.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
module MeiliSearch
77
class Index < HTTPRequest
8-
attr_reader :uid, :primary_key
8+
attr_reader :uid, :primary_key, :created_at, :updated_at
99

1010
def initialize(index_uid, url, api_key = nil, primary_key = nil, options = {})
1111
@uid = index_uid
@@ -16,12 +16,16 @@ def initialize(index_uid, url, api_key = nil, primary_key = nil, options = {})
1616
def fetch_info
1717
index_hash = http_get "/indexes/#{@uid}"
1818
@primary_key = index_hash['primaryKey']
19+
@created_at = Time.parse(index_hash['createdAt'])
20+
@updated_at = Time.parse(index_hash['updatedAt'])
1921
self
2022
end
2123

2224
def update(body)
2325
index_hash = http_put "/indexes/#{@uid}", body
2426
@primary_key = index_hash['primaryKey']
27+
@created_at = Time.parse(index_hash['createdAt'])
28+
@updated_at = Time.parse(index_hash['updatedAt'])
2529
self
2630
end
2731
alias update_index update
Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,29 @@
11
# frozen_string_literal: true
22

33
RSpec.describe 'MeiliSearch::Client - Dumps' do
4-
before(:all) do
5-
@client = MeiliSearch::Client.new(URL, MASTER_KEY)
6-
clear_all_indexes(@client)
7-
end
8-
94
it 'creates a new dump' do
10-
response = @client.create_dump
5+
response = client.create_dump
116
expect(response).to be_a(Hash)
127
expect(response['uid']).to_not be_nil
138
expect(response['status']).to_not be_nil
149
expect(response['status']).to eq('in_progress')
15-
wait_for_dump_creation(@client, response['uid'])
10+
wait_for_dump_creation(client, response['uid'])
1611
end
1712

1813
it 'gets dump status' do
19-
dump = @client.create_dump
20-
response = @client.dump_status(dump['uid'])
14+
dump = client.create_dump
15+
response = client.dump_status(dump['uid'])
2116
expect(response['status']).to_not be_nil
22-
wait_for_dump_creation(@client, dump['uid'])
17+
wait_for_dump_creation(client, dump['uid'])
2318
end
2419

2520
it 'fails to get dump status without uid' do
2621
expect do
27-
@client.dump_status('uid_not_exists')
22+
client.dump_status('uid_not_exists')
2823
end.to raise_meilisearch_api_error_with(404, 'not_found', 'invalid_request_error')
2924
end
3025

3126
it 'works with method aliases' do
32-
expect(@client.method(:dump_status) == @client.method(:get_dump_status)).to be_truthy
27+
expect(client.method(:dump_status) == client.method(:get_dump_status)).to be_truthy
3328
end
3429
end

0 commit comments

Comments
 (0)