meilisearch-rails 0.14.1 → 0.14.3
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 +4 -4
- data/Gemfile +6 -4
- data/LICENSE +1 -1
- data/README.md +56 -30
- data/lib/meilisearch/rails/multi_search/result.rb +34 -11
- data/lib/meilisearch/rails/multi_search.rb +2 -0
- data/lib/meilisearch/rails/pagination/kaminari.rb +8 -2
- data/lib/meilisearch/rails/pagination/will_paginate.rb +6 -0
- data/lib/meilisearch/rails/version.rb +1 -1
- data/lib/meilisearch-rails.rb +1 -1
- data/meilisearch-rails.gemspec +2 -1
- metadata +21 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: babcf0719c23af9294b52e76c7549cacf9baeb578221c18cf2be53db5bbeaaa1
|
4
|
+
data.tar.gz: 33aee866b13502a67657a5803d395fbcebe737456e2f45e812b1312074b5b7df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 230fc45c263f5aa10ff137eba952673eed221a33bae3ae1c5cb7cfe35adbdc50d9399feaeaf20c7766fd78bf0c29ed440de08880de8f5c2e9d7889bcf6d107c5
|
7
|
+
data.tar.gz: 18bbbc7a7fd9cb64bf1f2429234c10c56b1c3c88a044909a3b01f1e4ceb276449f61cc6ceb52148131c44b8d5dfbeeb09438953dff15ff9857b3d9e7864e2ccd
|
data/Gemfile
CHANGED
@@ -13,17 +13,18 @@ group :development do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
group :test do
|
16
|
-
rails_version = ENV['RAILS_VERSION'] || '
|
16
|
+
rails_version = ENV['RAILS_VERSION'] || '7.1'
|
17
17
|
sequel_version = ENV['SEQUEL_VERSION'] ? "~> #{ENV['SEQUEL_VERSION']}" : '>= 4.0'
|
18
18
|
|
19
19
|
gem 'active_model_serializers'
|
20
20
|
gem 'rails', "~> #{rails_version}"
|
21
21
|
gem 'sequel', sequel_version
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
# remove when deprecate rails 6
|
24
|
+
if Gem::Version.new(rails_version) >= Gem::Version.new('7.0')
|
25
|
+
gem 'sqlite3', '~> 2', platform: %i[rbx ruby]
|
25
26
|
else
|
26
|
-
gem 'sqlite3', '<
|
27
|
+
gem 'sqlite3', '< 2', platform: %i[rbx ruby]
|
27
28
|
end
|
28
29
|
|
29
30
|
gem 'activerecord-jdbc-adapter', platform: :jruby
|
@@ -33,6 +34,7 @@ group :test do
|
|
33
34
|
gem 'simplecov', require: 'false'
|
34
35
|
gem 'simplecov-cobertura', require: 'false'
|
35
36
|
gem 'threads'
|
37
|
+
gem 'logger'
|
36
38
|
|
37
39
|
gem 'byebug'
|
38
40
|
gem 'dotenv', '~> 2.7', '>= 2.7.6'
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -32,7 +32,6 @@
|
|
32
32
|
## Table of Contents <!-- omit in TOC -->
|
33
33
|
|
34
34
|
- [📖 Documentation](#-documentation)
|
35
|
-
- [⚡ Supercharge your Meilisearch experience](#-supercharge-your-meilisearch-experience)
|
36
35
|
- [🤖 Compatibility with Meilisearch](#-compatibility-with-meilisearch)
|
37
36
|
- [🚀 Getting started](#-getting-started)
|
38
37
|
- [Compatibility](#-compatibility)
|
@@ -66,10 +65,6 @@ The whole usage of this gem is detailed in this README.
|
|
66
65
|
|
67
66
|
To learn more about Meilisearch, check out our [Documentation](https://www.meilisearch.com/docs/learn/tutorials/getting_started.html) or our [API References](https://www.meilisearch.com/docs/reference/api/).
|
68
67
|
|
69
|
-
## ⚡ Supercharge your Meilisearch experience
|
70
|
-
|
71
|
-
Say goodbye to server deployment and manual updates with [Meilisearch Cloud](https://www.meilisearch.com/pricing?utm_campaign=oss&utm_source=integration&utm_medium=meilisearch-rails). No credit card required.
|
72
|
-
|
73
68
|
## 🤖 Compatibility with Meilisearch
|
74
69
|
|
75
70
|
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-rails/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22+label%3Aenhancement) for more info.
|
@@ -92,16 +87,9 @@ gem 'meilisearch-rails'
|
|
92
87
|
|
93
88
|
### Run Meilisearch <!-- omit in toc -->
|
94
89
|
|
95
|
-
|
96
|
-
|
97
|
-
For example, if you use Docker:
|
98
|
-
|
99
|
-
```bash
|
100
|
-
docker pull getmeili/meilisearch:latest # Fetch the latest version of Meilisearch image from Docker Hub
|
101
|
-
docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest meilisearch --master-key=masterKey
|
102
|
-
```
|
90
|
+
⚡️ **Launch, scale, and streamline in minutes with Meilisearch Cloud**—no maintenance, no commitment, cancel anytime. [Try it free now](https://cloud.meilisearch.com/login?utm_campaign=oss&utm_source=github&utm_medium=meilisearch-rails).
|
103
91
|
|
104
|
-
|
92
|
+
🪨 Prefer to self-host? [Download and deploy](https://www.meilisearch.com/docs/learn/self_hosted/getting_started_with_self_hosted_meilisearch?utm_campaign=oss&utm_source=github&utm_medium=meilisearch-rails) our fast, open-source search engine on your own infrastructure.
|
105
93
|
|
106
94
|
## 🚀 Getting started
|
107
95
|
|
@@ -253,22 +241,7 @@ multi_search_results = MeiliSearch::Rails.multi_search(
|
|
253
241
|
)
|
254
242
|
```
|
255
243
|
|
256
|
-
|
257
|
-
|
258
|
-
```erb
|
259
|
-
<% multi_search_results.each do |record| %>
|
260
|
-
<p><%= record.title %></p>
|
261
|
-
<p><%= record.author %></p>
|
262
|
-
<% end %>
|
263
|
-
|
264
|
-
<p>Harry Potter and the Philosopher's Stone</p>
|
265
|
-
<p>J. K. Rowling</p>
|
266
|
-
<p>Harry Potter and the Chamber of Secrets</p>
|
267
|
-
<p>J. K. Rowling</p>
|
268
|
-
<p>Attack on Titan</p>
|
269
|
-
<p>Iseyama</p>
|
270
|
-
```
|
271
|
-
|
244
|
+
Use `#each_result` to loop through pairs of your provided keys and the results:
|
272
245
|
```erb
|
273
246
|
<% multi_search_results.each_result do |klass, results| %>
|
274
247
|
<p><%= klass.name.pluralize %></p>
|
@@ -292,6 +265,59 @@ You can iterate through the results with `.each` or `.each_result`:
|
|
292
265
|
</ul>
|
293
266
|
```
|
294
267
|
|
268
|
+
Records are loaded when the keys are models, or when `:class_name` option is passed:
|
269
|
+
|
270
|
+
```ruby
|
271
|
+
multi_search_results = MeiliSearch::Rails.multi_search(
|
272
|
+
'books' => { q: 'Harry', class_name: 'Book' },
|
273
|
+
'mangas' => { q: 'Attack', class_name: 'Manga' }
|
274
|
+
)
|
275
|
+
```
|
276
|
+
|
277
|
+
Otherwise, hashes are returned.
|
278
|
+
|
279
|
+
The index to search is inferred from the model if the key is a model, if the key is a string the key is assumed to be the index unless the `:index_uid` option is passed:
|
280
|
+
|
281
|
+
```ruby
|
282
|
+
multi_search_results = MeiliSearch::Rails.multi_search(
|
283
|
+
'western' => { q: 'Harry', class_name: 'Book', index_uid: 'books_production' },
|
284
|
+
'japanese' => { q: 'Attack', class_name: 'Manga', index_uid: 'mangas_production' }
|
285
|
+
)
|
286
|
+
```
|
287
|
+
|
288
|
+
### Multi search the same index <!-- omit in toc -->
|
289
|
+
|
290
|
+
You can search the same index multiple times by specifying `:index_uid`:
|
291
|
+
|
292
|
+
```ruby
|
293
|
+
query = 'hero'
|
294
|
+
multi_search_results = MeiliSearch::Rails.multi_search(
|
295
|
+
'Isekai Manga' => { q: query, class_name: 'Manga', filters: 'genre:isekai', index_uid: 'mangas_production' }
|
296
|
+
'Shounen Manga' => { q: query, class_name: 'Manga', filters: 'genre:shounen', index_uid: 'mangas_production' }
|
297
|
+
'Steampunk Manga' => { q: query, class_name: 'Manga', filters: 'genre:steampunk', index_uid: 'mangas_production' }
|
298
|
+
)
|
299
|
+
```
|
300
|
+
|
301
|
+
### Deprecated #each <!-- omit in toc -->
|
302
|
+
|
303
|
+
**DEPRECATED:** You used to be able to iterate through a flattened collection with `.each`:
|
304
|
+
|
305
|
+
```erb
|
306
|
+
<% multi_search_results.each do |record| %>
|
307
|
+
<p><%= record.title %></p>
|
308
|
+
<p><%= record.author %></p>
|
309
|
+
<% end %>
|
310
|
+
|
311
|
+
<p>Harry Potter and the Philosopher's Stone</p>
|
312
|
+
<p>J. K. Rowling</p>
|
313
|
+
<p>Harry Potter and the Chamber of Secrets</p>
|
314
|
+
<p>J. K. Rowling</p>
|
315
|
+
<p>Attack on Titan</p>
|
316
|
+
<p>Iseyama</p>
|
317
|
+
```
|
318
|
+
|
319
|
+
But this has been deprecated in favor of **federated search**.
|
320
|
+
|
295
321
|
See the [official multi search documentation](https://www.meilisearch.com/docs/reference/api/multi_search).
|
296
322
|
|
297
323
|
## 🪛 Options
|
@@ -7,34 +7,57 @@ module MeiliSearch
|
|
7
7
|
@results = {}
|
8
8
|
@metadata = {}
|
9
9
|
|
10
|
-
searches.zip(raw_results['results']).each do |(
|
11
|
-
|
10
|
+
searches.zip(raw_results['results']).each do |(target, search_options), result|
|
11
|
+
results_class = if search_options[:class_name]
|
12
|
+
search_options[:class_name].constantize
|
13
|
+
elsif target.instance_of?(Class)
|
14
|
+
target
|
15
|
+
end
|
12
16
|
|
13
|
-
@results[
|
14
|
-
when String, Symbol
|
15
|
-
result['hits']
|
16
|
-
else
|
17
|
-
load_results(index_target, result)
|
18
|
-
end
|
17
|
+
@results[target] = results_class ? load_results(results_class, result) : result['hits']
|
19
18
|
|
20
|
-
@metadata[
|
19
|
+
@metadata[target] = result.except('hits')
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
24
23
|
include Enumerable
|
25
24
|
|
26
25
|
def each_hit(&block)
|
27
|
-
|
26
|
+
MeiliSearch::Rails.logger.warn(
|
27
|
+
<<~DEPRECATION
|
28
|
+
[meilisearch-rails] Flattening multi search results is deprecated.
|
29
|
+
If you do not want the results to be grouped, please use federated search instead.
|
30
|
+
DEPRECATION
|
31
|
+
)
|
32
|
+
|
33
|
+
@results.each_value do |results|
|
28
34
|
results.each(&block)
|
29
35
|
end
|
30
36
|
end
|
31
|
-
|
37
|
+
|
38
|
+
def each(&block)
|
39
|
+
MeiliSearch::Rails.logger.info(
|
40
|
+
<<~INFO
|
41
|
+
[meilisearch-rails] #each on a multi search now iterates through grouped results.
|
42
|
+
If you do not want the results to be grouped, please use federated search instead.
|
43
|
+
To quickly go back to the old deprecated behavior, use `#each_hit`.
|
44
|
+
INFO
|
45
|
+
)
|
46
|
+
|
47
|
+
@results.each(&block)
|
48
|
+
end
|
32
49
|
|
33
50
|
def each_result(&block)
|
34
51
|
@results.each(&block)
|
35
52
|
end
|
36
53
|
|
37
54
|
def to_a
|
55
|
+
MeiliSearch::Rails.logger.warn(
|
56
|
+
<<~DEPRECATION
|
57
|
+
[meilisearch-rails] Flattening multi search results is deprecated.
|
58
|
+
If you do not want the results to be grouped, please use federated search instead.
|
59
|
+
DEPRECATION
|
60
|
+
)
|
38
61
|
@results.values.flatten(1)
|
39
62
|
end
|
40
63
|
alias to_ary to_a
|
@@ -5,6 +5,8 @@ module MeiliSearch
|
|
5
5
|
class << self
|
6
6
|
def multi_search(searches)
|
7
7
|
search_parameters = searches.map do |(index_target, options)|
|
8
|
+
index_target = options.delete(:index_uid) || index_target
|
9
|
+
|
8
10
|
paginate(options) if pagination_enabled?
|
9
11
|
normalize(options, index_target)
|
10
12
|
end
|
@@ -18,14 +18,20 @@ module MeiliSearch
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.create(results, total_hits, options = {})
|
21
|
-
|
21
|
+
unless MeiliSearch::Rails.active?
|
22
|
+
total_hits = 0
|
23
|
+
options[:page] = 1
|
24
|
+
options[:per_page] = 1
|
25
|
+
end
|
26
|
+
|
27
|
+
offset = (options[:page] - 1) * options[:per_page]
|
22
28
|
array = new results, limit: options[:per_page], offset: offset, total_count: total_hits
|
23
29
|
|
24
30
|
if array.empty? && !results.empty?
|
25
31
|
# since Kaminari 0.16.0, you need to pad the results with nil values so it matches the offset param
|
26
32
|
# otherwise you'll get an empty array: https://github.com/amatsuda/kaminari/commit/29fdcfa8865f2021f710adaedb41b7a7b081e34d
|
27
33
|
results = Array.new(offset) + results
|
28
|
-
array = new results, offset: offset, limit:
|
34
|
+
array = new results, offset: offset, limit: limit, total_count: total_hits
|
29
35
|
end
|
30
36
|
|
31
37
|
array
|
@@ -10,6 +10,12 @@ module MeiliSearch
|
|
10
10
|
module Pagination
|
11
11
|
class WillPaginate
|
12
12
|
def self.create(results, total_hits, options = {})
|
13
|
+
unless MeiliSearch::Rails.active?
|
14
|
+
total_hits = 0
|
15
|
+
options[:page] = 1
|
16
|
+
options[:per_page] = 1
|
17
|
+
end
|
18
|
+
|
13
19
|
::WillPaginate::Collection.create(options[:page], options[:per_page], total_hits) do |pager|
|
14
20
|
pager.replace results
|
15
21
|
end
|
data/lib/meilisearch-rails.rb
CHANGED
@@ -415,7 +415,7 @@ module MeiliSearch
|
|
415
415
|
raise ArgumentError, "Invalid `enqueue` option: #{options[:enqueue]}"
|
416
416
|
end
|
417
417
|
meilisearch_options[:enqueue] = proc do |record, remove|
|
418
|
-
proc.call(record, remove)
|
418
|
+
proc.call(record, remove) if ::MeiliSearch::Rails.active? && !ms_without_auto_index_scope
|
419
419
|
end
|
420
420
|
end
|
421
421
|
unless options[:auto_index] == false
|
data/meilisearch-rails.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meilisearch-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.14.
|
4
|
+
version: 0.14.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Meili
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: meilisearch
|
@@ -16,14 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.28.4
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.28.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mutex_m
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.2'
|
27
41
|
description: Meilisearch integration for Ruby on Rails. See https://github.com/meilisearch/meilisearch
|
28
42
|
email: bonjour@meilisearch.com
|
29
43
|
executables: []
|
@@ -58,7 +72,7 @@ homepage: https://github.com/meilisearch/meilisearch-rails
|
|
58
72
|
licenses:
|
59
73
|
- MIT
|
60
74
|
metadata: {}
|
61
|
-
post_install_message:
|
75
|
+
post_install_message:
|
62
76
|
rdoc_options: []
|
63
77
|
require_paths:
|
64
78
|
- lib
|
@@ -74,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
88
|
version: '0'
|
75
89
|
requirements: []
|
76
90
|
rubygems_version: 3.4.19
|
77
|
-
signing_key:
|
91
|
+
signing_key:
|
78
92
|
specification_version: 4
|
79
93
|
summary: Meilisearch integration for Ruby on Rails.
|
80
94
|
test_files: []
|