Skip to content

Commit f1985df

Browse files
committed
Merge branch 'main' into add-method-to-get-the-raw-index-information
# Conflicts: # spec/meilisearch/client/indexes_spec.rb
2 parents 8f5c594 + 0f9b405 commit f1985df

File tree

14 files changed

+298
-135
lines changed

14 files changed

+298
-135
lines changed

.code-samples.meilisearch.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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: |-

CONTRIBUTING.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,26 @@ To update it, run the following command:
8989
bundle exec rubocop --auto-gen-config
9090
```
9191

92+
### Using Docker Compose <!-- omit in toc -->
93+
94+
If you have Docker and Docker Compose installed, you can alternatively set up your local development environment following the steps below.
95+
96+
```bash
97+
# Create/run the containers
98+
docker compose up -d
99+
# Run bash in meilisearch_ruby container
100+
docker compose exec meilisearch_ruby bash
101+
```
102+
103+
You can now run the previous steps in the `meilisearc_ruby` container:
104+
105+
```bash
106+
bundle install
107+
bundle exec rspec
108+
bundle exec rubocop lib/ spec/
109+
...
110+
```
111+
92112
### Want to debug? <!-- omit in toc -->
93113

94114
You can use the [`byebug` gem](https://github.com/deivid-rodriguez/byebug).

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,50 @@ JSON output:
152152
}
153153
```
154154

155+
#### Custom Search With Filters <!-- omit in toc -->
156+
157+
If you want to enable filtering, you must add your attributes to the `filterableAttributes` index setting.
158+
159+
```ruby
160+
index.update_filterable_attributes([
161+
'id',
162+
'genres'
163+
])
164+
```
165+
166+
You only need to perform this operation once.
167+
168+
Note that MeiliSearch will rebuild your index whenever you update `filterableAttributes`. Depending on the size of your dataset, this might take time. You can track the process using the [update status](https://docs.meilisearch.com/reference/api/updates.html#get-an-update-status).
169+
170+
Then, you can perform the search:
171+
172+
```ruby
173+
index.search('wonder', { filter: ['id > 1 AND genres = Action'] })
174+
```
175+
176+
JSON output:
177+
178+
```json
179+
{
180+
"hits": [
181+
{
182+
"id": 2,
183+
"title": "Wonder Woman",
184+
"genres": [
185+
"Action",
186+
"Adventure"
187+
]
188+
}
189+
],
190+
"nbHits": 1,
191+
"exhaustiveNbHits": false,
192+
"query": "wonder",
193+
"limit": 20,
194+
"offset": 0,
195+
"processingTimeMs": 0
196+
}
197+
```
198+
155199
## 🤖 Compatibility with MeiliSearch
156200

157201
This package only guarantees the compatibility with the [version v0.23.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.23.0).

docker-compose.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: "3.7"
2+
3+
services:
4+
meilisearch_ruby:
5+
image: ruby
6+
tty: true
7+
stdin_open: true
8+
working_dir: /home/app
9+
environment:
10+
- MEILISEARCH_HOST=meilisearch
11+
- MEILISEARCH_PORT=7700
12+
ports:
13+
- "3001:3000"
14+
volumes:
15+
- ./:/home/app
16+
17+
meilisearch:
18+
image: getmeili/meilisearch:latest
19+
tty: true
20+
stdin_open: true
21+
container_name: meilisearch
22+
ports:
23+
- "7700:7700"
24+
# Uncomment this to run the test suite
25+
# environment:
26+
# - MEILI_MASTER_KEY=masterKey

lib/meilisearch/client.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ module MeiliSearch
66
class Client < HTTPRequest
77
### INDEXES
88

9+
def raw_indexes
10+
http_get('/indexes')
11+
end
12+
913
def indexes
10-
http_get '/indexes'
14+
raw_indexes.map do |index_hash|
15+
index_object(index_hash['uid'], index_hash['primaryKey'])
16+
end
1117
end
1218

1319
# Usage:

lib/meilisearch/http_request.rb

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,54 @@ def initialize(url, api_key = nil, options = {})
1717
'Content-Type' => 'application/json',
1818
'X-Meili-API-Key' => api_key
1919
}.compact
20+
@headers_no_body = {
21+
'X-Meili-API-Key' => api_key
22+
}.compact
2023
end
2124

2225
def http_get(relative_path = '', query_params = {})
2326
send_request(
2427
proc { |path, config| self.class.get(path, config) },
2528
relative_path,
26-
query_params
29+
query_params: query_params,
30+
headers: @headers_no_body
2731
)
2832
end
2933

3034
def http_post(relative_path = '', body = nil, query_params = nil)
3135
send_request(
3236
proc { |path, config| self.class.post(path, config) },
3337
relative_path,
34-
query_params,
35-
body
38+
query_params: query_params,
39+
body: body,
40+
headers: @headers
3641
)
3742
end
3843

3944
def http_put(relative_path = '', body = nil, query_params = nil)
4045
send_request(
4146
proc { |path, config| self.class.put(path, config) },
4247
relative_path,
43-
query_params,
44-
body
48+
query_params: query_params,
49+
body: body,
50+
headers: @headers
4551
)
4652
end
4753

4854
def http_delete(relative_path = '')
4955
send_request(
5056
proc { |path, config| self.class.delete(path, config) },
51-
relative_path
57+
relative_path,
58+
headers: @headers_no_body
5259
)
5360
end
5461

5562
private
5663

5764
SNAKE_CASE = /[^a-zA-Z0-9]+(.)/.freeze
5865

59-
def send_request(http_method, relative_path, query_params = nil, body = nil)
60-
config = http_config(query_params, body)
66+
def send_request(http_method, relative_path, query_params: nil, body: nil, headers: nil)
67+
config = http_config(query_params, body, headers)
6168
begin
6269
response = http_method.call(@base_url + relative_path, config)
6370
rescue Errno::ECONNREFUSED => e
@@ -66,11 +73,10 @@ def send_request(http_method, relative_path, query_params = nil, body = nil)
6673
validate(response)
6774
end
6875

69-
def http_config(query_params, body)
76+
def http_config(query_params, body, headers)
7077
body = transform_attributes(body).to_json
71-
7278
{
73-
headers: @headers,
79+
headers: headers,
7480
query: query_params,
7581
body: body,
7682
timeout: @options[:timeout] || 1,

0 commit comments

Comments
 (0)