mebla 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mebla (1.0.2)
4
+ mebla (1.0.3)
5
5
  bson (= 1.2.0)
6
6
  bson_ext (= 1.2.0)
7
7
  mebla
@@ -58,7 +58,7 @@ GEM
58
58
  yajl-ruby (> 0.7.9)
59
59
  tzinfo (0.3.24)
60
60
  will_paginate (3.0.pre2)
61
- yajl-ruby (0.8.1)
61
+ yajl-ruby (0.8.2)
62
62
  yard (0.6.4)
63
63
 
64
64
  PLATFORMS
data/README.md CHANGED
@@ -82,6 +82,49 @@ You can also index embedded documents as follows:
82
82
 
83
83
  This will index all comments and make it available for searching directly through the Comment model.
84
84
 
85
+ #### Indexing methods
86
+
87
+ You can also index method results:
88
+
89
+ class Post
90
+ include Mongoid::Document
91
+ include Mongoid::Mebla
92
+ field :title
93
+ field :author
94
+ field :body
95
+ field :publish_date, :type => Date
96
+ field :tags, :type => Array
97
+
98
+ embeds_many :comments
99
+ search_in :author, :body, :publish_date, :tags, :permalink, :title => { :boost => 2.0, :analyzer => 'snowball' }
100
+
101
+ def permalink
102
+ self.title.gsub(/\s/, "-").downcase
103
+ end
104
+ end
105
+
106
+ This will index the result of the method permalink.
107
+
108
+ #### Indexing fields of relations
109
+
110
+ You can also index fields of relations:
111
+
112
+ class Post
113
+ include Mongoid::Document
114
+ include Mongoid::Mebla
115
+ field :title
116
+ field :author
117
+ field :body
118
+ field :publish_date, :type => Date
119
+ field :tags, :type => Array
120
+
121
+ embeds_many :comments
122
+ search_in :author, :body, :publish_date, :tags, :title => { :boost => 2.0, :analyzer => 'snowball' },
123
+ :search_relations => {:comments => :author}
124
+ end
125
+
126
+ This will index authors of all comments embedded with this Post.
127
+
85
128
  ### Searching the index
86
129
 
87
130
  Mebla supports two types of search, index search and model search; in index search Mebla searches
data/TODO.md CHANGED
@@ -1,8 +1,14 @@
1
+ TODO for version 1.1.0
2
+ ==============
3
+
4
+ * <strike>add ability to index embedded documents fields (as part of the parent document)</strike>
5
+ * <strike>add instructions for indexing methods to README.md</strike>
6
+ * <strike>add ability to index methods results</strike>
7
+
1
8
  TODO for version 1.0.1
2
9
  ==============
3
10
 
4
- * add ability to index embedded documents (as part of the parent document)
5
- * properly handle sub classes
11
+ * <strike>properly handle sub classes</strike>
6
12
 
7
13
  TODO for version 1.0.0
8
14
  ==============
@@ -13,5 +19,5 @@ TODO for version 1.0.0
13
19
  Future plan
14
20
  =======
15
21
 
16
- * optimize : should find a solution for not refreshing the index while indexing embedded documents in lib/mebla/context
17
- * optimize : refractor result_set
22
+ * optimize : refractor result_set
23
+ * <strike>optimize : should find a solution for not refreshing the index while indexing embedded documents in lib/mebla/context</strike> not necessary since indexing/reindexing
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.3
1
+ 1.1.0
data/lib/mebla/context.rb CHANGED
@@ -112,9 +112,9 @@ module Mebla
112
112
  entries = []
113
113
  unless to_index.embedded?
114
114
  if to_index.sub_class?
115
- entries = to_index.any_in(:_type => [to_index.name]).only(to_index.search_fields)
115
+ entries = to_index.any_in(:_type => [to_index.name])
116
116
  else
117
- entries = to_index.any_in(:_type => [nil, to_index.name]).only(to_index.search_fields)
117
+ entries = to_index.any_in(:_type => [nil, to_index.name])
118
118
  end
119
119
  else
120
120
  parent = to_index.embedded_parent
@@ -122,9 +122,9 @@ module Mebla
122
122
 
123
123
  parent.all.each do |parent_record|
124
124
  if to_index.sub_class?
125
- entries += parent_record.send(access_method.to_sym).any_in(:_type => [to_index.name]).only(to_index.search_fields)
125
+ entries += parent_record.send(access_method.to_sym).any_in(:_type => [to_index.name])
126
126
  else
127
- entries += parent_record.send(access_method.to_sym).any_in(:_type => [nil, to_index.name]).only(to_index.search_fields)
127
+ entries += parent_record.send(access_method.to_sym).any_in(:_type => [nil, to_index.name])
128
128
  end
129
129
  end
130
130
  end
@@ -134,12 +134,43 @@ module Mebla
134
134
 
135
135
  # Build the queries for this model
