meilisearch 0.23.0 → 0.26.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a02358b002d9f3a7b6f256140a01a8e3a55e90bab3b6a43889e8a23010bb0b4a
4
- data.tar.gz: e2f28298a8041755692c333bb778b5996226bc7889ab2d58dab9d9cae7a350e7
3
+ metadata.gz: e182244659129f40ceff661d8e117af391a68aa1cf5fed79f198fc715863ba4e
4
+ data.tar.gz: 17f9fd0b3b529829f1bd3d4d39cb3444532ec2cc14b0aebaeac00bae6f217d9b
5
5
  SHA512:
6
- metadata.gz: 0f4d24797d09a8176788fad8708d7dd9ac962b24d53db21a16d68ea16568935f9dc72e2c0160b50e516a45b7c2547e7afc8f0e4fc3534659daf3ec22f5b68d37
7
- data.tar.gz: 93f401846f98f6b388eb251fe804d862ed64d45ea346944364284da47f8c4d511a082746afde481ba6f7d8742a4d95693dd7e086c219cc9ba64e6a55fb15bd66
6
+ metadata.gz: 6aefe0097ef3f3c1785f1498ade5508ac77fca3e5aef025931d7ec34e12462419721cd2b7a1ee9d8c5037a36fa0dedd3aeabb35b473a400e05b9880401495149
7
+ data.tar.gz: 5b9949303254ca87e378904dadbbf0f7fc77a113cbda175dfb7bb950b674ed09742d411c0fb45cbc3a5626c6c16ebd1549e402b76504016b1e9567e28ba4e084
data/README.md CHANGED
@@ -6,16 +6,20 @@
6
6
 
7
7
  <h4 align="center">
8
8
  <a href="https://github.com/meilisearch/meilisearch">Meilisearch</a> |
9
+ <a href="https://www.meilisearch.com/cloud?utm_campaign=oss&utm_source=github&utm_medium=meilisearch-ruby">Meilisearch Cloud</a> |
9
10
  <a href="https://docs.meilisearch.com">Documentation</a> |
10
11
  <a href="https://discord.meilisearch.com">Discord</a> |
11
12
  <a href="https://roadmap.meilisearch.com/tabs/1-under-consideration">Roadmap</a> |
12
13
  <a href="https://www.meilisearch.com">Website</a> |
13
- <a href="https://docs.meilisearch.com/faq">FAQ</a>
14
+ <a href="https://www.meilisearch.com/docs/faq">FAQ</a>
14
15
  </h4>
15
16
 
16
17
  <p align="center">
17
18
  <a href="https://badge.fury.io/rb/meilisearch"><img src="https://badge.fury.io/rb/meilisearch.svg" alt="Latest Stable Version"></a>
18
19
  <a href="https://github.com/meilisearch/meilisearch-ruby/actions"><img src="https://github.com/meilisearch/meilisearch-ruby/workflows/Tests/badge.svg" alt="Test"></a>
20
+ <a href="https://app.codecov.io/gh/meilisearch/meilisearch-ruby/tree/main" >
21
+ <img src="https://codecov.io/gh/meilisearch/meilisearch-ruby/branch/main/graph/badge.svg?token=9J7LRP11IR"/>
22
+ </a>
19
23
  <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
24
  <a href="https://ms-bors.herokuapp.com/repositories/6"><img src="https://bors.tech/images/badge_small.svg" alt="Bors enabled"></a>
21
25
  </p>
@@ -26,9 +30,10 @@
26
30
 
