mongoid-elasticsearch 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/Gemfile +1 -1
- data/gemfiles/mongoid3.gemfile +7 -0
- data/lib/mongoid/elasticsearch/response.rb +21 -4
- data/lib/mongoid/elasticsearch/version.rb +1 -1
- data/mongoid-elasticsearch.gemspec +2 -2
- data/spec/models/article.rb +1 -1
- data/spec/models/namespaced.rb +1 -1
- data/spec/models/post.rb +7 -2
- data/spec/mongoid_elasticsearch_spec.rb +18 -2
- data/spec/spec_helper.rb +1 -0
- metadata +18 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f0c6eaa6812978af90ec347086edbcc03e71d8d
|
4
|
+
data.tar.gz: 9d8f30124b7a438dfab87a4e605f5c288050e466
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f403b7966a91e238c8cdd7e4d3b990d5a5344f5cf60a51bf76178ed06cd75f998cb96efc5850a5a834c8e6a012709b52f40dd8df7cf7588daa039d4b1c799c9
|
7
|
+
data.tar.gz: 9396e8ac12fb662c50cc3e159d957a862952635747a9946c1fce4dc054eee67b491b067f7ff3ebb6f79e4a02d6f6c9cf175677aa1a4a98a303600ec0153589d4
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -61,7 +61,11 @@ module Mongoid
|
|
61
61
|
hits.map do |h|
|
62
62
|
s = h.delete('_source')
|
63
63
|
m = Hashie::Mash.new(h.merge(s))
|
64
|
-
|
64
|
+
if defined?(Moped::BSON)
|
65
|
+
m.id = Moped::BSON::ObjectId.from_string(h['_id'])
|
66
|
+
else
|
67
|
+
m.id = BSON::ObjectId.from_string(h['_id'])
|
68
|
+
end
|
65
69
|
m._id = m.id
|
66
70
|
m
|
67
71
|
end
|
@@ -148,13 +152,26 @@ module Mongoid
|
|
148
152
|
hits.map do |h|
|
149
153
|
klass = find_klass(h['_type'])
|
150
154
|
source = h.delete('_source')
|
151
|
-
|
152
|
-
|
153
|
-
|
155
|
+
if defined?(Moped::BSON)
|
156
|
+
source.each do |k,v|
|
157
|
+
if v.is_a?(Hash) && v.has_key?("$oid")
|
158
|
+
source[k] = Moped::BSON::ObjectId.from_string(v["$oid"])
|
159
|
+
end
|
160
|
+
end
|
161
|
+
else
|
162
|
+
source.each do |k,v|
|
163
|
+
if v.is_a?(Hash) && v.has_key?("$oid")
|
164
|
+
source[k] = BSON::ObjectId.from_string(v["$oid"])
|
165
|
+
end
|
154
166
|
end
|
155
167
|
end
|
156
168
|
begin
|
157
169
|
m = klass.new(h.merge(source))
|
170
|
+
if defined?(Moped::BSON)
|
171
|
+
m.id = Moped::BSON::ObjectId.from_string(h['_id'])
|
172
|
+
else
|
173
|
+
m.id = BSON::ObjectId.from_string(h['_id'])
|
174
|
+
end
|
158
175
|
rescue Mongoid::Errors::UnknownAttribute
|
159
176
|
klass.class_eval <<-RUBY, __FILE__, __LINE__+1
|
160
177
|
attr_accessor :_type, :_score, :_source
|
@@ -18,10 +18,10 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "mongoid", "
|
21
|
+
spec.add_dependency "mongoid", [">= 3.0", "< 4.1"]
|
22
22
|
spec.add_dependency "elasticsearch", "~> 0.4.1"
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler"
|
24
|
+
spec.add_development_dependency "bundler"
|
25
25
|
spec.add_development_dependency "rake"
|
26
26
|
spec.add_development_dependency "rspec"
|
27
27
|
spec.add_development_dependency "kaminari"
|
data/spec/models/article.rb
CHANGED
data/spec/models/namespaced.rb
CHANGED
data/spec/models/post.rb
CHANGED
@@ -3,8 +3,13 @@ class Post
|
|
3
3
|
|
4
4
|
field :name, type: String
|
5
5
|
field :content, type: String
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
if defined?(Moped::BSON)
|
8
|
+
field :my_object_id, type: Moped::BSON::ObjectId
|
9
|
+
else
|
10
|
+
field :my_object_id, type: BSON::ObjectId
|
11
|
+
end
|
12
|
+
|
8
13
|
|
9
14
|
include Mongoid::Elasticsearch
|
10
15
|
elasticsearch!
|
@@ -44,7 +44,14 @@ describe Article do
|
|
44
44
|
@article_1 = Article.create!(name: 'test article name likes', tags: 'likely')
|
45
45
|
@article_2 = Article.create!(name: 'tests likely an another article title')
|
46
46
|
@article_3 = Article.create!(name: 'a strange name for this stuff')
|
47
|
-
|
47
|
+
|
48
|
+
if defined?(Moped::BSON)
|
49
|
+
@post_1 = Post.create!(name: 'object_id', my_object_id: Moped::BSON::ObjectId.new)
|
50
|
+
else
|
51
|
+
@post_1 = Post.create!(name: 'object_id', my_object_id: BSON::ObjectId.new)
|
52
|
+
end
|
53
|
+
|
54
|
+
|
48
55
|
Article.es.index.refresh
|
49
56
|
Post.es.index.refresh
|
50
57
|
end
|
@@ -76,7 +83,12 @@ describe Article do
|
|
76
83
|
|
77
84
|
it 'restores BSON::ObjectId with wrapper :model' do
|
78
85
|
results = Post.es.search 'object_id'
|
79
|
-
|
86
|
+
if defined?(Moped::BSON)
|
87
|
+
results.first.my_object_id.should be_kind_of(Moped::BSON::ObjectId)
|
88
|
+
else
|
89
|
+
results.first.my_object_id.should be_kind_of(BSON::ObjectId)
|
90
|
+
end
|
91
|
+
|
80
92
|
results.first.my_object_id.should eq(@post_1.my_object_id)
|
81
93
|
end
|
82
94
|
|
@@ -254,6 +266,10 @@ describe "Multisearch" do
|
|
254
266
|
|
255
267
|
it 'works' do
|
256
268
|
response = Mongoid::Elasticsearch.search 'test'
|
269
|
+
#p response
|
270
|
+
#pp response.results
|
271
|
+
#pp response.raw_response
|
272
|
+
#pp @article_1
|
257
273
|
response.length.should eq 4
|
258
274
|
response.to_a.map(&:class).map(&:name).uniq.sort.should eq ['Article', 'Namespaced::Model', 'Post']
|
259
275
|
response.select { |r| r.class == Article && r.id == @article_1.id }.first.should_not be_nil
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-elasticsearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- glebtv
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
- - <
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.
|
22
|
+
version: '4.1'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- - <
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: 4.
|
32
|
+
version: '4.1'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: elasticsearch
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,16 +48,16 @@ dependencies:
|
|
42
48
|
name: bundler
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
|
-
- -
|
51
|
+
- - '>='
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
53
|
+
version: '0'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
|
-
- -
|
58
|
+
- - '>='
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
60
|
+
version: '0'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: rake
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -169,6 +175,7 @@ files:
|
|
169
175
|
- Rakefile
|
170
176
|
- gemfiles/es-0.4.1.gemfile
|
171
177
|
- gemfiles/es-git.gemfile
|
178
|
+
- gemfiles/mongoid3.gemfile
|
172
179
|
- lib/mongoid-elasticsearch.rb
|
173
180
|
- lib/mongoid/elasticsearch.rb
|
174
181
|
- lib/mongoid/elasticsearch/callbacks.rb
|
@@ -207,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
214
|
version: '0'
|
208
215
|
requirements: []
|
209
216
|
rubyforge_project:
|
210
|
-
rubygems_version: 2.1
|
217
|
+
rubygems_version: 2.2.1
|
211
218
|
signing_key:
|
212
219
|
specification_version: 4
|
213
220
|
summary: Simple and easy integration of mongoid with the new elasticsearch gem
|