136
136
  entries.each do |document|
137
- attrs = document.attributes.dup # make sure we dont modify the document it self
138
- attrs["id"] = attrs.delete("_id") # the id is already added in the meta data of the action part of the query
137
+ attrs = {} #document.attributes.dup # make sure we dont modify the document it self
138
+ attrs[:id] = document.attributes["_id"] # the id is already added in the meta data of the action part of the query
139
139
 
140
+ # only index search fields and methods
141
+ document.class.search_fields.each do |field|
142
+ if document.attributes.keys.include?(field.to_s)
143
+ attrs[field] = document.attributes[field.to_s]
144
+ else
145
+ attrs[field] = document.send(field)
146
+ end
147
+ end
140
148
 
141
- # only index search fields
142
- attrs.select!{|field, value| document.class.search_fields.include?(field.to_sym)}
149
+ # index relational fields
150
+ document.class.search_relations.each do |relation, fields|
151
+ items = document.send(relation.to_sym)
152
+
153
+ next if items.nil?
154
+
155
+ if items.is_a?(Array)
156
+ next if items.empty?
157
+ attrs[relation] = []
158
+ items.each do |item|
159
+ if fields.is_a?(Array)
160
+ attrs[relation] << item.attributes.reject{|key, value| !fields.include?(key.to_sym)}
161
+ else
162
+ attrs[relation] << { fields => item.attributes[fields.to_s] }
163
+ end
164
+ end
165
+ else
166
+ attrs[relation] = {}
167
+ if fields.is_a?(Array)
168
+ attrs[relation].merge!(items.attributes.reject{|key, value| !fields.include?(key.to_sym)})
169
+ else
170
+ attrs[relation].merge!({ fields => items.attributes[fields.to_s] })
171
+ end
172
+ end
173
+ end
143
174
 
144
175
  # If embedded get the parent id
145
176
  if document.embedded?
@@ -1,9 +1,5 @@
1
1
  # @private
2
2
  module Mongoid
3
- # --
4
- # TODO: add ability to index embedded documents (as part of the parent document)
5
- # ++
6
-
7
3
  # A wrapper for slingshot elastic-search adapter for Mongoid
8
4
  module Mebla
9
5
  extend ActiveSupport::Concern
@@ -26,6 +22,7 @@ module Mongoid
26
22
  class_inheritable_accessor :embedded_parent_foreign_key
27
23
  class_inheritable_accessor :slingshot_mappings
28
24
  class_inheritable_accessor :search_fields
25
+ class_inheritable_accessor :search_relations
29
26
  class_inheritable_accessor :whiny_indexing # set to true to raise errors if indexing fails
30
27
 
31
28
  # make sure critical data remain read only
@@ -58,6 +55,40 @@ module Mongoid
58
55
  # search_in :title, :publish_date, :body => { :boost => 2.0, :analyzer => 'snowball' }
59
56
  # end
60
57
  #
58
+ # Defines a search index on a normal document with an index on a field inside a relation::
59
+ #
60
+ # class Document
61
+ # include Mongoid::Document
62
+ # include Mongoid::Mebla
63
+ # field :title
64
+ # field :body
65
+ # field :publish_date, :type => Date
66
+ #
67
+ # referenced_in :blog
68
+ # #...
69
+ # # relations mappings are detected automatically
70
+ # search_in :title, :publish_date, :body => { :boost => 2.0, :analyzer => 'snowball' }, :search_relations => {
71
+ # :blog => [:author, :name]
72
+ # }
73
+ # end
74
+ #
75
+ # Defines a search index on a normal document with an index on method "permalink"::
76
+ #
77
+ # class Document
78
+ # include Mongoid::Document
79
+ # include Mongoid::Mebla
80
+ # field :title
81
+ # field :body
82
+ # field :publish_date, :type => Date
83
+ #
84
+ # def permalink
85
+ # self.title.gsub(/\s/, "-").downcase
86
+ # end
87
+ # #...
88
+ # # methods can also define custom mappings if needed
89
+ # search_in :title, :publish_date, :permalink, :body => { :boost => 2.0, :analyzer => 'snowball' }
90
+ # end
91
+ #
61
92
  # Defines a search index on an embedded document with a single parent and custom mappings on "body"::
62
93
  #
63
94
  # class Document
@@ -88,7 +119,7 @@ module Mongoid
88
119
  # Infer the attributes of the relation
89
120
  self.embedded_parent = relation.class_name.constantize
90
121
  self.embedded_parent_foreign_key = relation.key.to_s
91
- self.embedded_as = relation[:inverse_of] || relation.inverse_setter.to_s.gsub(/=$/, '')
122
+ self.embedded_as = relation[:inverse_of] || relation.inverse_setter.to_s.gsub(/=$/, '')
92
123
 
93
124
  if self.embedded_as.blank?