27
31
  **Meilisearch** is an open-source search engine. [Learn more about Meilisearch.](https://github.com/meilisearch/meilisearch)
28
32
 
29
- ## Table of Contents <!-- omit in toc -->
33
+ ## Table of Contents <!-- omit in TOC -->
30
34
 
31
35
  - [📖 Documentation](#-documentation)
36
+ - [⚡ Supercharge your Meilisearch experience](#-supercharge-your-meilisearch-experience)
32
37
  - [🔧 Installation](#-installation)
33
38
  - [🚀 Getting started](#-getting-started)
34
39
  - [🤖 Compatibility with Meilisearch](#-compatibility-with-meilisearch)
@@ -39,9 +44,13 @@
39
44
 
40
45
  This readme contains all the documentation you need to start using this Meilisearch SDK.
41
46
 
42
- For general information on how to use Meilisearch—such as our API reference, tutorials, guides, and in-depth articles—refer to our [main documentation website](https://docs.meilisearch.com/).
47
+ For general information on how to use Meilisearch—such as our API reference, tutorials, guides, and in-depth articles—refer to our [main documentation website](https://www.meilisearch.com/docs/).
43
48
 
44
49
 
50
+ ## ⚡ Supercharge your Meilisearch experience
51
+
52
+ Say goodbye to server deployment and manual updates with [Meilisearch Cloud](https://www.meilisearch.com/cloud?utm_campaign=oss&utm_source=github&utm_medium=meilisearch-ruby). Get started with a 14-day free trial! No credit card required.
53
+
45
54
  ## 🔧 Installation
46
55
 
47
56
  This package requires Ruby version 2.6.0 or later.
@@ -60,12 +69,12 @@ gem 'meilisearch'
60
69
 
61
70
  ### Run Meilisearch <!-- omit in toc -->
62
71
 
63
- There are many easy ways to [download and run a Meilisearch instance](https://docs.meilisearch.com/reference/features/installation.html#download-and-launch).
72
+ There are many easy ways to [download and run a Meilisearch instance](https://www.meilisearch.com/docs/learn/getting_started/quick_start#setup-and-installation).
64
73
 
65
- For example, using the `curl` command in your [Terminal](https://itconnect.uw.edu/learn/workshops/online-tutorials/web-publishing/what-is-a-terminal/):
74
+ For example, using the `curl` command in your [Terminal](https://itconnect.uw.edu/learn/workshops/online-tutorials/what-is-a-terminal/):
66
75
 
67
76
  ```sh
68
- #Install Meilisearch
77
+ # Install Meilisearch
69
78
  curl -L https://install.meilisearch.com | sh
70
79
 
71
80
  # Launch Meilisearch
@@ -98,7 +107,7 @@ documents = [
98
107
  index.add_documents(documents) # => { "uid": 0 }
99
108
  ```
100
109
 
101
- With the `uid`, you can check the status (`enqueued`, `processing`, `succeeded` or `failed`) of your documents addition using the [task](https://docs.meilisearch.com/reference/api/tasks.html#get-task).
110
+ With the `uid`, you can check the status (`enqueued`, `canceled`, `processing`, `succeeded` or `failed`) of your documents addition using the [task](https://www.meilisearch.com/docs/reference/api/tasks#get-tasks).
102
111
 
103
112
  💡 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.
104
113
 
@@ -125,7 +134,7 @@ Output:
125
134
 
126
135
  #### Custom search <!-- omit in toc -->
127
136
 
128
- All the supported options are described in the [search parameters](https://docs.meilisearch.com/reference/features/search_parameters.html) section of the documentation.
137
+ All the supported options are described in the [search parameters](https://www.meilisearch.com/docs/reference/api/search#search-parameters) section of the documentation.
129
138
 
130
139
  ```ruby
131
140
  index.search(
@@ -168,7 +177,7 @@ index.update_filterable_attributes([
168
177
 
169
178
  You only need to perform this operation once.
170
179
 
171
- 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 [tasks](https://docs.meilisearch.com/reference/api/tasks.html#get-task)).
180
+ 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 [tasks](https://www.meilisearch.com/docs/reference/api/tasks#get-tasks)).
172
181
 
173
182
  Then, you can perform the search:
174
183
 
@@ -198,6 +207,82 @@ JSON output:
198
207
  }
199
208
  ```
200
209
 
210
+ #### Display ranking details at search
211
+
212
+ JSON output:
213
+
214
+ ```json
215
+ {
216
+ "hits": [
217
+ {
218
+ "id": 15359,
219
+ "title": "Wonder Woman",
220
+ "_rankingScoreDetails": {
221
+ "words": {
222
+ "order": 0,
223
+ "matchingWords": 2,
224
+ "maxMatchingWords": 2,
225
+ "score": 1.0
226
+ },
227
+ "typo": {
228
+ "order": 1,
229
+ "typoCount": 0,
230
+ "maxTypoCount": 2,
231
+ "score": 1.0
232
+ },
233
+ "proximity": {
234
+ "order": 2,
235
+ "score": 1.0
236
+ },
237
+ "attribute": {
238
+ "order": 3,
239
+ "attributeRankingOrderScore": 0.8181818181818182,
240
+ "queryWordDistanceScore": 1.0,
241
+ "score": 0.8181818181818182
242
+ },
243
+ "exactness": {
244
+ "order": 4,
245
+ "matchType": "exactMatch",
246
+ "score": 1.0
247
+ }
248
+ }
249
+ }
250
+ ]
251
+ }
252
+ ```
253
+
254
+ You can enable it by querying PATCH /experimental-features with { "scoreDetails": true }
255
+
256
+ This feature is only available with Meilisearch v1.3 and newer (optional).
257
+
258
+ #### Custom Search With attributes on at search time <!-- omit in toc -->
259
+
260
+ [Customize attributes to search on at search time](https://www.meilisearch.com/docs/reference/api/search#customize-attributes-to-search-on-at-search-time).
261
+
262
+ you can perform the search :
263
+
264
+ ```ruby
265
+ index.search('wonder', { attributes_to_search_on: ['genres'] })
266
+ ```
267
+
268
+
269
+ JSON output:
270
+
271
+ ```json
272
+ {
273
+ "hits":[],
274
+ "query":"wonder",
275
+ "processingTimeMs":0,
276
+ "limit":20,
277
+ "offset":0,
278
+ "estimatedTotalHits":0,
279
+ "nbHits":0
280
+ }
281
+ ```
282
+
283
+ This feature is only available with Meilisearch v1.3 and newer (optional).
284
+
285
+
201
286
  ## 🤖 Compatibility with Meilisearch
202
287
 
203
288
  This package guarantees compatibility with [version v1.x of Meilisearch](https://github.com/meilisearch/meilisearch/releases/latest), but some features may not be present. Please check the [issues](https://github.com/meilisearch/meilisearch-ruby/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22+label%3Aenhancement) for more info.
@@ -206,12 +291,12 @@ This package guarantees compatibility with [version v1.x of Meilisearch](https:/
206
291
 
207
292
  The following sections in our main documentation website may interest you:
208
293
 
209
- - **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).
210
- - **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).
211
- - **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).
212
- - **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).
294
+ - **Manipulate documents**: see the [API references](https://www.meilisearch.com/docs/reference/api/documents) or read more about [documents](https://www.meilisearch.com/docs/learn/core_concepts/documents).
295
+ - **Search**: see the [API references](https://www.meilisearch.com/docs/reference/api/search) or follow our guide on [search parameters](https://www.meilisearch.com/docs/reference/api/search#search-parameters).
296
+ - **Manage the indexes**: see the [API references](https://www.meilisearch.com/docs/reference/api/indexes) or read more about [indexes](https://www.meilisearch.com/docs/learn/core_concepts/indexes).
297
+ - **Configure the index settings**: see the [API references](https://www.meilisearch.com/docs/reference/api/settings) or follow our guide on [settings parameters](https://www.meilisearch.com/docs/reference/api/settings).
213
298
 
214
- 📖 Also, check out the [Wiki](https://github.com/meilisearch/meilisearch-ruby/wiki) of this repository to know what this SDK provdes!
299
+ 📖 Also, check out the [Wiki](https://github.com/meilisearch/meilisearch-ruby/wiki) of this repository to know what this SDK provides!
215
300
 
216
301
  ## ⚙️ Contributing
217
302
 
@@ -31,7 +31,7 @@ module MeiliSearch
31
31
 
32
32
  # Usage:
33
33
  # client.create_index('indexUID')
34
- # client.create_index('indexUID', primaryKey: 'id')
34
+ # client.create_index('indexUID', primary_key: 'id')
35
35
  def create_index(index_uid, options = {})
36
36
  body = Utils.transform_attributes(options.merge(uid: index_uid))
37
37
 
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MeiliSearch
4
- class ApiError < StandardError
4
+ class Error < StandardError
5
+ end
6
+
7
+ class ApiError < Error
5
8
  # :http_code # e.g. 400, 404...
6
9
  # :http_message # e.g. Bad Request, Not Found...
7
10
  # :http_body # The response body received from the MeiliSearch API
@@ -45,7 +48,7 @@ module MeiliSearch
45
48
  end
46
49
  end
47
50
 
48
- class CommunicationError < StandardError
51
+ class CommunicationError < Error
49
52
  attr_reader :message
50
53
 
51
54
  def initialize(message)
@@ -54,7 +57,7 @@ module MeiliSearch
54
57
  end
55
58
  end
56
59
 
57
- class TimeoutError < StandardError
60
+ class TimeoutError < Error
58
61
  attr_reader :message
59
62
 
60
63
  def initialize(message = nil)
@@ -64,8 +67,8 @@ module MeiliSearch
64
67
  end
65
68
 
66
69
  module TenantToken
67
- class ExpireOrInvalidSignature < StandardError; end
68
- class InvalidApiKey < StandardError; end
69
- class InvalidSearchRules < StandardError; end
70
+ class ExpireOrInvalidSignature < MeiliSearch::Error; end
71
+ class InvalidApiKey < MeiliSearch::Error; end
72
+ class InvalidSearchRules < MeiliSearch::Error; end
70
73
  end
71
74
  end
@@ -63,8 +63,24 @@ module MeiliSearch
63
63
  alias get_document document
64
64
  alias get_one_document document
65
65
 
66
+ # Public: Retrieve documents from a index.
67
+ #
68
+ # options - The hash options used to refine the selection (default: {}):
69
+ # :limit - Number of documents to return (optional).
70
+ # :offset - Number of documents to skip (optional).
71
+ # :fields - Array of document attributes to show (optional).
72
+ # :filter - Filter queries by an attribute's value.
73
+ # Available ONLY with Meilisearch v1.2 and newer (optional).
74
+ #
75
+ # Returns the documents results object.
66
76
  def documents(options = {})
67
- http_get "/indexes/#{@uid}/documents", Utils.parse_query(options, [:limit, :offset, :fields])
77
+ Utils.version_error_handler(__method__) do
78
+ if options.key?(:filter)
79
+ http_post "/indexes/#{@uid}/documents/fetch", Utils.filter(options, [:limit, :offset, :fields, :filter])
80
+ else
81
+ http_get "/indexes/#{@uid}/documents", Utils.parse_query(options, [:limit, :offset, :fields])
82
+ end
83
+ end
68
84
  end
69
85
  alias get_documents documents
70
86
 
@@ -153,11 +169,24 @@ module MeiliSearch
153
169
  responses
154
170
  end
155
171
 
156
- def delete_documents(documents_ids)
157
- if documents_ids.is_a?(Array)
158
- http_post "/indexes/#{@uid}/documents/delete-batch", documents_ids
159
- else
160
- delete_document(documents_ids)
172
+ # Public: Delete documents from an index
173
+ #
174
+ # options: A Hash or an Array containing documents_ids or a hash with filter:.
175
+ # filter: - A hash containing a filter that should match documents.
176
+ # Available ONLY with Meilisearch v1.2 and newer (optional)
177
+ #
178
+ # Returns a Task object.
179
+ def delete_documents(options = {})
180
+ Utils.version_error_handler(__method__) do
181
+ if options.is_a?(Hash) && options.key?(:filter)
182
+ http_post "/indexes/#{@uid}/documents/delete", options
183
+ else
184
+ # backwards compatibility:
185
+ # expect to be a array or/number/string to send alongside as documents_ids.
186
+ options = [options] unless options.is_a?(Array)
187
+
188
+ http_post "/indexes/#{@uid}/documents/delete-batch", options
189
+ end
161
190
  end
162
191
  end
163
192
  alias delete_multiple_documents delete_documents
@@ -191,9 +220,13 @@ module MeiliSearch
191
220
 
192
221
  ### SEARCH
193
222
 
223
+ # options: A Hash
224
+ # show_ranking_score - To see the ranking scores for returned documents
225
+ # attributes_to_search_on - Customize attributes to search on at search time.
194
226
  def search(query, options = {})
195
- parsed_options = Utils.transform_attributes({ q: query.to_s }.merge(options.compact))
227
+ attributes = { q: query.to_s }.merge(options.compact)
196
228
 
229
+ parsed_options = Utils.transform_attributes(attributes)
197
230
  response = http_post "/indexes/#{@uid}/search", parsed_options
198
231
 
199
232
  response['nbHits'] ||= response['estimatedTotalHits'] unless response.key?('totalPages')
@@ -201,6 +234,15 @@ module MeiliSearch
201
234
  response
202
235
  end
203
236
 
237
+ ### FACET SEARCH
238
+
239
+ def facet_search(name, query = '', **options)
240
+ options.merge!(facet_name: name, facet_query: query)
241
+ options = Utils.transform_attributes(options)
242
+
243
+ http_post("/indexes/#{@uid}/facet-search", options)
244
+ end
245
+
204
246
  ### TASKS
205
247
 
206
248
  def task_endpoint
@@ -428,5 +470,49 @@ module MeiliSearch
428
470
  def reset_faceting
429
471
  http_delete("/indexes/#{@uid}/settings/faceting")
430
472
  end
473
+
474
+ ### SETTINGS - DICTIONARY
475
+
476
+ def dictionary
477
+ http_get("/indexes/#{@uid}/settings/dictionary")
478
+ end
479
+
480
+ def update_dictionary(dictionary_attributes)
481
+ attributes = Utils.transform_attributes(dictionary_attributes)
482
+ http_put("/indexes/#{@uid}/settings/dictionary", attributes)
483
+ end
484
+
485
+ def reset_dictionary
486
+ http_delete("/indexes/#{@uid}/settings/dictionary")
487
+ end
488
+ ### SETTINGS - SEPARATOR TOKENS
489
+
490
+ def separator_tokens
491
+ http_get("/indexes/#{@uid}/settings/separator-tokens")
492
+ end
493
+
494
+ def update_separator_tokens(separator_tokens_attributes)
495
+ attributes = Utils.transform_attributes(separator_tokens_attributes)
496
+ http_put("/indexes/#{@uid}/settings/separator-tokens", attributes)
497
+ end
498
+
499
+ def reset_separator_tokens
500
+ http_delete("/indexes/#{@uid}/settings/separator-tokens")
501
+ end
502
+
503
+ ### SETTINGS - NON SEPARATOR TOKENS
504
+
505
+ def non_separator_tokens
506
+ http_get("/indexes/#{@uid}/settings/non-separator-tokens")
507
+ end
508
+
509
+ def update_non_separator_tokens(non_separator_tokens_attributes)
510
+ attributes = Utils.transform_attributes(non_separator_tokens_attributes)
511
+ http_put("/indexes/#{@uid}/settings/non-separator-tokens", attributes)
512
+ end
513
+
514
+ def reset_non_separator_tokens
515
+ http_delete("/indexes/#{@uid}/settings/non-separator-tokens")
516
+ end
431
517
  end
432
518
  end
@@ -9,6 +9,7 @@ module MeiliSearch
9
9
  when Array
10
10
  body.map { |item| transform_attributes(item) }
11
11
  when Hash
12
+ warn_on_non_conforming_attribute_names(body)
12
13
  parse(body)
13
14
  else
14
15
  body
@@ -23,8 +24,12 @@ module MeiliSearch
23
24
  end
24
25
  end
25
26
 
27
+ def self.filter(original_options, allowed_params = [])
28
+ original_options.transform_keys(&:to_sym).slice(*allowed_params)
29
+ end
30
+
26
31
  def self.parse_query(original_options, allowed_params = [])
27
- only_allowed_params = original_options.transform_keys(&:to_sym).slice(*allowed_params)
32
+ only_allowed_params = filter(original_options, allowed_params)
28
33
 
29
34
  Utils.transform_attributes(only_allowed_params).then do |body|
30
35
  body.transform_values do |v|
@@ -33,6 +38,36 @@ module MeiliSearch
33
38
  end
34
39
  end
35
40
 
36
- private_class_method :parse
41
+ def self.message_builder(current_message, method_name)
42
+ "#{current_message}\nHint: It might not be working because maybe you're not up " \
43
+ "to date with the Meilisearch version that `#{method_name}` call requires."
44
+ end
45
+
46
+ def self.version_error_handler(method_name)
47
+ yield if block_given?
48
+ rescue MeiliSearch::ApiError => e
49
+ message = message_builder(e.http_message, method_name)
50
+
51
+ raise MeiliSearch::ApiError.new(e.http_code, message, e.http_body)
52
+ rescue StandardError => e
53
+ raise e.class, message_builder(e.message, method_name)
54
+ end
55
+
56
+ def self.warn_on_non_conforming_attribute_names(body)
57
+ return if body.nil?
58
+
59
+ non_snake_case = body.keys.grep_v(/^[a-z0-9_]+$/)
60
+ return if non_snake_case.empty?
61
+
62
+ message = <<~MSG
63
+ Attributes will be expected to be snake_case in future versions of Meilisearch Ruby.
64
+
65
+ Non-conforming attributes: #{non_snake_case.join(', ')}
66
+ MSG
67
+
68
+ warn(message)
69
+ end
70
+
71
+ private_class_method :parse, :message_builder
37
72
  end
38
73
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MeiliSearch
4
- VERSION = '0.23.0'
4
+ VERSION = '0.26.0'
5
5
 
6
6
  def self.qualified_version
7
7
  "Meilisearch Ruby (v#{VERSION})"
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.23.0
4
+ version: 0.26.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Meili
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-03 00:00:00.000000000 Z
11
+ date: 2023-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty