meilisearch 0.17.2 → 0.17.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -0
- data/README.md +222 -0
- data/lib/meilisearch/http_request.rb +45 -20
- data/lib/meilisearch/index.rb +21 -0
- data/lib/meilisearch/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c90df98b1b08039b339c49b47bfd052639e1301e9e7e3b25989b9ce6e3d1e67
|
4
|
+
data.tar.gz: 3f200a9de09db7a47780b01aa20a8ce5b2b1d0d0579954cd8842cb208b06b4dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3b38312517176303e9fdc49af5c38647ea4d719d8988cb1e1fd60839e7c593226fd9369febd24a326d214dbb606acd201464fd6590f46438383cf25f3e7e934
|
7
|
+
data.tar.gz: 494fa30322be3d624851117e460c31046c51ea3ef4d00326f4be969a76f5f056a15147c065b1ef02a56f3a589643e137ac4af1a05a088bab606cdf6d31bc8abc
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019-2021 Meili
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,222 @@
|
|
1
|
+
<p align="center">
|
2
|
+
<img src="https://res.cloudinary.com/meilisearch/image/upload/v1587402338/SDKs/meilisearch_ruby.svg" alt="MeiliSearch-Ruby" width="200" height="200" />
|
3
|
+
</p>
|
4
|
+
|
5
|
+
<h1 align="center">MeiliSearch Ruby</h1>
|
6
|
+
|
7
|
+
<h4 align="center">
|
8
|
+
<a href="https://github.com/meilisearch/MeiliSearch">MeiliSearch</a> |
|
9
|
+
<a href="https://docs.meilisearch.com">Documentation</a> |
|
10
|
+
<a href="https://slack.meilisearch.com">Slack</a> |
|
11
|
+
<a href="https://roadmap.meilisearch.com/tabs/1-under-consideration">Roadmap</a> |
|
12
|
+
<a href="https://www.meilisearch.com">Website</a> |
|
13
|
+
<a href="https://docs.meilisearch.com/faq">FAQ</a>
|
14
|
+
</h4>
|
15
|
+
|
16
|
+
<p align="center">
|
17
|
+
<a href="https://badge.fury.io/rb/meilisearch"><img src="https://badge.fury.io/rb/meilisearch.svg" alt="Latest Stable Version"></a>
|
18
|
+
<a href="https://github.com/meilisearch/meilisearch-ruby/actions"><img src="https://github.com/meilisearch/meilisearch-ruby/workflows/Tests/badge.svg" alt="Test"></a>
|
19
|
+
<a href="https://github.com/meilisearch/meilisearch-ruby/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-informational" alt="License"></a>
|
20
|
+
<a href="https://app.bors.tech/repositories/28781"><img src="https://bors.tech/images/badge_small.svg" alt="Bors enabled"></a>
|
21
|
+
</p>
|
22
|
+
|
23
|
+
<p align="center">⚡ The MeiliSearch API client written for Ruby 💎</p>
|
24
|
+
|
25
|
+
**MeiliSearch Ruby** is the MeiliSearch API client for Ruby developers.
|
26
|
+
|
27
|
+
**MeiliSearch** is an open-source search engine. [Discover what MeiliSearch is!](https://github.com/meilisearch/MeiliSearch)
|
28
|
+
|
29
|
+
## Table of Contents <!-- omit in toc -->
|
30
|
+
|
31
|
+
- [📖 Documentation](#-documentation)
|
32
|
+
- [🔧 Installation](#-installation)
|
33
|
+
- [🚀 Getting Started](#-getting-started)
|
34
|
+
- [🤖 Compatibility with MeiliSearch](#-compatibility-with-meilisearch)
|
35
|
+
- [💡 Learn More](#-learn-more)
|
36
|
+
- [⚙️ Development Workflow and Contributing](#️-development-workflow-and-contributing)
|
37
|
+
|
38
|
+
## 📖 Documentation
|
39
|
+
|
40
|
+
See our [Documentation](https://docs.meilisearch.com/learn/tutorials/getting_started.html) or our [API References](https://docs.meilisearch.com/reference/api/).
|
41
|
+
|
42
|
+
## 🔧 Installation
|
43
|
+
|
44
|
+
This package requires Ruby version 2.6.0 or later.
|
45
|
+
|
46
|
+
With `gem` in command line:
|
47
|
+
```bash
|
48
|
+
gem install meilisearch
|
49
|
+
```
|
50
|
+
|
51
|
+
In your `Gemfile` with [bundler](https://bundler.io/):
|
52
|
+
```ruby
|
53
|
+
source 'https://rubygems.org'
|
54
|
+
|
55
|
+
gem 'meilisearch'
|
56
|
+
```
|
57
|
+
|
58
|
+
### Run MeiliSearch <!-- omit in toc -->
|
59
|
+
|
60
|
+
There are many easy ways to [download and run a MeiliSearch instance](https://docs.meilisearch.com/reference/features/installation.html#download-and-launch).
|
61
|
+
|
62
|
+
For example, using the `curl` command in your [Terminal](https://itconnect.uw.edu/learn/workshops/online-tutorials/web-publishing/what-is-a-terminal/):
|
63
|
+
|
64
|
+
```sh
|
65
|
+
#Install MeiliSearch
|
66
|
+
curl -L https://install.meilisearch.com | sh
|
67
|
+
|
68
|
+
# Launch MeiliSearch
|
69
|
+
./meilisearch --master-key=masterKey
|
70
|
+
```
|
71
|
+
|
72
|
+
NB: you can also download MeiliSearch from **Homebrew** or **APT** or even run it using **Docker**.
|
73
|
+
|
74
|
+
## 🚀 Getting Started
|
75
|
+
|
76
|
+
#### Add documents <!-- omit in toc -->
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
require 'meilisearch'
|
80
|
+
|
81
|
+
client = MeiliSearch::Client.new('http://127.0.0.1:7700', 'masterKey')
|
82
|
+
|
83
|
+
# An index is where the documents are stored.
|
84
|
+
index = client.index('movies')
|
85
|
+
|
86
|
+
documents = [
|
87
|
+
{ id: 1, title: 'Carol', genres: ['Romance', 'Drama'] },
|
88
|
+
{ id: 2, title: 'Wonder Woman', genres: ['Action', 'Adventure'] },
|
89
|
+
{ id: 3, title: 'Life of Pi', genres: ['Adventure', 'Drama'] },
|
90
|
+
{ id: 4, title: 'Mad Max: Fury Road', genres: ['Adventure', 'Science Fiction'] },
|
91
|
+
{ id: 5, title: 'Moana', genres: ['Fantasy', 'Action']},
|
92
|
+
{ id: 6, title: 'Philadelphia', genres: ['Drama'] },
|
93
|
+
]
|
94
|
+
# If the index 'movies' does not exist, MeiliSearch creates it when you first add the documents.
|
95
|
+
index.add_documents(documents) # => { "updateId": 0 }
|
96
|
+
```
|
97
|
+
|
98
|
+
With the `updateId`, you can check the status (`enqueued`, `processing`, `processed` or `failed`) of your documents addition using the [update endpoint](https://docs.meilisearch.com/reference/api/updates.html#get-an-update-status).
|
99
|
+
|
100
|
+
💡 To customize the `Client`, for example, increasing the default timeout, please check out [this section](https://github.com/meilisearch/meilisearch-ruby/wiki/Client-Options) of the Wiki.
|
101
|
+
|
102
|
+
#### Basic Search <!-- omit in toc -->
|
103
|
+
|
104
|
+
``` ruby
|
105
|
+
# MeiliSearch is typo-tolerant:
|
106
|
+
puts index.search('carlo')
|
107
|
+
```
|
108
|
+
Output:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
{
|
112
|
+
"hits" => [{
|
113
|
+
"id" => 1,
|
114
|
+
"title" => "Carol"
|
115
|
+
}],
|
116
|
+
"offset" => 0,
|
117
|
+
"limit" => 20,
|
118
|
+
"processingTimeMs" => 1,
|
119
|
+
"query" => "carlo"
|
120
|
+
}
|
121
|
+
```
|
122
|
+
|
123
|
+
#### Custom search <!-- omit in toc -->
|
124
|
+
|
125
|
+
All the supported options are described in the [search parameters](https://docs.meilisearch.com/reference/features/search_parameters.html) section of the documentation.
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
index.search(
|
129
|
+
'wonder',
|
130
|
+
attributes_to_highlight: ['*']
|
131
|
+
)
|
132
|
+
```
|
133
|
+
|
134
|
+
JSON output:
|
135
|
+
|
136
|
+
```json
|
137
|
+
{
|
138
|
+
"hits": [
|
139
|
+
{
|
140
|
+
"id": 2,
|
141
|
+
"title": "Wonder Woman",
|
142
|
+
"_formatted": {
|
143
|
+
"id": 2,
|
144
|
+
"title": "<em>Wonder</em> Woman"
|
145
|
+
}
|
146
|
+
}
|
147
|
+
],
|
148
|
+
"offset": 0,
|
149
|
+
"limit": 20,
|
150
|
+
"processingTimeMs": 0,
|
151
|
+
"query": "wonder"
|
152
|
+
}
|
153
|
+
```
|
154
|
+
|
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
|
+
|
199
|
+
## 🤖 Compatibility with MeiliSearch
|
200
|
+
|
201
|
+
This package only guarantees the compatibility with the [version v0.24.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.24.0).
|
202
|
+
|
203
|
+
## 💡 Learn More
|
204
|
+
|
205
|
+
The following sections may interest you:
|
206
|
+
|
207
|
+
- **Manipulate documents**: see the [API references](https://docs.meilisearch.com/reference/api/documents.html) or read more about [documents](https://docs.meilisearch.com/learn/core_concepts/documents.html).
|
208
|
+
- **Search**: see the [API references](https://docs.meilisearch.com/reference/api/search.html) or follow our guide on [search parameters](https://docs.meilisearch.com/reference/features/search_parameters.html).
|
209
|
+
- **Manage the indexes**: see the [API references](https://docs.meilisearch.com/reference/api/indexes.html) or read more about [indexes](https://docs.meilisearch.com/learn/core_concepts/indexes.html).
|
210
|
+
- **Configure the index settings**: see the [API references](https://docs.meilisearch.com/reference/api/settings.html) or follow our guide on [settings parameters](https://docs.meilisearch.com/reference/features/settings.html).
|
211
|
+
|
212
|
+
📖 Also, check out the [Wiki](https://github.com/meilisearch/meilisearch-ruby/wiki) of this repository to know what this SDK provdes!
|
213
|
+
|
214
|
+
## ⚙️ Development Workflow and Contributing
|
215
|
+
|
216
|
+
Any new contribution is more than welcome in this project!
|
217
|
+
|
218
|
+
If you want to know more about the development workflow or want to contribute, please visit our [contributing guidelines](/CONTRIBUTING.md) for detailed instructions!
|
219
|
+
|
220
|
+
<hr>
|
221
|
+
|
222
|
+
**MeiliSearch** provides and maintains many **SDKs and Integration tools** like this one. We want to provide everyone with an **amazing search experience for any kind of project**. If you want to contribute, make suggestions, or just know what's going on right now, visit us in the [integration-guides](https://github.com/meilisearch/integration-guides) repository.
|
@@ -12,14 +12,12 @@ module MeiliSearch
|
|
12
12
|
def initialize(url, api_key = nil, options = {})
|
13
13
|
@base_url = url
|
14
14
|
@api_key = api_key
|
15
|
-
@options =
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
'X-Meili-API-Key' => api_key
|
22
|
-
}.compact
|
15
|
+
@options = merge_options({
|
16
|
+
timeout: 1,
|
17
|
+
max_retries: 0,
|
18
|
+
headers: build_default_options_headers(api_key),
|
19
|
+
convert_body?: true
|
20
|
+
}, options)
|
23
21
|
end
|
24
22
|
|
25
23
|
def http_get(relative_path = '', query_params = {})
|
@@ -27,17 +25,17 @@ module MeiliSearch
|
|
27
25
|
proc { |path, config| self.class.get(path, config) },
|
28
26
|
relative_path,
|
29
27
|
query_params: query_params,
|
30
|
-
|
28
|
+
options: remove_options_header(@options, 'Content-Type')
|
31
29
|
)
|
32
30
|
end
|
33
31
|
|
34
|
-
def http_post(relative_path = '', body = nil, query_params = nil)
|
32
|
+
def http_post(relative_path = '', body = nil, query_params = nil, options = {})
|
35
33
|
send_request(
|
36
34
|
proc { |path, config| self.class.post(path, config) },
|
37
35
|
relative_path,
|
38
36
|
query_params: query_params,
|
39
37
|
body: body,
|
40
|
-
|
38
|
+
options: merge_options(@options, options)
|
41
39
|
)
|
42
40
|
end
|
43
41
|
|
@@ -47,7 +45,7 @@ module MeiliSearch
|
|
47
45
|
relative_path,
|
48
46
|
query_params: query_params,
|
49
47
|
body: body,
|
50
|
-
|
48
|
+
options: @options
|
51
49
|
)
|
52
50
|
end
|
53
51
|
|
@@ -55,14 +53,40 @@ module MeiliSearch
|
|
55
53
|
send_request(
|
56
54
|
proc { |path, config| self.class.delete(path, config) },
|
57
55
|
relative_path,
|
58
|
-
|
56
|
+
options: remove_options_header(@options, 'Content-Type')
|
59
57
|
)
|
60
58
|
end
|
61
59
|
|
62
60
|
private
|
63
61
|
|
64
|
-
def
|
65
|
-
|
62
|
+
def build_default_options_headers(api_key = nil)
|
63
|
+
{
|
64
|
+
'Content-Type' => 'application/json',
|
65
|
+
'X-Meili-API-Key' => api_key
|
66
|
+
}.compact
|
67
|
+
end
|
68
|
+
|
69
|
+
def merge_options(default_options, added_options = {})
|
70
|
+
default_cloned_headers = default_options[:headers].clone
|
71
|
+
merged_options = default_options.merge(added_options)
|
72
|
+
merged_options[:headers] = default_cloned_headers.merge(added_options[:headers]) if added_options.key?(:headers)
|
73
|
+
merged_options
|
74
|
+
end
|
75
|
+
|
76
|
+
def remove_options_header(options, key)
|
77
|
+
cloned_options = clone_options(options)
|
78
|
+
cloned_options[:headers].tap { |headers| headers.delete(key) }
|
79
|
+
cloned_options
|
80
|
+
end
|
81
|
+
|
82
|
+
def clone_options(options)
|
83
|
+
cloned_options = options.clone
|
84
|
+
cloned_options[:headers] = options[:headers].clone
|
85
|
+
cloned_options
|
86
|
+
end
|
87
|
+
|
88
|
+
def send_request(http_method, relative_path, query_params: nil, body: nil, options: {})
|
89
|
+
config = http_config(query_params, body, options)
|
66
90
|
begin
|
67
91
|
response = http_method.call(@base_url + relative_path, config)
|
68
92
|
rescue Errno::ECONNREFUSED => e
|
@@ -71,13 +95,14 @@ module MeiliSearch
|
|
71
95
|
validate(response)
|
72
96
|
end
|
73
97
|
|
74
|
-
def http_config(query_params, body,
|
98
|
+
def http_config(query_params, body, options)
|
99
|
+
body = body.to_json if options[:convert_body?] == true
|
75
100
|
{
|
76
|
-
headers: headers,
|
101
|
+
headers: options[:headers],
|
77
102
|
query: query_params,
|
78
|
-
body: body
|
79
|
-
timeout:
|
80
|
-
max_retries:
|
103
|
+
body: body,
|
104
|
+
timeout: options[:timeout],
|
105
|
+
max_retries: options[:max_retries]
|
81
106
|
}.compact
|
82
107
|
end
|
83
108
|
|
data/lib/meilisearch/index.rb
CHANGED
@@ -84,6 +84,27 @@ module MeiliSearch
|
|
84
84
|
alias replace_documents! add_documents!
|
85
85
|
alias add_or_replace_documents! add_documents!
|
86
86
|
|
87
|
+
def add_documents_json(documents, primary_key = nil)
|
88
|
+
options = { headers: { 'Content-Type' => 'application/json' }, convert_body?: false }
|
89
|
+
http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact, options
|
90
|
+
end
|
91
|
+
alias replace_documents_json add_documents_json
|
92
|
+
alias add_or_replace_documents_json add_documents_json
|
93
|
+
|
94
|
+
def add_documents_ndjson(documents, primary_key = nil)
|
95
|
+
options = { headers: { 'Content-Type' => 'application/x-ndjson' }, convert_body?: false }
|
96
|
+
http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact, options
|
97
|
+
end
|
98
|
+
alias replace_documents_ndjson add_documents_ndjson
|
99
|
+
alias add_or_replace_documents_ndjson add_documents_ndjson
|
100
|
+
|
101
|
+
def add_documents_csv(documents, primary_key = nil)
|
102
|
+
options = { headers: { 'Content-Type' => 'text/csv' }, convert_body?: false }
|
103
|
+
http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact, options
|
104
|
+
end
|
105
|
+
alias replace_documents_csv add_documents_csv
|
106
|
+
alias add_or_replace_documents_csv add_documents_csv
|
107
|
+
|
87
108
|
def update_documents(documents, primary_key = nil)
|
88
109
|
documents = [documents] if documents.is_a?(Hash)
|
89
110
|
http_put "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact
|
data/lib/meilisearch/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meilisearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.17.
|
4
|
+
version: 0.17.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Meili
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -36,6 +36,8 @@ executables: []
|
|
36
36
|
extensions: []
|
37
37
|
extra_rdoc_files: []
|
38
38
|
files:
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
39
41
|
- lib/meilisearch.rb
|
40
42
|
- lib/meilisearch/client.rb
|
41
43
|
- lib/meilisearch/error.rb
|