94
125
  raise ::Mebla::Errors::MeblaConfigurationException.new("Couldn't infer #{embedor.to_s} inverse relation, please set :inverse_of option on the relation.")
@@ -98,6 +129,14 @@ module Mongoid
98
129
  end
99
130
  end
100
131
 
132
+ self.search_relations = {}
133
+ # Keep track of relational indecies
134
+ unless (relations_inedcies = options.delete(:search_relations)).nil?
135
+ relations_inedcies.each do |relation, index|
136
+ self.search_relations[relation] = index
137
+ end
138
+ end
139
+
101
140
  # Keep track of searchable fields (for indexing)
102
141
  self.search_fields = attrs + options.keys
103
142
 
@@ -105,16 +144,34 @@ module Mongoid
105
144
  attrs_mappings = {}
106
145
 
107
146
  attrs.each do |attribute|
108
- unless (field_type = self.fields[attribute.to_s].type.to_s) == "Array" # arrays don't need mappings
109
- attrs_mappings[attribute] = {:type => SLINGSHOT_TYPE_MAPPING[field_type] || "string"}
147
+ unless (attr_field = self.fields[attribute.to_s]).nil?
148
+ unless (field_type = attr_field.type.to_s) == "Array" # arrays don't need mappings
149
+ attrs_mappings[attribute] = {:type => SLINGSHOT_TYPE_MAPPING[field_type] || "string"}
150
+ end
151
+ else
152
+ if self.method_defined?(attribute)
153
+ attrs_mapping[attribute] = {:type => "string"}
154
+ else
155
+ ::Mebla::Errors::MeblaConfigurationException.new("Invalid field #{attribute.to_s} defined for indexing #{self.name}.")
156
+ end
110
157
  end
111
158
  end
112
159
 
113
160
  # Generate advanced indeces' mappings
114
161
  opts_mappings = {}
115
162
 
116
- options.each do |opt, properties|
117
- opts_mappings[opt] = {:type => SLINGSHOT_TYPE_MAPPING[self.fields[opt.to_s].type.to_s] || "string" }.merge!(properties)
163
+ options.each do |opt, properties|
164
+ unless (attr_field = self.fields[opt.to_s]).nil?
165
+ unless (field_type = attr_field.type.to_s) == "Array"
166
+ opts_mappings[opt] = {:type => SLINGSHOT_TYPE_MAPPING[field_type] || "string" }.merge!(properties)
167
+ end
168
+ else
169
+ if self.method_defined?(opt)
170
+ opts_mappings[opt] = {:type => "string"}.merge!(properties)
171
+ else
172
+ ::Mebla::Errors::MeblaConfigurationException.new("Invalid field #{opt.to_s} defined for indexing #{self.name}.")
173
+ end
174
+ end
118
175
  end
119
176
 
120
177
  # Merge mappings
@@ -206,7 +263,37 @@ module Mongoid
206
263
 
207
264
  # Add indexed fields to the hash
208
265
  self.class.search_fields.each do |sfield|
209
- to_index_hash[sfield] = self.attributes[sfield]
266
+ if self.class.fields[sfield.to_s]
267
+ to_index_hash[sfield] = self.attributes[sfield]
268
+ else
269
+ to_index_hash[sfield] = self.send(sfield)
270
+ end
271
+ end
272
+
273
+ # Add indexed relations to the hash
274
+ self.class.search_relations.each do |relation, fields|
275
+ entries = self.send(relation.to_sym)
276
+
277
+ next if entries.nil?
278
+
279
+ if entries.is_a?(Array)
280
+ next if entries.empty?
281
+ to_index_hash[relation] = []
282
+ entries.each do |entry|
283
+ if fields.is_a?(Array)
284
+ to_index_hash[relation] << entry.attributes.reject{|key, value| !fields.include?(key.to_sym)}
285
+ else
286
+ to_index_hash[relation] << { fields => entry.attributes[fields.to_s] }
287
+ end
288
+ end
289
+ else
290
+ to_index_hash[relation] = {}
291
+ if fields.is_a?(Array)
292
+ to_index_hash[relation].merge!(entries.attributes.reject{|key, value| !fields.include?(key.to_sym)})
293
+ else
294
+ to_index_hash[relation].merge!({ fields => entries.attributes[fields.to_s] })
295
+ end
296
+ end
210
297
  end
211
298
 
212
299
  ::Mebla.log("Indexing #{self.class.slingshot_type_name}: #{to_index_hash.to_s}", :debug)
