elasticsearch-model-mongoid_extensions 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +11 -0
- data/Gemfile +4 -0
- data/Guardfile +5 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +197 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/elasticsearch-model-mongoid_extensions.gemspec +33 -0
- data/lib/elasticsearch/model/importing_monkey_patch.rb +6 -0
- data/lib/elasticsearch/model/mongoid_extensions/fields.rb +30 -0
- data/lib/elasticsearch/model/mongoid_extensions/importing.rb +18 -0
- data/lib/elasticsearch/model/mongoid_extensions/localized.rb +53 -0
- data/lib/elasticsearch/model/mongoid_extensions/sci.rb +67 -0
- data/lib/elasticsearch/model/mongoid_extensions/version.rb +7 -0
- data/lib/elasticsearch/model/mongoid_extensions.rb +11 -0
- metadata +224 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c3d6ba1edb6c47a91c710c5578b7bb24c17c5deb
|
4
|
+
data.tar.gz: 89e96917a42b16caf84b6f1528136204595930ec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4a687c4cbf9a4d1b4d3b43588d31858355d16887c56ec6c3f5e46519c3a6064cf6d4eefd75a1263d61868f69711a9ff623f8e9f7dd0d9be99123df18b680937f
|
7
|
+
data.tar.gz: bb8933aeb9a96b4b1a3c98eda924f2ea1044648901d9d2f769d694f4d0501ae0682b059b16526ec0195610915f70b7f23a07236bed9b720ad8bd22bbadc0abf1
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 Tomáš Celizna
|
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/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Tomas Celizna
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
# Elasticsearch::Model::MongoidExtensions
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/tomasc/elasticsearch-model-mongoid_extensions.svg)](https://travis-ci.org/tomasc/elasticsearch-model-mongoid_extensions) [![Gem Version](https://badge.fury.io/rb/elasticsearch-model-mongoid_extensions.svg)](http://badge.fury.io/rb/elasticsearch-model-mongoid_extensions) [![Coverage Status](https://img.shields.io/coveralls/tomasc/elasticsearch-model-mongoid_extensions.svg)](https://coveralls.io/r/tomasc/elasticsearch-model-mongoid_extensions)
|
4
|
+
|
5
|
+
[Elasticsearch::Model](https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-model) extensions for Mongoid adding support of [single collection inheritance](#sci) (by the way of multiple indexes), [localized fields](#localized) and [mapped fields extraction](#fields).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'elasticsearch-model-mongoid_extensions'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install elasticsearch-model-mongoid_extensions
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### SCI
|
26
|
+
|
27
|
+
Using a separate index per each subclass is beneficial in case the field definitions vary across the subclasses (as it may in document oriented databases such as Mongoid). On the contrary sharing an index for all subclasses might lead into conflicts with different mappings of fields with same name.
|
28
|
+
|
29
|
+
If your subclass tree shares same field definitions, you might prefer use only one index (see the `inheritance_enabled` setting on [`ElasticSearch::Model`](https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-model#settings)).
|
30
|
+
|
31
|
+
#### Setup
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
class MyDoc
|
35
|
+
include Mongoid::Document
|
36
|
+
include Elasticsearch::Model::MongoidExtensions::SCI
|
37
|
+
|
38
|
+
field :field_1, type: String
|
39
|
+
|
40
|
+
mapping do
|
41
|
+
indexes :field_1
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class MyDoc1 < MyDoc
|
46
|
+
field :field_2, type: String
|
47
|
+
|
48
|
+
mapping do
|
49
|
+
indexes :field_2
|
50
|
+
end
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
The `MyDoc` class will use index with name `my_docs`, the `MyDoc1` subclass will use `my_doc_1s`. If you wish to customize the index name (prepend application name, append Rails environment name etc.) supply an `index_name_template` that will be automatically evaluated in context of each of the subclasses. Similarly a template can be used for document type.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
class MyDoc
|
58
|
+
# …
|
59
|
+
index_name_template -> (cls) { ['elasticsearch-model-mongoid_extensions', cls.model_name.plural].join('-') }
|
60
|
+
document_type_template -> (cls) { cls.model_name.singular }
|
61
|
+
# …
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
#### Index creation & refresh
|
66
|
+
|
67
|
+
Use the class methods defined on the base class to create/refresh indexes for all descending classes as well:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
MyDoc.create_index! # will trigger MyDoc1.create_index! as well
|
71
|
+
MyDoc.refresh_index! # will trigger MyDoc1.refresh_index! as well
|
72
|
+
```
|
73
|
+
|
74
|
+
#### Importing
|
75
|
+
|
76
|
+
Import on base class (here `MyDoc`) imports all documents of descending classes as well:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
MyDoc.import # will trigger MyDoc1.import as well
|
80
|
+
```
|
81
|
+
|
82
|
+
#### Indexing
|
83
|
+
|
84
|
+
Indexing works as expected using the standard proxied methods:
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
my_doc.__elasticsearch__.index_document
|
88
|
+
my_doc.__elasticsearch__.update_document
|
89
|
+
my_doc.__elasticsearch__.delete_document
|
90
|
+
```
|
91
|
+
|
92
|
+
#### Search
|
93
|
+
|
94
|
+
Search on base class searches descendants as well:
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
MyDoc.search('*') # will search MyDoc1 as well
|
98
|
+
```
|
99
|
+
|
100
|
+
Use the `type` option to limit the searched classes:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
MyDoc.search('*', type: [MyDoc.document_type]) # will search only MyDoc
|
104
|
+
```
|
105
|
+
|
106
|
+
### Localized
|
107
|
+
|
108
|
+
By including the `Localized` module, all Mongoid localized fields will be automatically mapped and serialized as objects:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
class MyDoc3
|
112
|
+
# …
|
113
|
+
include Elasticsearch::Model::MongoidExtensions::Localized
|
114
|
+
|
115
|
+
field :field_3, type: String, localize: true
|
116
|
+
|
117
|
+
mapping do
|
118
|
+
indexes :field_3
|
119
|
+
end
|
120
|
+
# …
|
121
|
+
end
|
122
|
+
```
|
123
|
+
|
124
|
+
#### Mapping
|
125
|
+
|
126
|
+
The mapping will be altered, so that fields that would be originally mapped as:
|
127
|
+
|
128
|
+
```
|
129
|
+
{ 'field_1' => { 'type' => 'string' } }
|
130
|
+
```
|
131
|
+
|
132
|
+
Are automatically transformed to:
|
133
|
+
|
134
|
+
```
|
135
|
+
{ 'field_1' => { 'type' => 'object', 'properties' => { 'en' => { 'type' => 'string' } } } }
|
136
|
+
```
|
137
|
+
|
138
|
+
This happens for all `I18n.available_locales`.
|
139
|
+
|
140
|
+
#### Serializing
|
141
|
+
|
142
|
+
The `:as_indexed_json` is automatically transformed behind the scenes to correspond with the mapping. Therefore it can be specified as usual:
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
def as_indexed_json(options = {})
|
146
|
+
super(only: %i(field_1))
|
147
|
+
end
|
148
|
+
```
|
149
|
+
|
150
|
+
The result automatically becoming:
|
151
|
+
|
152
|
+
```
|
153
|
+
{ 'field_1' => { 'en' => 'value_en', 'cs' => 'value_cs' } }
|
154
|
+
```
|
155
|
+
|
156
|
+
TODO: it might be helpful to add support for the I18n's fallbacks, so that missing value is correctly replaced by a fallback.
|
157
|
+
|
158
|
+
### Fields
|
159
|
+
|
160
|
+
The gem add `to_fields` method on `mappings` that returns all fields names as they are mapped in Elasticsearch. This is especially useful in combination with the `Localized` mixin as it allows to select only fields for a particular locale and use those when searching.
|
161
|
+
|
162
|
+
Having document with the following mapping:
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
class MyDocFields
|
166
|
+
# …
|
167
|
+
mapping do
|
168
|
+
indexes :field_1
|
169
|
+
indexes :field_2 do
|
170
|
+
indexes :number, type: :integer, index: :not_analyzed
|
171
|
+
indexes :string, type: :string, index: :not_analyzed
|
172
|
+
end
|
173
|
+
end
|
174
|
+
# …
|
175
|
+
end
|
176
|
+
```
|
177
|
+
|
178
|
+
The `#to_fields` returns:
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
MyDocFields.mapping.to_fields # => ["field_1", "field_2", "field_2.number", "field_2.string"]
|
182
|
+
```
|
183
|
+
|
184
|
+
## Development
|
185
|
+
|
186
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
187
|
+
|
188
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
189
|
+
|
190
|
+
## Contributing
|
191
|
+
|
192
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tomasc/elasticsearch-model-mongoid_extensions.
|
193
|
+
|
194
|
+
|
195
|
+
## License
|
196
|
+
|
197
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "elasticsearch/model/mongoid_extensions"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'elasticsearch/model/mongoid_extensions/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'elasticsearch-model-mongoid_extensions'
|
8
|
+
spec.version = Elasticsearch::Model::MongoidExtensions::VERSION
|
9
|
+
spec.authors = ['Tomas Celizna']
|
10
|
+
spec.email = ['tomas.celizna@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Elasticsearch::Model extensions for Mongoid adding support of single collection inheritance (by the way of multiple indexes), localized fields and mapped fields extraction.'
|
13
|
+
spec.homepage = 'https://github.com/tomasc/elasticsearch-model-mongoid_extensions'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'activesupport', '>= 4', '< 6'
|
22
|
+
spec.add_dependency 'elasticsearch-model', '~> 0.1'
|
23
|
+
spec.add_dependency 'elasticsearch-rails', '~> 0.1'
|
24
|
+
spec.add_dependency 'mongoid', '~> 5'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
27
|
+
spec.add_development_dependency 'database_cleaner'
|
28
|
+
spec.add_development_dependency 'guard'
|
29
|
+
spec.add_development_dependency 'guard-minitest'
|
30
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
31
|
+
spec.add_development_dependency 'minitest-around'
|
32
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
33
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'elasticsearch/model/indexing'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Model
|
5
|
+
module MongoidExtensions
|
6
|
+
module Fields
|
7
|
+
def to_fields
|
8
|
+
mapping_hash = to_hash[@type.to_sym]
|
9
|
+
|
10
|
+
l = lambda do |h, parent = nil|
|
11
|
+
res = []
|
12
|
+
h.each do |field_name, props|
|
13
|
+
key_type = Elasticsearch::Model::Indexing::Mappings::TYPES_WITH_EMBEDDED_PROPERTIES.include?(props[:type].to_s) ? :properties : :fields
|
14
|
+
path = [parent, field_name].compact.join('.')
|
15
|
+
res << path
|
16
|
+
res += l.call(props[key_type], path) if props[key_type].present?
|
17
|
+
end
|
18
|
+
res.compact
|
19
|
+
end
|
20
|
+
|
21
|
+
l.call(mapping_hash[:properties]).map(&:to_s)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Elasticsearch::Model::Indexing::Mappings
|
29
|
+
include Elasticsearch::Model::MongoidExtensions::Fields
|
30
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# NOTE: waiting for https://github.com/elastic/elasticsearch-rails/pull/625 to be merged
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Model
|
5
|
+
module MongoidExtensions
|
6
|
+
module Importing
|
7
|
+
def __find_in_batches(options = {})
|
8
|
+
batch_size = options.fetch(:batch_size, 1_000)
|
9
|
+
base_criteria = options.fetch(:criteria, all)
|
10
|
+
|
11
|
+
base_criteria.no_timeout.each_slice(batch_size) do |items|
|
12
|
+
yield items
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'elasticsearch/model/indexing'
|
2
|
+
|
3
|
+
module Elasticsearch
|
4
|
+
module Model
|
5
|
+
module MongoidExtensions
|
6
|
+
module Localized
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
class Mappings < Elasticsearch::Model::Indexing::Mappings
|
10
|
+
def indexes(name, options = {}, &block)
|
11
|
+
# take the cls from options on the Mappings object
|
12
|
+
@cls ||= @options.delete(:cls) if @options[:cls]
|
13
|
+
|
14
|
+
return super(name, options, &block) unless @cls
|
15
|
+
|
16
|
+
field = @cls.fields[name.to_s] || @cls.fields.detect { |_, meta| meta.options[:as] == name.to_sym }.try(:last)
|
17
|
+
|
18
|
+
return super(name, options, &block) unless field.present? && field.localized?
|
19
|
+
|
20
|
+
super(name) do
|
21
|
+
Array(::I18n.available_locales).each do |locale|
|
22
|
+
super(locale, options, &block)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module Serializing
|
29
|
+
def as_indexed_json(*args)
|
30
|
+
super(*args).tap do |obj|
|
31
|
+
fields.select { |_, field| field.localized? }.each do |name, field|
|
32
|
+
aliased_name = field.options[:as].to_s
|
33
|
+
translations_field_name = [name, 'translations'].join('_')
|
34
|
+
if obj.key?(name) then obj[name] = send(translations_field_name)
|
35
|
+
elsif obj.key?(aliased_name) then obj[aliased_name] = send(translations_field_name)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
included do
|
43
|
+
def self.mapping(options = {}, &block)
|
44
|
+
__elasticsearch__.instance_variable_set(:@mapping, Mappings.new(document_type, { cls: self }.merge(options))) unless __elasticsearch__.instance_variable_get(:@mapping)
|
45
|
+
__elasticsearch__.mapping(options, &block)
|
46
|
+
end
|
47
|
+
|
48
|
+
prepend Serializing
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Elasticsearch
|
2
|
+
module Model
|
3
|
+
module MongoidExtensions
|
4
|
+
module SCI
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
include Elasticsearch::Model
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def index_name_template(proc)
|
13
|
+
@@index_name_template = proc
|
14
|
+
index_name @@index_name_template.call(self)
|
15
|
+
end
|
16
|
+
|
17
|
+
def document_type_template(proc)
|
18
|
+
@@document_type_template = proc
|
19
|
+
document_type @@document_type_template.call(self)
|
20
|
+
end
|
21
|
+
|
22
|
+
def inherited(descendant)
|
23
|
+
super(descendant)
|
24
|
+
|
25
|
+
descendant.instance_eval do
|
26
|
+
include Elasticsearch::Model
|
27
|
+
end
|
28
|
+
|
29
|
+
# propagate index_name_template
|
30
|
+
descendant.index_name @@index_name_template.call(descendant) if defined?(@@index_name_template)
|
31
|
+
descendant.document_type @@document_type_template.call(descendant) if defined?(@@document_type_template)
|
32
|
+
|
33
|
+
# propagate settings
|
34
|
+
descendant.settings settings.to_hash
|
35
|
+
|
36
|
+
# propagate mapping to all descendants
|
37
|
+
mapping.instance_variable_get(:@mapping).each do |name, options|
|
38
|
+
descendant.mapping do
|
39
|
+
indexes(name, options)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_index!(options = {})
|
45
|
+
__elasticsearch__.create_index!(options)
|
46
|
+
descendants.each { |cls| cls.__elasticsearch__.create_index!(options) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def refresh_index!(options = {})
|
50
|
+
__elasticsearch__.refresh_index!(options)
|
51
|
+
descendants.each { |cls| cls.__elasticsearch__.refresh_index!(options) }
|
52
|
+
end
|
53
|
+
|
54
|
+
def search(query_or_payload, options = {})
|
55
|
+
models = options.fetch :models, [self] + descendants
|
56
|
+
Elasticsearch::Model.search(query_or_payload, models, options)
|
57
|
+
end
|
58
|
+
|
59
|
+
def import(options = {}, &block)
|
60
|
+
__elasticsearch__.import(options.merge(criteria: criteria.type(to_s)), &block)
|
61
|
+
descendants.each { |cls| cls.import(options, &block) }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'mongoid'
|
2
|
+
require 'elasticsearch/model'
|
3
|
+
|
4
|
+
require 'active_support/concern'
|
5
|
+
require 'elasticsearch/model/importing_monkey_patch'
|
6
|
+
|
7
|
+
require 'elasticsearch/model/mongoid_extensions/fields'
|
8
|
+
require 'elasticsearch/model/mongoid_extensions/localized'
|
9
|
+
require 'elasticsearch/model/mongoid_extensions/sci'
|
10
|
+
|
11
|
+
require 'elasticsearch/model/mongoid_extensions/version'
|
metadata
ADDED
@@ -0,0 +1,224 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: elasticsearch-model-mongoid_extensions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomas Celizna
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '6'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '6'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: elasticsearch-model
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.1'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0.1'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: elasticsearch-rails
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0.1'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0.1'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: mongoid
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '5'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '5'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: bundler
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '1.12'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '1.12'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: database_cleaner
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: guard
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: guard-minitest
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: minitest
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '5.0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '5.0'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: minitest-around
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: rake
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - "~>"
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '10.0'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - "~>"
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '10.0'
|
173
|
+
description:
|
174
|
+
email:
|
175
|
+
- tomas.celizna@gmail.com
|
176
|
+
executables: []
|
177
|
+
extensions: []
|
178
|
+
extra_rdoc_files: []
|
179
|
+
files:
|
180
|
+
- ".gitignore"
|
181
|
+
- ".travis.yml"
|
182
|
+
- Gemfile
|
183
|
+
- Guardfile
|
184
|
+
- LICENSE
|
185
|
+
- LICENSE.txt
|
186
|
+
- README.md
|
187
|
+
- Rakefile
|
188
|
+
- bin/console
|
189
|
+
- bin/setup
|
190
|
+
- elasticsearch-model-mongoid_extensions.gemspec
|
191
|
+
- lib/elasticsearch/model/importing_monkey_patch.rb
|
192
|
+
- lib/elasticsearch/model/mongoid_extensions.rb
|
193
|
+
- lib/elasticsearch/model/mongoid_extensions/fields.rb
|
194
|
+
- lib/elasticsearch/model/mongoid_extensions/importing.rb
|
195
|
+
- lib/elasticsearch/model/mongoid_extensions/localized.rb
|
196
|
+
- lib/elasticsearch/model/mongoid_extensions/sci.rb
|
197
|
+
- lib/elasticsearch/model/mongoid_extensions/version.rb
|
198
|
+
homepage: https://github.com/tomasc/elasticsearch-model-mongoid_extensions
|
199
|
+
licenses:
|
200
|
+
- MIT
|
201
|
+
metadata: {}
|
202
|
+
post_install_message:
|
203
|
+
rdoc_options: []
|
204
|
+
require_paths:
|
205
|
+
- lib
|
206
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
207
|
+
requirements:
|
208
|
+
- - ">="
|
209
|
+
- !ruby/object:Gem::Version
|
210
|
+
version: '0'
|
211
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ">="
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
requirements: []
|
217
|
+
rubyforge_project:
|
218
|
+
rubygems_version: 2.4.5.1
|
219
|
+
signing_key:
|
220
|
+
specification_version: 4
|
221
|
+
summary: Elasticsearch::Model extensions for Mongoid adding support of single collection
|
222
|
+
inheritance (by the way of multiple indexes), localized fields and mapped fields
|
223
|
+
extraction.
|
224
|
+
test_files: []
|