meilisearch-rails 0.9.1 → 0.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/README.md +31 -12
- data/lib/meilisearch/rails/pagination.rb +1 -1
- data/lib/meilisearch/rails/tasks/meilisearch.rake +7 -0
- data/lib/meilisearch/rails/templates/initializer.rb +4 -0
- data/lib/meilisearch/rails/version.rb +1 -1
- data/lib/meilisearch-rails.rb +41 -22
- data/meilisearch-rails.gemspec +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb990c26e799658b655df059ea7a22b4cfc7511a88e7581d72c27841b736f74f
|
4
|
+
data.tar.gz: c2457a258356732877729a9f110a8f392316a98d725d6d052f2dc64824a3ea2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7499509091a149069f1322e3ceec9c789432c3495d8c2754d258bb17c5cc1d70a410ebcd41e1eb76bcbe50b3c9e301044d0a5e6931e94bdd8779eb290e9eaecf
|
7
|
+
data.tar.gz: 68173b7d7767308144b6987c35c9c2fb75806959a6fcdc3ee3545cab88779d24e013dea0ea0b3b0a3182f8fb9bcd5c7e1634aaf89ecd39f4cb7ad21231b95a0b
|
data/Gemfile
CHANGED
@@ -13,7 +13,7 @@ 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'] || '6.1'
|
17
17
|
sequel_version = ENV['SEQUEL_VERSION'] ? "~> #{ENV['SEQUEL_VERSION']}" : '>= 4.0'
|
18
18
|
|
19
19
|
gem 'active_model_serializers'
|
@@ -31,6 +31,7 @@ group :test do
|
|
31
31
|
gem 'jdbc-sqlite3', platform: :jruby
|
32
32
|
gem 'rspec', '~> 3.0'
|
33
33
|
gem 'simplecov', require: 'false'
|
34
|
+
gem 'codecov', require: 'false'
|
34
35
|
gem 'threads'
|
35
36
|
|
36
37
|
gem 'byebug'
|
data/README.md
CHANGED
@@ -6,17 +6,21 @@
|
|
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/pricing?utm_campaign=oss&utm_source=integration&utm_medium=meilisearch-rails">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://
|
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://github.com/meilisearch/meilisearch-rails/actions"><img src="https://github.com/meilisearch/meilisearch-rails/workflows/Tests/badge.svg" alt="Test"></a>
|
19
|
+
<a href="https://app.codecov.io/gh/meilisearch/meilisearch-rails/tree/main" >
|
20
|
+
<img src="https://codecov.io/gh/meilisearch/meilisearch-rails/branch/main/graph/badge.svg?token=9J7LRP11IR"/>
|
21
|
+
</a>
|
18
22
|
<a href="https://github.com/meilisearch/meilisearch-rails/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-informational" alt="License"></a>
|
19
|
-
<a href="https://
|
23
|
+
<a href="https://ms-bors.herokuapp.com/repositories/68"><img src="https://bors.tech/images/badge_small.svg" alt="Bors enabled"></a>
|
20
24
|
</p>
|
21
25
|
|
22
26
|
<p align="center">⚡ The Meilisearch integration for Ruby on Rails 💎</p>
|
@@ -25,9 +29,10 @@
|
|
25
29
|
|
26
30
|
**Meilisearch** is an open-source search engine. [Learn more about Meilisearch.](https://github.com/meilisearch/meilisearch)
|
27
31
|
|
28
|
-
## Table of Contents <!-- omit in
|
32
|
+
## Table of Contents <!-- omit in TOC -->
|
29
33
|
|
30
34
|
- [📖 Documentation](#-documentation)
|
35
|
+
- [⚡ Supercharge your Meilisearch experience](#-supercharge-your-meilisearch-experience)
|
31
36
|
- [🤖 Compatibility with Meilisearch](#-compatibility-with-meilisearch)
|
32
37
|
- [🚀 Getting started](#-getting-started)
|
33
38
|
- [Compatibility](#-compatibility)
|
@@ -58,7 +63,11 @@
|
|
58
63
|
|
59
64
|
The whole usage of this gem is detailed in this README.
|
60
65
|
|
61
|
-
To learn more about Meilisearch, check out our [Documentation](https://
|
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/).
|
67
|
+
|
68
|
+
## ⚡ Supercharge your Meilisearch experience
|
69
|
+
|
70
|
+
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.
|
62
71
|
|
63
72
|
## 🤖 Compatibility with Meilisearch
|
64
73
|
|
@@ -66,7 +75,7 @@ This package guarantees compatibility with [version v1.x of Meilisearch](https:/
|
|
66
75
|
|
67
76
|
## 🔧 Installation <!-- omit in toc -->
|
68
77
|
|
69
|
-
This package requires Ruby version 2.
|
78
|
+
This package requires Ruby version 2.7.0 or later and Rails 6.1 or later. It may work in older versions but it is not officially supported.
|
70
79
|
|
71
80
|
With `gem` in command line:
|
72
81
|
```bash
|
@@ -82,7 +91,7 @@ gem 'meilisearch-rails'
|
|
82
91
|
|
83
92
|
### Run Meilisearch <!-- omit in toc -->
|
84
93
|
|
85
|
-
There are many easy ways to [download and run a Meilisearch instance](https://
|
94
|
+
There are many easy ways to [download and run a Meilisearch instance](https://www.meilisearch.com/docs/reference/features/installation.html#download-and-launch).
|
86
95
|
|
87
96
|
For example, if you use Docker:
|
88
97
|
|
@@ -101,13 +110,21 @@ Create a new file `config/initializers/meilisearch.rb` to setup your `MEILISEARC
|
|
101
110
|
|
102
111
|
```ruby
|
103
112
|
MeiliSearch::Rails.configuration = {
|
104
|
-
meilisearch_url: '
|
105
|
-
meilisearch_api_key: 'YourMeilisearchAPIKey'
|
113
|
+
meilisearch_url: ENV.fetch('MEILISEARCH_HOST', 'http://localhost:7700'),
|
114
|
+
meilisearch_api_key: ENV.fetch('MEILISEARCH_API_KEY', 'YourMeilisearchAPIKey')
|
106
115
|
}
|
107
116
|
```
|
108
117
|
|
118
|
+
Or you can run a rake task to create the initializer file for you:
|
119
|
+
|
120
|
+
```bash
|
121
|
+
bin/rails meilisearch:install
|
122
|
+
```
|
123
|
+
|
109
124
|
The gem is compatible with [ActiveRecord](https://github.com/rails/rails/tree/master/activerecord), [Mongoid](https://github.com/mongoid/mongoid) and [Sequel](https://github.com/jeremyevans/sequel).
|
110
125
|
|
126
|
+
⚠️ Note that even if you want to use all the default options, you must declare an empty `meilisearch` block in your model.
|
127
|
+
|
111
128
|
#### Add documents <!-- omit in toc -->
|
112
129
|
|
113
130
|
The following code will create a `Book` index and add search capabilities to your `Book` model.
|
@@ -123,7 +140,9 @@ class Book < ActiveRecord::Base
|
|
123
140
|
end
|
124
141
|
```
|
125
142
|
|
126
|
-
|
143
|
+
#### Automatic indexing
|
144
|
+
|
145
|
+
As soon as you configure your model as mentioned above, `meilisearch-rails` will keep your database table data in sync with your Meilisearch instance using the `ActiveRecord` callbacks automatically.
|
127
146
|
|
128
147
|
#### Basic Backend Search <!-- omit in toc -->
|
129
148
|
|
@@ -191,11 +210,11 @@ class Book < ApplicationRecord
|
|
191
210
|
end
|
192
211
|
```
|
193
212
|
|
194
|
-
Check the dedicated section of the documentation, for more information on the [settings](https://
|
213
|
+
Check the dedicated section of the documentation, for more information on the [settings](https://www.meilisearch.com/docs/reference/api/settings#settings_parameters).
|
195
214
|
|
196
215
|
## 🔍 Custom search
|
197
216
|
|
198
|
-
All the supported options are described in the [search parameters](https://
|
217
|
+
All the supported options are described in the [search parameters](https://www.meilisearch.com/docs/reference/api/search#search-parameters) section of the documentation.
|
199
218
|
|
200
219
|
```ruby
|
201
220
|
Book.search('Harry', attributes_to_highlight: ['*'])
|
@@ -310,7 +329,7 @@ Check [`ddnexus/pagy`](https://ddnexus.github.io/pagy/extras/meilisearch) for mo
|
|
310
329
|
|
311
330
|
#### Deactivate Meilisearch in certain moments
|
312
331
|
|
313
|
-
By default HTTP connections to the Meilisearch URL
|
332
|
+
By default, HTTP connections to the Meilisearch URL are always active, but sometimes you want to disable the HTTP requests in a particular moment or environment.<br>
|
314
333
|
you have multiple ways to achieve this.
|
315
334
|
|
316
335
|
By adding `active: false` in the configuration initializer:
|
@@ -17,7 +17,7 @@ module MeiliSearch
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.log_pagy_error
|
20
|
-
|
20
|
+
MeiliSearch::Rails.logger
|
21
21
|
.warning('[meilisearch-rails] Remove `pagination_backend: :pagy` from your initializer, `pagy` it is not required for `pagy`')
|
22
22
|
end
|
23
23
|
|
@@ -19,4 +19,11 @@ namespace :meilisearch do
|
|
19
19
|
|
20
20
|
MeiliSearch::Rails::Utilities.clear_all_indexes
|
21
21
|
end
|
22
|
+
|
23
|
+
desc 'Create initializer file'
|
24
|
+
task install: :environment do
|
25
|
+
puts 'Creating initializer file'
|
26
|
+
|
27
|
+
copy_file "#{__dir__}/../templates/initializer.rb", 'config/initializers/meilisearch.rb'
|
28
|
+
end
|
22
29
|
end
|
data/lib/meilisearch-rails.rb
CHANGED
@@ -39,6 +39,10 @@ module MeiliSearch
|
|
39
39
|
include InstanceMethods
|
40
40
|
end
|
41
41
|
end
|
42
|
+
|
43
|
+
def logger
|
44
|
+
@logger ||= (::Rails.logger || Logger.new($stdout))
|
45
|
+
end
|
42
46
|
end
|
43
47
|
|
44
48
|
class IndexSettings
|
@@ -48,23 +52,23 @@ module MeiliSearch
|
|
48
52
|
|
49
53
|
# Meilisearch settings
|
50
54
|
OPTIONS = %i[
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
55
|
+
searchable_attributes
|
56
|
+
filterable_attributes
|
57
|
+
sortable_attributes
|
58
|
+
displayed_attributes
|
59
|
+
distinct_attribute
|
56
60
|
synonyms
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
61
|
+
stop_words
|
62
|
+
ranking_rules
|
63
|
+
attributes_to_highlight
|
64
|
+
attributes_to_crop
|
65
|
+
crop_length
|
62
66
|
pagination
|
63
67
|
faceting
|
64
|
-
|
68
|
+
typo_tolerance
|
65
69
|
].freeze
|
66
70
|
|
67
|
-
CAMELIZE_OPTIONS = %i[pagination faceting
|
71
|
+
CAMELIZE_OPTIONS = %i[pagination faceting typo_tolerance].freeze
|
68
72
|
|
69
73
|
OPTIONS.each do |option|
|
70
74
|
define_method option do |value|
|
@@ -265,9 +269,9 @@ module MeiliSearch
|
|
265
269
|
::MeiliSearch::Index.instance_methods(false).each do |m|
|
266
270
|
define_method(m) do |*args, &block|
|
267
271
|
if m == :update_settings
|
268
|
-
args[0].delete(:
|
269
|
-
args[0].delete(:
|
270
|
-
args[0].delete(:
|
272
|
+
args[0].delete(:attributes_to_highlight) if args[0][:attributes_to_highlight]
|
273
|
+
args[0].delete(:attributes_to_crop) if args[0][:attributes_to_crop]
|
274
|
+
args[0].delete(:crop_length) if args[0][:crop_length]
|
271
275
|
end
|
272
276
|
|
273
277
|
SafeIndex.log_or_throw(m, @raise_on_failure) do
|
@@ -304,7 +308,7 @@ module MeiliSearch
|
|
304
308
|
raise e if raise_on_failure
|
305
309
|
|
306
310
|
# log the error
|
307
|
-
|
311
|
+
MeiliSearch::Rails.logger.info("[meilisearch-rails] #{e.message}")
|
308
312
|
# return something
|
309
313
|
case method.to_s
|
310
314
|
when 'search'
|
@@ -444,6 +448,8 @@ module MeiliSearch
|
|
444
448
|
after_destroy { |searchable| searchable.ms_enqueue_remove_from_index!(ms_synchronous?) }
|
445
449
|
end
|
446
450
|
end
|
451
|
+
|
452
|
+
warn_searchable_missing_attributes
|
447
453
|
end
|
448
454
|
|
449
455
|
def ms_without_auto_index(&block)
|
@@ -581,15 +587,15 @@ module MeiliSearch
|
|
581
587
|
def ms_raw_search(q, params = {})
|
582
588
|
index_uid = params.delete(:index) || params.delete('index')
|
583
589
|
|
584
|
-
unless meilisearch_settings.get_setting(:
|
585
|
-
params[:
|
590
|
+
unless meilisearch_settings.get_setting(:attributes_to_highlight).nil?
|
591
|
+
params[:attributes_to_highlight] = meilisearch_settings.get_setting(:attributes_to_highlight)
|
586
592
|
end
|
587
593
|
|
588
|
-
unless meilisearch_settings.get_setting(:
|
589
|
-
params[:
|
594
|
+
unless meilisearch_settings.get_setting(:attributes_to_crop).nil?
|
595
|
+
params[:attributes_to_crop] = meilisearch_settings.get_setting(:attributes_to_crop)
|
590
596
|
|
591
|
-
unless meilisearch_settings.get_setting(:
|
592
|
-
params[:
|
597
|
+
unless meilisearch_settings.get_setting(:crop_length).nil?
|
598
|
+
params[:crop_length] = meilisearch_settings.get_setting(:crop_length)
|
593
599
|
end
|
594
600
|
end
|
595
601
|
|
@@ -858,6 +864,19 @@ module MeiliSearch
|
|
858
864
|
# We don't know if the attribute has changed, so conservatively assume it has
|
859
865
|
true
|
860
866
|
end
|
867
|
+
|
868
|
+
def warn_searchable_missing_attributes
|
869
|
+
searchables = meilisearch_settings.get_setting(:searchable_attributes)
|
870
|
+
attrs = meilisearch_settings.get_setting(:attributes)&.keys
|
871
|
+
|
872
|
+
if searchables.present? && attrs.present?
|
873
|
+
(searchables.map(&:to_s) - attrs.map(&:to_s)).each do |missing_searchable|
|
874
|
+
MeiliSearch::Rails.logger.warn(
|
875
|
+
"[meilisearch-rails] #{name}##{missing_searchable} declared in searchable_attributes but not in attributes. Please add it to attributes if it should be searchable."
|
876
|
+
)
|
877
|
+
end
|
878
|
+
end
|
879
|
+
end
|
861
880
|
end
|
862
881
|
|
863
882
|
# these are the instance methods included
|
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.
|
4
|
+
version: 0.10.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Meili
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: meilisearch
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.26.0
|
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: 0.
|
26
|
+
version: 0.26.0
|
27
27
|
description: Meilisearch integration for Ruby on Rails. See https://github.com/meilisearch/meilisearch
|
28
28
|
email: bonjour@meilisearch.com
|
29
29
|
executables: []
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- lib/meilisearch/rails/pagination/will_paginate.rb
|
48
48
|
- lib/meilisearch/rails/railtie.rb
|
49
49
|
- lib/meilisearch/rails/tasks/meilisearch.rake
|
50
|
+
- lib/meilisearch/rails/templates/initializer.rb
|
50
51
|
- lib/meilisearch/rails/utilities.rb
|
51
52
|
- lib/meilisearch/rails/version.rb
|
52
53
|
- meilisearch-rails.gemspec
|
@@ -69,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
70
|
- !ruby/object:Gem::Version
|
70
71
|
version: '0'
|
71
72
|
requirements: []
|
72
|
-
rubygems_version: 3.
|
73
|
+
rubygems_version: 3.1.6
|
73
74
|
signing_key:
|
74
75
|
specification_version: 4
|
75
76
|
summary: Meilisearch integration for Ruby on Rails.
|