meilisearch 0.22.0 → 0.24.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: f2556e7bd3fe01c37c9cc3c19a16d912e6e105a6b0f6089abdc3dd1d0e88111b
4
- data.tar.gz: 452a6e9453809e2ed86fd119efaf1e447d090f498d09e6c26f248aa9caa1d37f
3
+ metadata.gz: a6fbd8b345ade69adfd322c7cf10e0e1acca19ecdbf84eb0ef7f04b8ce2ec810
4
+ data.tar.gz: 88c9635e0310e89f3a793a7ff39741e49c88f1bcf7f9916c2f2873642dd329d0
5
5
  SHA512:
6
- metadata.gz: 94e85529b349d311d94f822461f157d3ca9b1409b896b3867b0bf9cabcbe6bfbcb07c23ced479629837756f0ca8a98df1a3d691dcfe768613df8a965e37c28bc
7
- data.tar.gz: f7838589d5b9f3f2b7b87ed3fed398c693555708091d869438557849b099c83ded82f308a897713d46d3e00cb4ccf5ddad73e278f18c3face25688ed2130ce96
6
+ metadata.gz: 9d674d11207d8f829d132996f01a2f6ed59da3f79d004c518df6d1ec73c8c7f966b5179da373a90d00073dc813a2cd3a74cb46efb6212b5dc3958fe2b7c27118
7
+ data.tar.gz: d5912112b1a69edafff5825d63d488d6d0ffc7106c7ec807d992f1eef9e7c0f6a635b54fe3b716afe6d372fad95cce10bcac4231ba233ec07a839e7ebc8e14f0
data/README.md CHANGED
@@ -60,12 +60,12 @@ gem 'meilisearch'
60
60
 
61
61
  ### Run Meilisearch <!-- omit in toc -->
62
62
 
