meilisearch-rails 0.4.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -6
- data/LICENSE +1 -1
- data/README.md +73 -61
- data/Rakefile +1 -1
- data/lib/meilisearch/rails/configuration.rb +23 -0
- data/lib/meilisearch/rails/errors.rb +14 -0
- data/lib/meilisearch/rails/ms_job.rb +11 -0
- data/lib/meilisearch/rails/pagination/kaminari.rb +48 -0
- data/lib/meilisearch/rails/pagination/will_paginate.rb +22 -0
- data/lib/meilisearch/rails/pagination.rb +20 -0
- data/lib/meilisearch/rails/railtie.rb +14 -0
- data/lib/meilisearch/rails/tasks/meilisearch.rake +22 -0
- data/lib/meilisearch/rails/utilities.rb +46 -0
- data/lib/meilisearch/{version.rb → rails/version.rb} +3 -1
- data/lib/meilisearch-rails.rb +693 -695
- data/meilisearch-rails.gemspec +12 -10
- metadata +19 -33
- data/lib/meilisearch/configuration.rb +0 -21
- data/lib/meilisearch/errors.rb +0 -12
- data/lib/meilisearch/ms_job.rb +0 -9
- data/lib/meilisearch/pagination/kaminari.rb +0 -46
- data/lib/meilisearch/pagination/will_paginate.rb +0 -20
- data/lib/meilisearch/pagination.rb +0 -18
- data/lib/meilisearch/railtie.rb +0 -12
- data/lib/meilisearch/tasks/meilisearch.rake +0 -17
- data/lib/meilisearch/utilities.rb +0 -44
data/meilisearch-rails.gemspec
CHANGED
@@ -1,19 +1,21 @@
|
|
1
|
-
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
2
3
|
|
3
|
-
require '
|
4
|
+
require 'meilisearch/rails/version'
|
4
5
|
|
5
6
|
Gem::Specification.new do |s|
|
6
7
|
s.name = 'meilisearch-rails'
|
7
|
-
s.version = MeiliSearch::VERSION
|
8
|
+
s.version = MeiliSearch::Rails::VERSION
|
8
9
|
|
9
|
-
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
10
10
|
s.authors = ['Meili']
|
11
|
-
s.description = 'MeiliSearch integration for Ruby on Rails. See https://github.com/meilisearch/MeiliSearch'
|
12
11
|
s.email = 'bonjour@meilisearch.com'
|
13
|
-
|
14
|
-
s.
|
12
|
+
|
13
|
+
s.description = 'Meilisearch integration for Ruby on Rails. See https://github.com/meilisearch/meilisearch'
|
14
|
+
s.homepage = 'https://github.com/meilisearch/meilisearch-rails'
|
15
|
+
s.summary = 'Meilisearch integration for Ruby on Rails.'
|
16
|
+
s.licenses = 'MIT'
|
17
|
+
|
15
18
|
s.require_paths = ['lib']
|
16
|
-
s.summary = 'MeiliSearch integration for Ruby on Rails.'
|
17
19
|
|
18
20
|
s.extra_rdoc_files = [
|
19
21
|
'LICENSE',
|
@@ -31,6 +33,6 @@ Gem::Specification.new do |s|
|
|
31
33
|
]
|
32
34
|
|
33
35
|
s.required_ruby_version = '>= 2.6.0'
|
34
|
-
|
35
|
-
s.add_dependency
|
36
|
+
|
37
|
+
s.add_dependency 'meilisearch', '~> 0.18'
|
36
38
|
end
|
metadata
CHANGED
@@ -1,44 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meilisearch-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Meili
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: json
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 1.5.1
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 1.5.1
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: meilisearch
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
|
-
- - "
|
17
|
+
- - "~>"
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
19
|
+
version: '0.18'
|
34
20
|
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
|
-
- - "
|
24
|
+
- - "~>"
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
41
|
-
description:
|
26
|
+
version: '0.18'
|
27
|
+
description: Meilisearch integration for Ruby on Rails. See https://github.com/meilisearch/meilisearch
|
42
28
|
email: bonjour@meilisearch.com
|
43
29
|
executables: []
|
44
30
|
extensions: []
|
@@ -52,18 +38,18 @@ files:
|
|
52
38
|
- README.md
|
53
39
|
- Rakefile
|
54
40
|
- lib/meilisearch-rails.rb
|
55
|
-
- lib/meilisearch/configuration.rb
|
56
|
-
- lib/meilisearch/errors.rb
|
57
|
-
- lib/meilisearch/ms_job.rb
|
58
|
-
- lib/meilisearch/pagination.rb
|
59
|
-
- lib/meilisearch/pagination/kaminari.rb
|
60
|
-
- lib/meilisearch/pagination/will_paginate.rb
|
61
|
-
- lib/meilisearch/railtie.rb
|
62
|
-
- lib/meilisearch/tasks/meilisearch.rake
|
63
|
-
- lib/meilisearch/utilities.rb
|
64
|
-
- lib/meilisearch/version.rb
|
41
|
+
- lib/meilisearch/rails/configuration.rb
|
42
|
+
- lib/meilisearch/rails/errors.rb
|
43
|
+
- lib/meilisearch/rails/ms_job.rb
|
44
|
+
- lib/meilisearch/rails/pagination.rb
|
45
|
+
- lib/meilisearch/rails/pagination/kaminari.rb
|
46
|
+
- lib/meilisearch/rails/pagination/will_paginate.rb
|
47
|
+
- lib/meilisearch/rails/railtie.rb
|
48
|
+
- lib/meilisearch/rails/tasks/meilisearch.rake
|
49
|
+
- lib/meilisearch/rails/utilities.rb
|
50
|
+
- lib/meilisearch/rails/version.rb
|
65
51
|
- meilisearch-rails.gemspec
|
66
|
-
homepage:
|
52
|
+
homepage: https://github.com/meilisearch/meilisearch-rails
|
67
53
|
licenses:
|
68
54
|
- MIT
|
69
55
|
metadata: {}
|
@@ -85,5 +71,5 @@ requirements: []
|
|
85
71
|
rubygems_version: 3.0.3.1
|
86
72
|
signing_key:
|
87
73
|
specification_version: 4
|
88
|
-
summary:
|
74
|
+
summary: Meilisearch integration for Ruby on Rails.
|
89
75
|
test_files: []
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module MeiliSearch
|
2
|
-
module Configuration
|
3
|
-
def configuration
|
4
|
-
raise NotConfigured if @_config.blank?
|
5
|
-
|
6
|
-
@_config
|
7
|
-
end
|
8
|
-
|
9
|
-
def configuration=(configuration)
|
10
|
-
@_config = configuration
|
11
|
-
end
|
12
|
-
|
13
|
-
def client
|
14
|
-
::MeiliSearch::Client.new(
|
15
|
-
configuration[:meilisearch_host] || 'http://localhost:7700',
|
16
|
-
configuration[:meilisearch_api_key],
|
17
|
-
configuration.slice(:timeout, :max_retries)
|
18
|
-
)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/lib/meilisearch/errors.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
module MeiliSearch
|
2
|
-
class NoBlockGiven < StandardError; end
|
3
|
-
|
4
|
-
class BadConfiguration < StandardError; end
|
5
|
-
|
6
|
-
class NotConfigured < StandardError
|
7
|
-
def message
|
8
|
-
'Please configure MeiliSearch. Set MeiliSearch.configuration = ' \
|
9
|
-
"{meilisearch_host: 'YOUR_MEILISEARCH_HOST', meilisearch_api_key: 'YOUR_API_KEY'}"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
data/lib/meilisearch/ms_job.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
unless defined? Kaminari
|
2
|
-
raise(MeiliSearch::BadConfiguration,
|
3
|
-
"MeiliSearch: Please add 'kaminari' to your Gemfile to use kaminari pagination backend")
|
4
|
-
end
|
5
|
-
|
6
|
-
require 'kaminari/models/array_extension'
|
7
|
-
|
8
|
-
module MeiliSearch
|
9
|
-
module Pagination
|
10
|
-
class Kaminari < ::Kaminari::PaginatableArray
|
11
|
-
def initialize(array, options)
|
12
|
-
if RUBY_VERSION >= '3'
|
13
|
-
super(array, **options)
|
14
|
-
else
|
15
|
-
super(array, options)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def limit(_num)
|
20
|
-
# noop
|
21
|
-
self
|
22
|
-
end
|
23
|
-
|
24
|
-
def offset(_num)
|
25
|
-
# noop
|
26
|
-
self
|
27
|
-
end
|
28
|
-
|
29
|
-
class << self
|
30
|
-
def create(results, total_hits, options = {})
|
31
|
-
offset = ((options[:page] - 1) * options[:per_page])
|
32
|
-
array = new results, limit: options[:per_page], offset: offset, total_count: total_hits
|
33
|
-
|
34
|
-
if array.empty? && !results.empty?
|
35
|
-
# since Kaminari 0.16.0, you need to pad the results with nil values so it matches the offset param
|
36
|
-
# otherwise you'll get an empty array: https://github.com/amatsuda/kaminari/commit/29fdcfa8865f2021f710adaedb41b7a7b081e34d
|
37
|
-
results = ([nil] * offset) + results
|
38
|
-
array = new results, offset: offset, limit: options[:per_page], total_count: total_hits
|
39
|
-
end
|
40
|
-
|
41
|
-
array
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'will_paginate/collection'
|
3
|
-
rescue LoadError
|
4
|
-
raise(MeiliSearch::BadConfiguration,
|
5
|
-
"MeiliSearch: Please add 'will_paginate' to your Gemfile to use will_paginate pagination backend")
|
6
|
-
end
|
7
|
-
|
8
|
-
module MeiliSearch
|
9
|
-
module Pagination
|
10
|
-
class WillPaginate
|
11
|
-
def self.create(results, total_hits, options = {})
|
12
|
-
::WillPaginate::Collection.create(options[:page], options[:per_page], total_hits) do |pager|
|
13
|
-
start = (options[:page] - 1) * options[:per_page]
|
14
|
-
paginated_results = results[start, options[:per_page]]
|
15
|
-
pager.replace paginated_results
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module MeiliSearch
|
2
|
-
module Pagination
|
3
|
-
autoload :WillPaginate, 'meilisearch/pagination/will_paginate'
|
4
|
-
autoload :Kaminari, 'meilisearch/pagination/kaminari'
|
5
|
-
|
6
|
-
def self.create(results, total_hits, options = {})
|
7
|
-
return results if MeiliSearch.configuration[:pagination_backend].nil?
|
8
|
-
|
9
|
-
begin
|
10
|
-
backend = MeiliSearch.configuration[:pagination_backend].to_s.classify
|
11
|
-
|
12
|
-
::MeiliSearch::Pagination.const_get(backend).create(results, total_hits, options)
|
13
|
-
rescue NameError
|
14
|
-
raise(BadConfiguration, 'Unknown pagination backend')
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/lib/meilisearch/railtie.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
namespace :meilisearch do
|
2
|
-
desc 'Reindex all models'
|
3
|
-
task reindex: :environment do
|
4
|
-
MeiliSearch::Utilities.reindex_all_models
|
5
|
-
end
|
6
|
-
|
7
|
-
desc 'Set settings to all indexes'
|
8
|
-
task set_all_settings: :environment do
|
9
|
-
MeiliSearch::Utilities.set_settings_all_models
|
10
|
-
end
|
11
|
-
|
12
|
-
desc 'Clear all indexes'
|
13
|
-
task clear_indexes: :environment do
|
14
|
-
puts 'clearing all indexes'
|
15
|
-
MeiliSearch::Utilities.clear_all_indexes
|
16
|
-
end
|
17
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
module MeiliSearch
|
2
|
-
module Utilities
|
3
|
-
class << self
|
4
|
-
def get_model_classes
|
5
|
-
if Rails.application && defined?(Rails.autoloaders) && Rails.autoloaders.zeitwerk_enabled?
|
6
|
-
Zeitwerk::Loader.eager_load_all
|
7
|
-
elsif Rails.application
|
8
|
-
Rails.application.eager_load!
|
9
|
-
end
|
10
|
-
klasses = MeiliSearch.instance_variable_get(:@included_in)
|
11
|
-
(klasses + klasses.map(&:descendants).flatten).uniq
|
12
|
-
end
|
13
|
-
|
14
|
-
def clear_all_indexes
|
15
|
-
get_model_classes.each(&:clear_index!)
|
16
|
-
end
|
17
|
-
|
18
|
-
def reindex_all_models
|
19
|
-
klasses = get_model_classes
|
20
|
-
|
21
|
-
Rails.logger.info "\n\nReindexing #{klasses.count} models: #{klasses.to_sentence}.\n"
|
22
|
-
|
23
|
-
klasses.each do |klass|
|
24
|
-
Rails.logger.info klass
|
25
|
-
Rails.logger.info "Reindexing #{klass.count} records..."
|
26
|
-
|
27
|
-
klass.ms_reindex!
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def set_settings_all_models
|
32
|
-
klasses = get_model_classes
|
33
|
-
|
34
|
-
Rails.logger.info "\n\nPushing settings for #{klasses.count} models: #{klasses.to_sentence}.\n"
|
35
|
-
|
36
|
-
klasses.each do |klass|
|
37
|
-
Rails.logger.info "Pushing #{klass} settings..."
|
38
|
-
|
39
|
-
klass.ms_set_settings
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|