data/mebla.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mebla}
8
- s.version = "1.0.3"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Omar Mekky"]
12
- s.date = %q{2011-03-22}
12
+ s.date = %q{2011-03-23}
13
13
  s.description = %q{
14
14
  An elasticsearch wrapper for mongoid odm based on slingshot. Makes integration between ElasticSearch full-text
15
15
  search engine and Mongoid documents seemless and simple.
@@ -52,7 +52,7 @@ Gem::Specification.new do |s|
52
52
  "spec/fixtures/mongoid.yml",
53
53
  "spec/mebla/indexing_spec.rb",
54
54
  "spec/mebla/searching_spec.rb",
55
- "spec/mebla/synchronization_spec.rb",
55
+ "spec/mebla/synchronizing_spec.rb",
56
56
  "spec/mebla_helper.rb",
57
57
  "spec/mebla_spec.rb",
58
58
  "spec/spec_helper.rb",
@@ -68,7 +68,7 @@ Gem::Specification.new do |s|
68
68
  "spec/fixtures/models.rb",
69
69
  "spec/mebla/indexing_spec.rb",
70
70
  "spec/mebla/searching_spec.rb",
71
- "spec/mebla/synchronization_spec.rb",
71
+ "spec/mebla/synchronizing_spec.rb",
72
72
  "spec/mebla_helper.rb",
73
73
  "spec/mebla_spec.rb",
74
74
  "spec/spec_helper.rb",
@@ -170,6 +170,14 @@ Gem::Specification.new do |s|
170
170
  s.add_development_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
171
171
  s.add_development_dependency(%q<database_cleaner>, ["= 0.6.4"])
172
172
  s.add_development_dependency(%q<bluecloth>, ["~> 2.1.0"])
173
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
174
+ s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
175
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
176
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
177
+ s.add_development_dependency(%q<rcov>, [">= 0"])
178
+ s.add_development_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
179
+ s.add_development_dependency(%q<database_cleaner>, ["= 0.6.4"])
180
+ s.add_development_dependency(%q<bluecloth>, ["~> 2.1.0"])
173
181
  s.add_runtime_dependency(%q<slingshot-rb>, ["~> 0.0.6"])
174
182
  s.add_runtime_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
175
183
  s.add_runtime_dependency(%q<bson>, ["= 1.2.0"])
@@ -273,6 +281,14 @@ Gem::Specification.new do |s|
273
281
  s.add_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
274
282
  s.add_dependency(%q<database_cleaner>, ["= 0.6.4"])
275
283
  s.add_dependency(%q<bluecloth>, ["~> 2.1.0"])
284
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
285
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
286
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
287
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
288
+ s.add_dependency(%q<rcov>, [">= 0"])
289
+ s.add_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
290
+ s.add_dependency(%q<database_cleaner>, ["= 0.6.4"])
291
+ s.add_dependency(%q<bluecloth>, ["~> 2.1.0"])
276
292
  s.add_dependency(%q<slingshot-rb>, ["~> 0.0.6"])
277
293
  s.add_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
278
294
  s.add_dependency(%q<bson>, ["= 1.2.0"])
@@ -377,6 +393,14 @@ Gem::Specification.new do |s|
377
393
  s.add_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
378
394
  s.add_dependency(%q<database_cleaner>, ["= 0.6.4"])
379
395
  s.add_dependency(%q<bluecloth>, ["~> 2.1.0"])
396
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
397
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
398
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
399
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
400
+ s.add_dependency(%q<rcov>, [">= 0"])
401
+ s.add_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
402
+ s.add_dependency(%q<database_cleaner>, ["= 0.6.4"])
403
+ s.add_dependency(%q<bluecloth>, ["~> 2.1.0"])
380
404
  s.add_dependency(%q<slingshot-rb>, ["~> 0.0.6"])
381
405
  s.add_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
382
406
  s.add_dependency(%q<bson>, ["= 1.2.0"])
@@ -8,6 +8,8 @@ class MongoidAlpha
8
8
 
9
9
  self.whiny_indexing = true
10
10
 
11
+ referenced_in :mongoid_epsilon
12
+
11
13
  search_in :name, :cost, :value
12
14
  end
13
15
 
@@ -17,7 +19,7 @@ class MongoidBeta
17
19
  field :name
18
20
 
19
21
  self.whiny_indexing = true
20
-
22
+
21
23
  embeds_many :mongoid_gammas
22
24
 
23
25
  search_in :name => {:boost => 2.0, :analyzer => 'snowball'}
@@ -37,6 +39,8 @@ class MongoidDelta
37
39
  include Mongoid::Document
38
40
  include Mongoid::Mebla
39
41
  field :name
42
+
43
+ self.whiny_indexing = true
40
44
  end
41
45
 
42
46
  class MongoidOmega < MongoidDelta
@@ -63,4 +67,33 @@ class MongoidGamma
63
67
  embedded_in :mongoid_beta
64
68
 
65
69
  search_in :name, :value, :embedded_in => :mongoid_beta
70
+ end
71
+
72
+ class MongoidPi
73
+ include Mongoid::Document
74
+ include Mongoid::Mebla
75
+ field :name
76
+
77
+ self.whiny_indexing = true
78
+
79
+ references_one :mongoid_epsilon
80
+
81
+ search_in :name, :does_smth
82
+
83
+ def does_smth
84
+ "returns smth"
85
+ end
86
+ end
87
+
88
+ class MongoidEpsilon
89
+ include Mongoid::Document
90
+ include Mongoid::Mebla
91
+ field :name
92
+
93
+ self.whiny_indexing = true
94
+
95
+ referenced_in :mongoid_pi
96
+ references_many :mongoid_alphas
97
+
98
+ search_in :name, :search_relations => {:mongoid_pi => :name, :mongoid_alphas => [:name, :value]}
66
99
  end
@@ -46,6 +46,50 @@ describe "Mebla" do
46
46
  end
47
47
  end
48
48
 
49
+ describe "method fields" do
50
+ it "should index method results" do
51
+ Mebla.context.drop_index
52
+
53
+ pi = nil
54
+
55
+ MongoidPi.without_indexing do
56
+ pi = MongoidPi.create! :name => "Document with an indexed method"
57
+ end
58
+
59
+ Mebla.context.index_data
60
+
61
+ lambda {Mebla.context.slingshot_index.retrieve(:mongoid_pi, pi.id.to_s)}.should_not raise_error
62
+ end
63
+ end
64
+
65
+ describe "relational fields" do
66
+ it "should index relational fields" do
67
+ Mebla.context.drop_index
68
+
69
+ pi = nil
70
+
71
+ MongoidPi.without_indexing do
72
+ pi = MongoidPi.create! :name => "A pi"
73
+ end
74
+
75
+ alpha = nil
76
+
77
+ MongoidAlpha.without_indexing do
78
+ alpha = MongoidAlpha.create! :name => "Testing index", :value => 1, :cost => 2.0
79
+ end
80
+
81
+ epsilon = nil
82
+
83
+ MongoidEpsilon.without_indexing do
84
+ epsilon = pi.create_mongoid_epsilon :name => "episilon", :mongoid_alphas => [alpha]
85
+ end
86
+
87
+ Mebla.context.index_data
88
+
89
+ lambda {Mebla.context.slingshot_index.retrieve(:mongoid_epsilon, epsilon.id.to_s)}.should_not raise_error
90
+ end
91
+ end
92
+
49
93
  describe "for sub-classed documents" do
50
94
  it "should index existing records" do
51
95
  Mebla.context.drop_index
@@ -38,6 +38,34 @@ describe "Mebla" do
38
38
  end
39
39
  end
40
40
 
41
+ describe "documents with indexed methods" do
42
+ before(:each) do
43
+ Mebla.context.rebuild_index
44
+ MongoidPi.create! :name => "Document with an indexed method"
45
+ end
46
+
47
+ it "should search within indexed methods" do
48
+ results = MongoidPi.search "returns smth"
49
+
50
+ results.count.should == 1
51
+ end
52
+ end
53
+
54
+ describe "documents with indexed relation fields" do
55
+ before(:each) do
56
+ Mebla.context.rebuild_index
57
+ pi = MongoidPi.create! :name => "A pi"
58
+ alpha = MongoidAlpha.create! :name => "Testing index", :value => 1, :cost => 2.0
59
+ epsilon = pi.create_mongoid_epsilon :name => "episilon", :mongoid_alphas => [alpha]
60
+ end
61
+
62
+ it "should search within indexed fields from the relations" do
63
+ results = MongoidEpsilon.search "Testing index"
64
+
65
+ results.count.should == 1
66
+ end
67
+ end
68
+
41
69
  describe "multiple types" do
42
70
  before(:each) do
43
71
  MongoidBeta.create! :name => "Testing index"
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "Mebla" do
4
- describe "synchronization" do
4
+ describe "synchronizing" do
5
5
  before(:each) do
6
6
  Mebla.context.rebuild_index
7
7
  MongoidAlpha.create! :name => "Testing index", :value => 1, :cost => 2.0
@@ -40,10 +40,54 @@ describe "Mebla" do
40
40
  lambda {Mebla.context.slingshot_index.retrieve(:mongoid_theta, mdocument.id.to_s)}.should_not raise_error
41
41
  end
42
42
 
43
- it "should index fields under sub-classed documents automatically and correctly" do
44
- mdocument = MongoidTheta.first
45
- result = Mebla.context.slingshot_index.retrieve(:mongoid_theta, mdocument.id.to_s)
46
- result.extra.should == "Is this indexed?"
43
+ it "should index sub-classed documents automatically and correctly" do
44
+ pdocument = MongoidTheta.first
45
+ result = Mebla.context.slingshot_index.retrieve(:mongoid_theta, pdocument.id.to_s)
46
+ result[:extra].should == "Is this indexed?"
47
+ end
48
+ end
49
+
50
+ describe "documents with indexed method fields" do
51
+ before(:each) do
52
+ Mebla.context.rebuild_index
53
+ MongoidPi.create! :name => "Testing indexing methods"
54
+ end
55
+
56
+ it "should index method" do
57
+ pdocument = MongoidPi.first
58
+
59
+ lambda {Mebla.context.slingshot_index.retrieve(:mongoid_pi, pdocument.id.to_s)}.should_not raise_error
60
+ end
61
+
62
+ it "should index method fields documents automatically and correctly" do
63
+ pdocument = MongoidPi.first
64
+ result = Mebla.context.slingshot_index.retrieve(:mongoid_pi, pdocument.id.to_s)
65
+ result[:does_smth].should == "returns smth"
66
+ end
67
+ end
68
+
69
+ describe "documents with indexed relation fields" do
70
+ before(:each) do
71
+ Mebla.context.rebuild_index
72
+ pi = MongoidPi.create! :name => "A pi"
73
+ alpha = MongoidAlpha.create! :name => "Testing index", :value => 1, :cost => 2.0
74
+ epsilon = pi.create_mongoid_epsilon :name => "episilon", :mongoid_alphas => [alpha]
75
+ end
76
+
77
+ it "should index documents with indexed fields from the relations" do
78
+ edocument = MongoidEpsilon.first
79
+
80
+ lambda {Mebla.context.slingshot_index.retrieve(:mongoid_epsilon, edocument.id.to_s)}.should_not raise_error
81
+ end
82
+
83
+ it "should index fields from the relations with the document" do
84
+ edocument = MongoidEpsilon.first
85
+
86
+ result = Mebla.context.slingshot_index.retrieve(:mongoid_epsilon, edocument.id.to_s)
87
+ result[:mongoid_pi][:name].should == "A pi"
88
+ result[:mongoid_alphas].is_a?(Array).should == true
89
+ result[:mongoid_alphas].first["name"].should == "Testing index"
90
+ result[:mongoid_alphas].first["value"].should == 1
47
91
  end
48
92
  end
49
93
 
@@ -54,6 +98,13 @@ describe "Mebla" do
54
98
 
55
99
  lambda {Mebla.context.slingshot_index.retrieve(:mongoid_zeta, zdocument.id.to_s)}.should_not raise_error
56
100
  end
101
+
102
+ it "should index array fields and retrieve them correctly" do
103
+ Mebla.context.rebuild_index
104
+ zdocument = MongoidZeta.create :name => "Document with array", :an_array => [:index, :index2, :index2]
105
+
106
+ lambda {Mebla.context.slingshot_index.retrieve(:mongoid_zeta, zdocument.id.to_s)}.should_not raise_error
107
+ end
57
108
  end
58
109
 
59
110
  describe "embedded documents" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mebla
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.3
5
+ version: 1.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Omar Mekky
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-22 00:00:00 +02:00
13
+ date: 2011-03-23 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -1004,8 +1004,96 @@ dependencies:
1004
1004
  prerelease: false
1005
1005
  version_requirements: *id090
1006
1006
  - !ruby/object:Gem::Dependency
1007
- name: slingshot-rb
1007
+ name: rspec
1008
1008
  requirement: &id091 !ruby/object:Gem::Requirement
1009
+ none: false
1010
+ requirements:
1011
+ - - ~>
1012
+ - !ruby/object:Gem::Version
1013
+ version: 2.3.0
1014
+ type: :development
1015
+ prerelease: false
1016
+ version_requirements: *id091
1017
+ - !ruby/object:Gem::Dependency
1018
+ name: yard
1019
+ requirement: &id092 !ruby/object:Gem::Requirement
1020
+ none: false
1021
+ requirements:
1022
+ - - ~>
1023
+ - !ruby/object:Gem::Version
1024
+ version: 0.6.0
1025
+ type: :development
1026
+ prerelease: false
1027
+ version_requirements: *id092
1028
+ - !ruby/object:Gem::Dependency
1029
+ name: bundler
1030
+ requirement: &id093 !ruby/object:Gem::Requirement
1031
+ none: false
1032
+ requirements:
1033
+ - - ~>
1034
+ - !ruby/object:Gem::Version
1035
+ version: 1.0.0
1036
+ type: :development
1037
+ prerelease: false
1038
+ version_requirements: *id093
1039
+ - !ruby/object:Gem::Dependency
1040
+ name: jeweler
1041
+ requirement: &id094 !ruby/object:Gem::Requirement
1042
+ none: false
1043
+ requirements:
1044
+ - - ~>
1045
+ - !ruby/object:Gem::Version
1046
+ version: 1.5.2
1047
+ type: :development
1048
+ prerelease: false
1049
+ version_requirements: *id094
1050
+ - !ruby/object:Gem::Dependency
1051
+ name: rcov
1052
+ requirement: &id095 !ruby/object:Gem::Requirement
1053
+ none: false
1054
+ requirements:
1055
+ - - ">="
1056
+ - !ruby/object:Gem::Version
1057
+ version: "0"
1058
+ type: :development
1059
+ prerelease: false
1060
+ version_requirements: *id095
1061
+ - !ruby/object:Gem::Dependency
1062
+ name: mongoid-rspec
1063
+ requirement: &id096 !ruby/object:Gem::Requirement
1064
+ none: false
1065
+ requirements:
1066
+ - - "="
1067
+ - !ruby/object:Gem::Version
1068
+ version: 1.4.1
1069
+ type: :development
1070
+ prerelease: false
1071
+ version_requirements: *id096
1072
+ - !ruby/object:Gem::Dependency
1073
+ name: database_cleaner
1074
+ requirement: &id097 !ruby/object:Gem::Requirement
1075
+ none: false
1076
+ requirements:
1077
+ - - "="
1078
+ - !ruby/object:Gem::Version
1079
+ version: 0.6.4
1080
+ type: :development
1081
+ prerelease: false
1082
+ version_requirements: *id097
1083
+ - !ruby/object:Gem::Dependency
1084
+ name: bluecloth
1085
+ requirement: &id098 !ruby/object:Gem::Requirement
1086
+ none: false
1087
+ requirements:
1088
+ - - ~>
1089
+ - !ruby/object:Gem::Version
1090
+ version: 2.1.0
1091
+ type: :development
1092
+ prerelease: false
1093
+ version_requirements: *id098
1094
+ - !ruby/object:Gem::Dependency
1095
+ name: slingshot-rb
1096
+ requirement: &id099 !ruby/object:Gem::Requirement
1009
1097
  none: false
1010
1098
  requirements:
1011
1099
  - - ~>
@@ -1013,10 +1101,10 @@ dependencies:
1013
1101
  version: 0.0.6
1014
1102
  type: :runtime
1015
1103
  prerelease: false
1016
- version_requirements: *id091
1104
+ version_requirements: *id099
1017
1105
  - !ruby/object:Gem::Dependency
1018
1106
  name: mongoid
1019
- requirement: &id092 !ruby/object:Gem::Requirement
1107
+ requirement: &id100 !ruby/object:Gem::Requirement
1020
1108
  none: false
1021
1109
  requirements:
1022
1110
  - - "="
@@ -1024,10 +1112,10 @@ dependencies:
1024
1112
  version: 2.0.0.rc.7
1025
1113
  type: :runtime
1026
1114
  prerelease: false
1027
- version_requirements: *id092
1115
+ version_requirements: *id100
1028
1116
  - !ruby/object:Gem::Dependency
1029
1117
  name: bson
1030
- requirement: &id093 !ruby/object:Gem::Requirement
1118
+ requirement: &id101 !ruby/object:Gem::Requirement
1031
1119
  none: false
1032
1120
  requirements:
1033
1121
  - - "="
@@ -1035,10 +1123,10 @@ dependencies:
1035
1123
  version: 1.2.0
1036
1124
  type: :runtime
1037
1125
  prerelease: false
1038
- version_requirements: *id093
1126
+ version_requirements: *id101
1039
1127
  - !ruby/object:Gem::Dependency
1040
1128
  name: bson_ext
1041
- requirement: &id094 !ruby/object:Gem::Requirement
1129
+ requirement: &id102 !ruby/object:Gem::Requirement
1042
1130
  none: false
1043
1131
  requirements:
1044
1132
  - - "="
@@ -1046,10 +1134,10 @@ dependencies:
1046
1134
  version: 1.2.0
1047
1135
  type: :runtime
1048
1136
  prerelease: false
1049
- version_requirements: *id094
1137
+ version_requirements: *id102
1050
1138
  - !ruby/object:Gem::Dependency
1051
1139
  name: rspec
1052
- requirement: &id095 !ruby/object:Gem::Requirement
1140
+ requirement: &id103 !ruby/object:Gem::Requirement
1053
1141
  none: false
1054
1142
  requirements:
1055
1143
  - - ~>
@@ -1057,10 +1145,10 @@ dependencies:
1057
1145
  version: 2.3.0
1058
1146
  type: :development
1059
1147
  prerelease: false
1060
- version_requirements: *id095
1148
+ version_requirements: *id103
1061
1149
  - !ruby/object:Gem::Dependency
1062
1150
  name: yard
1063
- requirement: &id096 !ruby/object:Gem::Requirement
1151
+ requirement: &id104 !ruby/object:Gem::Requirement
1064
1152
  none: false
1065
1153
  requirements:
1066
1154
  - - ~>
@@ -1068,10 +1156,10 @@ dependencies:
1068
1156
  version: 0.6.0
1069
1157
  type: :development
1070
1158
  prerelease: false
1071
- version_requirements: *id096
1159
+ version_requirements: *id104
1072
1160
  - !ruby/object:Gem::Dependency
1073
1161
  name: bundler
1074
- requirement: &id097 !ruby/object:Gem::Requirement
1162
+ requirement: &id105 !ruby/object:Gem::Requirement
1075
1163
  none: false
1076
1164
  requirements:
1077
1165
  - - ~>
@@ -1079,10 +1167,10 @@ dependencies:
1079
1167
  version: 1.0.0
1080
1168
  type: :development
1081
1169
  prerelease: false
1082
- version_requirements: *id097
1170
+ version_requirements: *id105
1083
1171
  - !ruby/object:Gem::Dependency
1084
1172
  name: jeweler
1085
- requirement: &id098 !ruby/object:Gem::Requirement
1173
+ requirement: &id106 !ruby/object:Gem::Requirement
1086
1174
  none: false
1087
1175
  requirements:
1088
1176
  - - ~>
@@ -1090,10 +1178,10 @@ dependencies:
1090
1178
  version: 1.5.2
1091
1179
  type: :development
1092
1180
  prerelease: false
1093
- version_requirements: *id098
1181
+ version_requirements: *id106
1094
1182
  - !ruby/object:Gem::Dependency
1095
1183
  name: rcov
1096
- requirement: &id099 !ruby/object:Gem::Requirement
1184
+ requirement: &id107 !ruby/object:Gem::Requirement
1097
1185
  none: false
1098
1186
  requirements:
1099
1187
  - - ">="
@@ -1101,10 +1189,10 @@ dependencies:
1101
1189
  version: "0"
1102
1190
  type: :development
1103
1191
  prerelease: false
1104
- version_requirements: *id099
1192
+ version_requirements: *id107
1105
1193
  - !ruby/object:Gem::Dependency
1106
1194
  name: mongoid-rspec
1107
- requirement: &id100 !ruby/object:Gem::Requirement
1195
+ requirement: &id108 !ruby/object:Gem::Requirement
1108
1196
  none: false
1109
1197
  requirements:
1110
1198
  - - "="
@@ -1112,10 +1200,10 @@ dependencies:
1112
1200
  version: 1.4.1
1113
1201
  type: :development
1114
1202
  prerelease: false
1115
- version_requirements: *id100
1203
+ version_requirements: *id108
1116
1204
  - !ruby/object:Gem::Dependency
1117
1205
  name: database_cleaner
1118
- requirement: &id101 !ruby/object:Gem::Requirement
1206
+ requirement: &id109 !ruby/object:Gem::Requirement
1119
1207
  none: false
1120
1208
  requirements:
1121
1209
  - - "="
@@ -1123,10 +1211,10 @@ dependencies:
1123
1211
  version: 0.6.4
1124
1212
  type: :development
1125
1213
  prerelease: false
1126
- version_requirements: *id101
1214
+ version_requirements: *id109
1127
1215
  - !ruby/object:Gem::Dependency
1128
1216
  name: bluecloth
1129
- requirement: &id102 !ruby/object:Gem::Requirement
1217
+ requirement: &id110 !ruby/object:Gem::Requirement
1130
1218
  none: false
1131
1219
  requirements:
1132
1220
  - - ~>
@@ -1134,7 +1222,7 @@ dependencies:
1134
1222
  version: 2.1.0
1135
1223
  type: :development
1136
1224
  prerelease: false
1137
- version_requirements: *id102
1225
+ version_requirements: *id110
1138
1226
  description: "\n An elasticsearch wrapper for mongoid odm based on slingshot. Makes integration between ElasticSearch full-text \n search engine and Mongoid documents seemless and simple.\n "
1139
1227
  email: omar.mekky@mashsolvents.com
1140
1228
  executables: []
@@ -1177,7 +1265,7 @@ files:
1177
1265
  - spec/fixtures/mongoid.yml
1178
1266
  - spec/mebla/indexing_spec.rb
1179
1267
  - spec/mebla/searching_spec.rb
1180
- - spec/mebla/synchronization_spec.rb
1268
+ - spec/mebla/synchronizing_spec.rb
1181
1269
  - spec/mebla_helper.rb
1182
1270
  - spec/mebla_spec.rb
1183
1271
  - spec/spec_helper.rb
@@ -1197,7 +1285,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
1197
1285
  requirements:
1198
1286
  - - ">="
1199
1287
  - !ruby/object:Gem::Version
1200
- hash: -929217804110582376
1288
+ hash: 164723235165281769
1201
1289
  segments:
1202
1290
  - 0
1203
1291
  version: "0"
@@ -1218,7 +1306,7 @@ test_files:
1218
1306
  - spec/fixtures/models.rb
1219
1307
  - spec/mebla/indexing_spec.rb
1220
1308
  - spec/mebla/searching_spec.rb
1221
- - spec/mebla/synchronization_spec.rb
1309
+ - spec/mebla/synchronizing_spec.rb
1222
1310
  - spec/mebla_helper.rb
1223
1311
  - spec/mebla_spec.rb
1224
1312
  - spec/spec_helper.rb