63
- There are many easy ways to [download and run a Meilisearch instance](https://docs.meilisearch.com/reference/features/installation.html#download-and-launch).
63
+ There are many easy ways to [download and run a Meilisearch instance](https://docs.meilisearch.com/learn/getting_started/quick_start.html#setup-and-installation).
64
64
 
65
- For example, using the `curl` command in your [Terminal](https://itconnect.uw.edu/learn/workshops/online-tutorials/web-publishing/what-is-a-terminal/):
65
+ For example, using the `curl` command in your [Terminal](https://itconnect.uw.edu/learn/workshops/online-tutorials/what-is-a-terminal/):
66
66
 
67
67
  ```sh
68
- #Install Meilisearch
68
+ # Install Meilisearch
69
69
  curl -L https://install.meilisearch.com | sh
70
70
 
71
71
  # Launch Meilisearch
@@ -98,7 +98,7 @@ documents = [
98
98
  index.add_documents(documents) # => { "uid": 0 }
99
99
  ```
100
100
 
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).
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-tasks).
102
102
 
103
103
  💡 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
104
 
@@ -125,7 +125,7 @@ Output:
125
125
 
126
126
  #### Custom search <!-- omit in toc -->
127
127
 
128
- All the supported options are described in the [search parameters](https://docs.meilisearch.com/reference/features/search_parameters.html) section of the documentation.
128
+ All the supported options are described in the [search parameters](https://docs.meilisearch.com/reference/api/search.html#search-parameters) section of the documentation.
129
129
 
130
130
  ```ruby
131
131
  index.search(
@@ -168,7 +168,7 @@ index.update_filterable_attributes([
168
168
 
169
169
  You only need to perform this operation once.
170
170
 
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)).
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-tasks)).
172
172
 
173
173
  Then, you can perform the search:
174
174
 
@@ -200,14 +200,14 @@ JSON output:
200
200
 
201
201
  ## 🤖 Compatibility with Meilisearch
202
202
 
203
- This package only guarantees the compatibility with the [version v1.0.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v1.0.0).
203
+ 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.
204
204
 
205
205
  ## 💡 Learn more
206
206
 
207
207
  The following sections in our main documentation website may interest you:
208
208
 
209
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).
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/api/search.html#search-parameters).
211
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
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).
213
213
 
@@ -3,6 +3,7 @@
3
3
  module MeiliSearch
4
4
  class Client < HTTPRequest
5
5
  include MeiliSearch::TenantToken
6
+ include MeiliSearch::MultiSearch
6
7
 
7
8
  ### INDEXES
8
9
 
@@ -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
 
@@ -96,9 +112,13 @@ module MeiliSearch
96
112
  alias replace_documents_ndjson add_documents_ndjson
97
113
  alias add_or_replace_documents_ndjson add_documents_ndjson
98
114
 
99
- def add_documents_csv(documents, primary_key = nil)
115
+ def add_documents_csv(documents, primary_key = nil, delimiter = nil)
100
116
  options = { headers: { 'Content-Type' => 'text/csv' }, convert_body?: false }
101
- http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact, options
117
+
118
+ http_post "/indexes/#{@uid}/documents", documents, {
119
+ primaryKey: primary_key,
120
+ csvDelimiter: delimiter
121
+ }.compact, options
102
122
  end
103
123
  alias replace_documents_csv add_documents_csv
104
124
  alias add_or_replace_documents_csv add_documents_csv
@@ -149,11 +169,24 @@ module MeiliSearch
149
169
  responses
150
170
  end
151
171
 
152
- def delete_documents(documents_ids)
153
- if documents_ids.is_a?(Array)
154
- http_post "/indexes/#{@uid}/documents/delete-batch", documents_ids
155
- else
156
- 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
157
190
  end
158
191
  end
159
192
  alias delete_multiple_documents delete_documents
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MeiliSearch
4
+ module MultiSearch
5
+ def multi_search(data)
6
+ body = Utils.transform_attributes(data)
7
+
8
+ http_post '/multi-search', queries: body
9
+ end
10
+ end
11
+ end
@@ -23,8 +23,12 @@ module MeiliSearch
23
23
  end
24
24
  end
25
25
 
26
+ def self.filter(original_options, allowed_params = [])
27
+ original_options.transform_keys(&:to_sym).slice(*allowed_params)
28
+ end
29
+
26
30
  def self.parse_query(original_options, allowed_params = [])
27
- only_allowed_params = original_options.transform_keys(&:to_sym).slice(*allowed_params)
31
+ only_allowed_params = filter(original_options, allowed_params)
28
32
 
29
33
  Utils.transform_attributes(only_allowed_params).then do |body|
30
34
  body.transform_values do |v|
@@ -33,6 +37,21 @@ module MeiliSearch
33
37
  end
34
38
  end
35
39
 
36
- private_class_method :parse
40
+ def self.message_builder(current_message, method_name)
41
+ "#{current_message}\nHint: It might not be working because maybe you're not up " \
42
+ "to date with the Meilisearch version that `#{method_name}` call requires."
43
+ end
44
+
45
+ def self.version_error_handler(method_name)
46
+ yield if block_given?
47
+ rescue MeiliSearch::ApiError => e
48
+ message = message_builder(e.http_message, method_name)
49
+
50
+ raise MeiliSearch::ApiError.new(e.http_code, message, e.http_body)
51
+ rescue StandardError => e
52
+ raise e.class, message_builder(e.message, method_name)
53
+ end
54
+
55
+ private_class_method :parse, :message_builder
37
56
  end
38
57
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MeiliSearch
4
- VERSION = '0.22.0'
4
+ VERSION = '0.24.0'
5
5
 
6
6
  def self.qualified_version
7
7
  "Meilisearch Ruby (v#{VERSION})"
data/lib/meilisearch.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'meilisearch/version'
4
4
  require 'meilisearch/utils'
5
5
  require 'meilisearch/http_request'
6
+ require 'meilisearch/multi_search'
6
7
  require 'meilisearch/tenant_token'
7
8
  require 'meilisearch/task'
8
9
  require 'meilisearch/client'
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.22.0
4
+ version: 0.24.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-02-06 00:00:00.000000000 Z
11
+ date: 2023-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -43,6 +43,7 @@ files:
43
43
  - lib/meilisearch/error.rb
44
44
  - lib/meilisearch/http_request.rb
45
45
  - lib/meilisearch/index.rb
46
+ - lib/meilisearch/multi_search.rb
46
47
  - lib/meilisearch/task.rb
47
48
  - lib/meilisearch/tenant_token.rb
48
49
  - lib/meilisearch/utils.rb