meilisearch 0.23.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a02358b002d9f3a7b6f256140a01a8e3a55e90bab3b6a43889e8a23010bb0b4a
4
- data.tar.gz: e2f28298a8041755692c333bb778b5996226bc7889ab2d58dab9d9cae7a350e7
3
+ metadata.gz: 6503fb7f801990fd58fee344cdd3ea25edc549ddf2423b59c2ca84b2bcd11390
4
+ data.tar.gz: dfbb61ed72936cf705cddbdf76601ea94250dbf0cd95142e54d6a4f82771307d
5
5
  SHA512:
6
- metadata.gz: 0f4d24797d09a8176788fad8708d7dd9ac962b24d53db21a16d68ea16568935f9dc72e2c0160b50e516a45b7c2547e7afc8f0e4fc3534659daf3ec22f5b68d37
7
- data.tar.gz: 93f401846f98f6b388eb251fe804d862ed64d45ea346944364284da47f8c4d511a082746afde481ba6f7d8742a4d95693dd7e086c219cc9ba64e6a55fb15bd66
6
+ metadata.gz: 5b0820f6b28e681410a4dde5538d8fb87dddba5f28d40ff5807d54c94e7886f3778b95e0b6c4658dabb6bd55c5698b27ca18fc051d00b60f138aeb3160e47260
7
+ data.tar.gz: aa7f20470f2014ae5a9526768c9418fd91d08478553254eb20e9600fbaf004042f7d585a5d3865c78c5db5daa024d1a583f048fef9b1428c1b73f09268327dc9
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>
@@ -29,6 +33,7 @@
29
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
 
@@ -206,12 +215,12 @@ This package guarantees compatibility with [version v1.x of Meilisearch](https:/
206
215
 
207
216
  The following sections in our main documentation website may interest you:
208
217
 
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).
218
+ - **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).
219
+ - **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).
220
+ - **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).
221
+ - **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
222
 
214
- 📖 Also, check out the [Wiki](https://github.com/meilisearch/meilisearch-ruby/wiki) of this repository to know what this SDK provdes!
223
+ 📖 Also, check out the [Wiki](https://github.com/meilisearch/meilisearch-ruby/wiki) of this repository to know what this SDK provides!
215
224
 
216
225
  ## ⚙️ Contributing
217
226
 
@@ -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
 
@@ -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
@@ -192,8 +221,9 @@ module MeiliSearch
192
221
  ### SEARCH
193
222
 
194
223
  def search(query, options = {})
195
- parsed_options = Utils.transform_attributes({ q: query.to_s }.merge(options.compact))
224
+ attributes = { q: query.to_s }.merge(options.compact)
196
225
 
226
+ parsed_options = Utils.transform_attributes(attributes)
197
227
  response = http_post "/indexes/#{@uid}/search", parsed_options
198
228
 
199
229
  response['nbHits'] ||= response['estimatedTotalHits'] unless response.key?('totalPages')
@@ -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.25.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.25.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-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty