meilisearch-rails 0.3.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -2
- data/LICENSE +1 -1
- data/README.md +69 -57
- 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 +690 -704
- data/meilisearch-rails.gemspec +4 -4
- metadata +14 -14
- 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,19 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'lib', 'meilisearch', 'version')
|
1
|
+
require File.join(File.dirname(__FILE__), 'lib', 'meilisearch', 'rails', 'version')
|
2
2
|
|
3
3
|
require 'date'
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'meilisearch-rails'
|
7
|
-
s.version = MeiliSearch::VERSION
|
7
|
+
s.version = MeiliSearch::Rails::VERSION
|
8
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 = '
|
11
|
+
s.description = 'Meilisearch integration for Ruby on Rails. See https://github.com/meilisearch/meilisearch'
|
12
12
|
s.email = 'bonjour@meilisearch.com'
|
13
13
|
s.homepage = 'http://github.com/meilisearch/meilisearch-rails'
|
14
14
|
s.licenses = ['MIT']
|
15
15
|
s.require_paths = ['lib']
|
16
|
-
s.summary = '
|
16
|
+
s.summary = 'Meilisearch integration for Ruby on Rails.'
|
17
17
|
|
18
18
|
s.extra_rdoc_files = [
|
19
19
|
'LICENSE',
|
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.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Meili
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.15.4
|
41
|
-
description:
|
41
|
+
description: Meilisearch integration for Ruby on Rails. See https://github.com/meilisearch/meilisearch
|
42
42
|
email: bonjour@meilisearch.com
|
43
43
|
executables: []
|
44
44
|
extensions: []
|
@@ -52,16 +52,16 @@ files:
|
|
52
52
|
- README.md
|
53
53
|
- Rakefile
|
54
54
|
- 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
|
55
|
+
- lib/meilisearch/rails/configuration.rb
|
56
|
+
- lib/meilisearch/rails/errors.rb
|
57
|
+
- lib/meilisearch/rails/ms_job.rb
|
58
|
+
- lib/meilisearch/rails/pagination.rb
|
59
|
+
- lib/meilisearch/rails/pagination/kaminari.rb
|
60
|
+
- lib/meilisearch/rails/pagination/will_paginate.rb
|
61
|
+
- lib/meilisearch/rails/railtie.rb
|
62
|
+
- lib/meilisearch/rails/tasks/meilisearch.rake
|
63
|
+
- lib/meilisearch/rails/utilities.rb
|
64
|
+
- lib/meilisearch/rails/version.rb
|
65
65
|
- meilisearch-rails.gemspec
|
66
66
|
homepage: http://github.com/meilisearch/meilisearch-rails
|
67
67
|
licenses:
|
@@ -85,5 +85,5 @@ requirements: []
|
|
85
85
|
rubygems_version: 3.0.3.1
|
86
86
|
signing_key:
|
87
87
|
specification_version: 4
|
88
|
-
summary:
|
88
|
+
summary: Meilisearch integration for Ruby on Rails.
|
89
89
|
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
|