redisearch-rails 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +64 -0
- data/LICENSE +21 -0
- data/README.md +1 -0
- data/lib/redisearch-rails/configuration.rb +5 -0
- data/lib/redisearch-rails/redisearchable/class_methods.rb +46 -0
- data/lib/redisearch-rails/redisearchable/instance_methods.rb +24 -0
- data/lib/redisearch-rails/redisearchable.rb +13 -0
- data/lib/redisearch-rails/version.rb +3 -0
- data/lib/redisearch-rails.rb +28 -0
- data/redisearch-rails.gemspec +25 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 80ed5e878885bad58d57c08681958ebc92d7b22b94b521e4ec557ba413b2e803
|
4
|
+
data.tar.gz: 96a9a50acea570e90cf15ab24440523f1068c98247ab5227b9de09b89b014578
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b5360060c9f62658e24d83c5f2f867b2240686872b961d8cee58b58801b50c3d23e06631a46a762a5b1b96dd0ab3ace6b05f99c2c35b0314cc6f7cb52b7847fb
|
7
|
+
data.tar.gz: 2ca94e58f7dc8747df3690b954b13b70b3ee21c9ed71ca4dd2fe9728edb35ee28801efd2c9b74bceb074c881e2bf07f22eea4289b9189f14cf107ded67b29fa4
|
data/.gitignore
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
57
|
+
|
58
|
+
*.gem
|
59
|
+
.bundle
|
60
|
+
Gemfile.lock
|
61
|
+
pkg/*
|
62
|
+
coverage/*
|
63
|
+
.DS_Store
|
64
|
+
.byebug_history
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Ticketplus.cl
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# redisearch-rails
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module RediSearch
|
2
|
+
module RediSearchable
|
3
|
+
module ClassMethods
|
4
|
+
|
5
|
+
attr_reader :redisearch_index
|
6
|
+
|
7
|
+
def redisearch(*args, schema:, **options)
|
8
|
+
prefix = options[:prefix]
|
9
|
+
|
10
|
+
index_name = [prefix, model_name.plural].compact.join("_")
|
11
|
+
@redisearch_index = RediSearch.client.generate_index(index_name, schema)
|
12
|
+
|
13
|
+
scope :redisearch_import, -> { all }
|
14
|
+
|
15
|
+
include InstanceMethods
|
16
|
+
extend RediSearchClassMethods
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
module RediSearchClassMethods
|
22
|
+
|
23
|
+
def redisearch(query, **options)
|
24
|
+
result = redisearch_index.search(query, options.deep_merge(nocontent: true))
|
25
|
+
result.shift # remove the first element (count)
|
26
|
+
self.find(result)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Reindex all
|
30
|
+
def reindex(recreate: false, only: [], **options)
|
31
|
+
index = redisearch_index
|
32
|
+
|
33
|
+
index.drop if recreate
|
34
|
+
index.create unless index.exists?
|
35
|
+
|
36
|
+
redisearch_import.find_in_batches do |elements|
|
37
|
+
redisearch_index.client.multi do
|
38
|
+
elements.each do |element|
|
39
|
+
element.redisearch_document.add(options.deep_merge(replace: true, partial: true))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module RediSearch
|
2
|
+
module RediSearchable
|
3
|
+
module InstanceMethods
|
4
|
+
|
5
|
+
def redisearch_document
|
6
|
+
@redisearch_document ||= generate_redisearch_document
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def generate_redisearch_document
|
12
|
+
index = self.class.redisearch_index
|
13
|
+
fields = index.schema.fields.map(&:name)
|
14
|
+
fields_values = Hash[fields.flatten.map! { |field| [field, public_send(field)] }]
|
15
|
+
index.generate_document(redisearch_document_id, fields_values)
|
16
|
+
end
|
17
|
+
|
18
|
+
def redisearch_document_id
|
19
|
+
"0#{id}"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module RediSearch
|
2
|
+
module RediSearchable
|
3
|
+
autoload :ClassMethods, 'redisearch-rails/redisearchable/class_methods'
|
4
|
+
autoload :InstanceMethods, 'redisearch-rails/redisearchable/instance_methods'
|
5
|
+
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
extend RediSearch::RediSearchable::ClassMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'redisearch-rails/configuration'
|
2
|
+
|
3
|
+
require "active_support/lazy_load_hooks"
|
4
|
+
|
5
|
+
module RediSearch
|
6
|
+
autoload :RediSearchable, 'redisearch-rails/redisearchable'
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_writer :configuration
|
10
|
+
|
11
|
+
def configuration
|
12
|
+
@configuration ||= Configuration.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def configure
|
16
|
+
yield(configuration)
|
17
|
+
end
|
18
|
+
|
19
|
+
def client
|
20
|
+
@client ||= RediSearcher::Client.new(configuration.redis_config)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
ActiveSupport.on_load(:active_record) do
|
27
|
+
include RediSearch::RediSearchable
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "redisearch-rails/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "redisearch-rails"
|
7
|
+
s.version = RediSearch::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Patricio Beckmann"]
|
10
|
+
s.email = ["pato.beckmann@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/Ticketplus/redisearch-rails"
|
12
|
+
s.summary = %q{RediSearch on Rails}
|
13
|
+
s.description = %q{'Index and search Rails models on redisearch'}
|
14
|
+
s.required_ruby_version = '>= 2.3'
|
15
|
+
s.license = 'MIT'
|
16
|
+
|
17
|
+
s.add_dependency 'activerecord', '~> 4.2'
|
18
|
+
s.add_dependency 'activesupport', '~> 4.2'
|
19
|
+
|
20
|
+
s.add_dependency "redi_searcher", '~> 0.1', '>= 0.1.1'
|
21
|
+
|
22
|
+
s.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^(spec/)}) }
|
23
|
+
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redisearch-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Patricio Beckmann
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: redi_searcher
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.1'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 0.1.1
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0.1'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.1.1
|
61
|
+
description: "'Index and search Rails models on redisearch'"
|
62
|
+
email:
|
63
|
+
- pato.beckmann@gmail.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- ".gitignore"
|
69
|
+
- LICENSE
|
70
|
+
- README.md
|
71
|
+
- lib/redisearch-rails.rb
|
72
|
+
- lib/redisearch-rails/configuration.rb
|
73
|
+
- lib/redisearch-rails/redisearchable.rb
|
74
|
+
- lib/redisearch-rails/redisearchable/class_methods.rb
|
75
|
+
- lib/redisearch-rails/redisearchable/instance_methods.rb
|
76
|
+
- lib/redisearch-rails/version.rb
|
77
|
+
- redisearch-rails.gemspec
|
78
|
+
homepage: https://github.com/Ticketplus/redisearch-rails
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '2.3'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubygems_version: 3.0.1
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: RediSearch on Rails
|
101
|
+
test_files: []
|