mebla 1.0.0.rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,85 @@
1
+ # @private
2
+ module Mebla
3
+ # Represents a set of search results
4
+ class ResultSet
5
+ include Enumerable
6
+ attr_reader :entries, :facets, :time, :total
7
+
8
+ # --
9
+ # OPTIMIZE: needs major refractoring
10
+ # ++
11
+
12
+ # Creates a new result set from an elasticsearch response hash
13
+ # @param response
14
+ def initialize(response)
15
+ # Keep the query time
16
+ @time = response['took']
17
+ # Keep the facets
18
+ @facets = response['facets']
19
+ # Keep the query total to check against the count
20
+ @total = response['hits']['total']
21
+
22
+ # Be efficient only query the database once
23
+ model_ids = {}
24
+
25
+ # Collect results' ids
26
+ response['hits']['hits'].each do |hit|
27
+ model_class = hit['_type'].camelize.constantize
28
+
29
+ if model_class.embedded?
30
+ unless model_ids[model_class]
31
+ model_ids[model_class] = {}
32
+ end
33
+ # collect parent ids
34
+ # {class => {parent_id => [ids]}}
35
+ parent_id = hit['_source']['_parent']
36
+
37
+ unless model_ids[model_class][parent_id]
38
+ model_ids[model_class][parent_id] = []
39
+ end
40
+
41
+ model_ids[model_class][parent_id].push hit['_source']['id']
42
+ else
43
+ unless model_ids[model_class]
44
+ model_ids[model_class] = []
45
+ end
46
+ # collect ids
47
+ # {class => [ids]}
48
+ model_ids[model_class].push hit['_source']['id']
49
+ end
50
+ end
51
+
52
+ # Cast the results into their appropriate classes
53
+ @entries = []
54
+
55
+ model_ids.each do |model_class, ids|
56
+ unless model_class.embedded?
57
+ # Retrieve the results from the database
58
+ @entries += model_class.any_in(:_id => ids).entries
59
+ else
60
+ # Get the parent
61
+ parent_class = model_class.embedded_parent
62
+ access_method = model_class.embedded_as
63
+
64
+ parent = parent_class.find ids.keys.first
65
+
66
+ # Retrieve the results from the database
67
+ @entries += parent.send(access_method.to_sym).any_in(:_id => ids.values.first).entries
68
+ end
69
+ end
70
+
71
+ Mebla.log("WARNING: Index not synchronized with the database; index total hits: #{@total}, retrieved documents: #{self.count}", :warn) if @total != self.count
72
+ end
73
+
74
+ # Iterates over the collection
75
+ def each(&block)
76
+ @entries.each(&block)
77
+ end
78
+
79
+ # Returns the item with the given index
80
+ # @param [Integer] index
81
+ def [](index)
82
+ @entries[index]
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,42 @@
1
+ Mebla.cofigure do |config|
2
+ config.logger = Logger.new(STDOUT)
3
+ config.setup_logger
4
+ end
5
+
6
+ namespace :mebla do
7
+ desc "Creates the indeces and indexes the data for all indexed models"
8
+ task :index => :environment do
9
+ context = Mebla.context
10
+ context.index_data
11
+ end
12
+
13
+ desc "Drops then creates the indeces and indexes the data for all indexed models"
14
+ task :reindex => :environment do
15
+ context = Mebla.context
16
+ context.reindex_data
17
+ end
18
+
19
+ desc "Creates the index without indexing the data"
20
+ task :create_index => :environment do
21
+ context = Mebla.context
22
+ context.create_index
23
+ end
24
+
25
+ desc "Rebuilds the index without indexing the data"
26
+ task :rebuild_index => :environment do
27
+ context = Mebla.context
28
+ context.rebuild_index
29
+ end
30
+
31
+ desc "Drops the index"
32
+ task :drop_index => :environment do
33
+ context = Mebla.context
34
+ context.drop_index
35
+ end
36
+
37
+ desc "Refreshes the index"
38
+ task :refresh_index => :environment do
39
+ context = Mebla.context
40
+ context.refresh_index
41
+ end
42
+ end
data/lib/mebla.rb ADDED
@@ -0,0 +1,137 @@
1
+ require 'active_support'
2
+
3
+ # @private
4
+ module Mebla
5
+ extend ActiveSupport::Autoload
6
+
7
+ # Dependencies
8
+ autoload :Mongoid, 'mongoid'
9
+ autoload :Slingshot, 'slingshot'
10
+ # Main modules
11
+ autoload :Configuration
12
+ autoload :Context
13
+ autoload :LogSubscriber
14
+ autoload :ResultSet
15
+ # Errors
16
+ autoload :Errors
17
+ # Mongoid extensions
18
+ autoload :Mebla, 'mebla/mongoid/mebla'
19
+
20
+ @@mebla_mutex = Mutex.new
21
+ @@context = nil
22
+
23
+ # Returns Mebla's context for minipulating the index
24
+ # @return [nil]
25
+ def self.context
26
+ if @@context.nil?
27
+ @@mebla_mutex.synchronize do
28
+ if @@context.nil?
29
+ @@context = Mebla::Context.new
30
+ end
31
+ end
32
+ end
33
+
34
+ @@context
35
+ end
36
+
37
+ # Resets the context (reloads Mebla)
38
+ # @return [nil]
39
+ def self.reset_context!
40
+ @@mebla_mutex.synchronize do
41
+ @@context = nil
42
+ end
43
+ end
44
+
45
+ # Check if mongoid is loaded
46
+ # @return [Boolean]
47
+ def self.mongoid?
48
+ !defined?(Mongoid).nil?
49
+ end
50
+
51
+ # Check if slingshot is loaded
52
+ # @return [Boolean]
53
+ def self.slingshot?
54
+ !defined?(Slingshot).nil?
55
+ end
56
+
57
+ # Check if elasticsearch is running
58
+ # @return [Boolean]
59
+ def self.elasticsearch?
60
+ result = Slingshot::Configuration.client.get "#{Slingshot::Configuration.url}/_status"
61
+ return (result =~ /error/) ? false: true
62
+ rescue RestClient::Exception
63
+ false
64
+ end
65
+
66
+ # Configure Mebla
67
+ #
68
+ # Example::
69
+ #
70
+ # Mebla.configure do |config|
71
+ # index = "mebla_index"
72
+ # host = "localhost"
73
+ # port = 9200
74
+ # end
75
+ def self.configure(&block)
76
+ yield Mebla::Configuration.instance
77
+ end
78
+
79
+
80
+ # Writes out a message to the log file according to the level given
81
+ # @note If no level is given a message of type Logger::UNKOWN will be written to the log file
82
+ # @param [String] message
83
+ # @param [Symbol] level can be :debug, :warn or :info
84
+ # @return [nil]
85
+ def self.log(message, level = :none)
86
+ case level
87
+ when :debug
88
+ hook = "mebla_debug.mebla"
89
+ when :warn
90
+ hook = "mebla_warn.mebla"
91
+ when :info
92
+ hook = "mebla_info.mebla"
93
+ else
94
+ hook = "mebla_unkown.mebla"
95
+ end
96
+
97
+ ::ActiveSupport::Notifications.
98
+ instrument(hook, :message => message)
99
+ end
100
+
101
+ # Search the index using Slingshot search DSL
102
+ # @param type_names a string, symbol or array representing the models to be searcheds
103
+ # @return [ResultSet]
104
+ #
105
+ # Search for all documents with a field title with a value 'Testing Search'::
106
+ #
107
+ # Mebla.search do
108
+ # query do
109
+ # string "title: Testing Search"
110
+ # end
111
+ # end
112
+ #
113
+ # @note For more information about Slingshot search DSL, check http://karmi.github.com/slingshot
114
+ def self.search(type_names = [], &block)
115
+ # Convert type names from string or symbol to array
116
+ type_names = case true
117
+ when type_names.is_a?(Symbol), type_names.is_a?(String)
118
+ [type_names]
119
+ when type_names.is_a?(Array)
120
+ type_names.collect{|name| name.to_s}
121
+ else
122
+ []
123
+ end
124
+ # Create slingshot search object
125
+ search_obj = Slingshot::Search::Search.new(::Mebla.context.slingshot_index_name, {}, &block)
126
+ # Add a type filter to return only certain types
127
+ search_obj = search_obj.filter(:terms, :_type => type_names) unless type_names.empty?
128
+ # Log search query
129
+ log("Searching:\n#{search_obj.to_json.to_s}", :debug)
130
+ # Perform the search and parse the response
131
+ results = Mebla::ResultSet.new(search_obj.perform.response)
132
+ # Log results statistics
133
+ log("Searched for:\n#{search_obj.to_json.to_s}\ngot #{results.total} in #{results.time}", :debug)
134
+ # Return the results
135
+ return results
136
+ end
137
+ end
data/mebla.gemspec ADDED
@@ -0,0 +1,248 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{mebla}
8
+ s.version = "1.0.0.rc2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Omar Mekky"]
12
+ s.date = %q{2011-03-16}
13
+ s.description = %q{
14
+ An elasticsearch wrapper for mongoid odm based on slingshot. Makes integration between ElasticSearch full-text
15
+ search engine and Mongoid documents seemless and simple.
16
+ }
17
+ s.email = %q{omar.mekky@mashsolvents.com}
18
+ s.extra_rdoc_files = [
19
+ "LICENSE.txt",
20
+ "README.md"
21
+ ]
22
+ s.files = [
23
+ ".document",
24
+ ".rspec",
25
+ "Gemfile",
26
+ "Gemfile.lock",
27
+ "LICENSE.txt",
28
+ "README.md",
29
+ "Rakefile",
30
+ "TODO.md",
31
+ "VERSION",
32
+ "lib/generators/mebla/install/USAGE",
33
+ "lib/generators/mebla/install/install_generator.rb",
34
+ "lib/generators/mebla/install/templates/mebla.yml",
35
+ "lib/mebla.rb",
36
+ "lib/mebla/configuration.rb",
37
+ "lib/mebla/context.rb",
38
+ "lib/mebla/errors/mebla_configuration_exception.rb",
39
+ "lib/mebla/errors/mebla_error.rb",
40
+ "lib/mebla/errors/mebla_fatal.rb",
41
+ "lib/mebla/errors/mebla_index_exception.rb",
42
+ "lib/mebla/errors/mebla_synchronization_exception.rb",
43
+ "lib/mebla/log_subscriber.rb",
44
+ "lib/mebla/mongoid/mebla.rb",
45
+ "lib/mebla/railtie.rb",
46
+ "lib/mebla/result_set.rb",
47
+ "lib/mebla/tasks.rb",
48
+ "mebla.gemspec",
49
+ "spec/fixtures/models.rb",
50
+ "spec/fixtures/mongoid.yml",
51
+ "spec/mebla/indexing_spec.rb",
52
+ "spec/mebla/searching_spec.rb",
53
+ "spec/mebla/synchronization_spec.rb",
54
+ "spec/mebla_helper.rb",
55
+ "spec/mebla_spec.rb",
56
+ "spec/spec_helper.rb",
57
+ "spec/support/mongoid.rb",
58
+ "spec/support/rails.rb"
59
+ ]
60
+ s.homepage = %q{http://github.com/cousine/mebla}
61
+ s.licenses = ["MIT"]
62
+ s.require_paths = ["lib"]
63
+ s.rubygems_version = %q{1.6.1}
64
+ s.summary = %q{An elasticsearch wrapper for mongoid odm based on slingshot.}
65
+ s.test_files = [
66
+ "spec/fixtures/models.rb",
67
+ "spec/mebla/indexing_spec.rb",
68
+ "spec/mebla/searching_spec.rb",
69
+ "spec/mebla/synchronization_spec.rb",
70
+ "spec/mebla_helper.rb",
71
+ "spec/mebla_spec.rb",
72
+ "spec/spec_helper.rb",
73
+ "spec/support/mongoid.rb",
74
+ "spec/support/rails.rb"
75
+ ]
76
+
77
+ if s.respond_to? :specification_version then
78
+ s.specification_version = 3
79
+
80
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
81
+ s.add_runtime_dependency(%q<mebla>, [">= 0"])
82
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
83
+ s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
84
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
85
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
86
+ s.add_development_dependency(%q<rcov>, [">= 0"])
87
+ s.add_development_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
88
+ s.add_development_dependency(%q<bson>, ["= 1.2.0"])
89
+ s.add_development_dependency(%q<bson_ext>, ["= 1.2.0"])
90
+ s.add_development_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
91
+ s.add_development_dependency(%q<database_cleaner>, ["= 0.6.4"])
92
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
93
+ s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
94
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
95
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
96
+ s.add_development_dependency(%q<rcov>, [">= 0"])
97
+ s.add_development_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
98
+ s.add_development_dependency(%q<database_cleaner>, ["= 0.6.4"])
99
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
100
+ s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
101
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
102
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
103
+ s.add_development_dependency(%q<rcov>, [">= 0"])
104
+ s.add_development_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
105
+ s.add_development_dependency(%q<database_cleaner>, ["= 0.6.4"])
106
+ s.add_development_dependency(%q<bluecloth>, ["~> 2.1.0"])
107
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
108
+ s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
109
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
110
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
111
+ s.add_development_dependency(%q<rcov>, [">= 0"])
112
+ s.add_development_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
113
+ s.add_development_dependency(%q<database_cleaner>, ["= 0.6.4"])
114
+ s.add_development_dependency(%q<bluecloth>, ["~> 2.1.0"])
115
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
116
+ s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
117
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
118
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
119
+ s.add_development_dependency(%q<rcov>, [">= 0"])
120
+ s.add_development_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
121
+ s.add_development_dependency(%q<database_cleaner>, ["= 0.6.4"])
122
+ s.add_development_dependency(%q<bluecloth>, ["~> 2.1.0"])
123
+ s.add_runtime_dependency(%q<slingshot-rb>, ["~> 0.0.6"])
124
+ s.add_runtime_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
125
+ s.add_runtime_dependency(%q<bson>, ["= 1.2.0"])
126
+ s.add_runtime_dependency(%q<bson_ext>, ["= 1.2.0"])
127
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
128
+ s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
129
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
130
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
131
+ s.add_development_dependency(%q<rcov>, [">= 0"])
132
+ s.add_development_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
133
+ s.add_development_dependency(%q<database_cleaner>, ["= 0.6.4"])
134
+ s.add_development_dependency(%q<bluecloth>, ["~> 2.1.0"])
135
+ else
136
+ s.add_dependency(%q<mebla>, [">= 0"])
137
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
138
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
139
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
140
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
141
+ s.add_dependency(%q<rcov>, [">= 0"])
142
+ s.add_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
143
+ s.add_dependency(%q<bson>, ["= 1.2.0"])
144
+ s.add_dependency(%q<bson_ext>, ["= 1.2.0"])
145
+ s.add_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
146
+ s.add_dependency(%q<database_cleaner>, ["= 0.6.4"])
147
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
148
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
149
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
150
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
151
+ s.add_dependency(%q<rcov>, [">= 0"])
152
+ s.add_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
153
+ s.add_dependency(%q<database_cleaner>, ["= 0.6.4"])
154
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
155
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
156
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
157
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
158
+ s.add_dependency(%q<rcov>, [">= 0"])
159
+ s.add_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
160
+ s.add_dependency(%q<database_cleaner>, ["= 0.6.4"])
161
+ s.add_dependency(%q<bluecloth>, ["~> 2.1.0"])
162
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
163
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
164
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
165
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
166
+ s.add_dependency(%q<rcov>, [">= 0"])
167
+ s.add_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
168
+ s.add_dependency(%q<database_cleaner>, ["= 0.6.4"])
169
+ s.add_dependency(%q<bluecloth>, ["~> 2.1.0"])
170
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
171
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
172
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
173
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
174
+ s.add_dependency(%q<rcov>, [">= 0"])
175
+ s.add_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
176
+ s.add_dependency(%q<database_cleaner>, ["= 0.6.4"])
177
+ s.add_dependency(%q<bluecloth>, ["~> 2.1.0"])
178
+ s.add_dependency(%q<slingshot-rb>, ["~> 0.0.6"])
179
+ s.add_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
180
+ s.add_dependency(%q<bson>, ["= 1.2.0"])
181
+ s.add_dependency(%q<bson_ext>, ["= 1.2.0"])
182
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
183
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
184
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
185
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
186
+ s.add_dependency(%q<rcov>, [">= 0"])
187
+ s.add_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
188
+ s.add_dependency(%q<database_cleaner>, ["= 0.6.4"])
189
+ s.add_dependency(%q<bluecloth>, ["~> 2.1.0"])
190
+ end
191
+ else
192
+ s.add_dependency(%q<mebla>, [">= 0"])
193
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
194
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
195
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
196
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
197
+ s.add_dependency(%q<rcov>, [">= 0"])
198
+ s.add_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
199
+ s.add_dependency(%q<bson>, ["= 1.2.0"])
200
+ s.add_dependency(%q<bson_ext>, ["= 1.2.0"])
201
+ s.add_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
202
+ s.add_dependency(%q<database_cleaner>, ["= 0.6.4"])
203
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
204
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
205
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
206
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
207
+ s.add_dependency(%q<rcov>, [">= 0"])
208
+ s.add_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
209
+ s.add_dependency(%q<database_cleaner>, ["= 0.6.4"])
210
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
211
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
212
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
213
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
214
+ s.add_dependency(%q<rcov>, [">= 0"])
215
+ s.add_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
216
+ s.add_dependency(%q<database_cleaner>, ["= 0.6.4"])
217
+ s.add_dependency(%q<bluecloth>, ["~> 2.1.0"])
218
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
219
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
220
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
221
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
222
+ s.add_dependency(%q<rcov>, [">= 0"])
223
+ s.add_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
224
+ s.add_dependency(%q<database_cleaner>, ["= 0.6.4"])
225
+ s.add_dependency(%q<bluecloth>, ["~> 2.1.0"])
226
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
227
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
228
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
229
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
230
+ s.add_dependency(%q<rcov>, [">= 0"])
231
+ s.add_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
232
+ s.add_dependency(%q<database_cleaner>, ["= 0.6.4"])
233
+ s.add_dependency(%q<bluecloth>, ["~> 2.1.0"])
234
+ s.add_dependency(%q<slingshot-rb>, ["~> 0.0.6"])
235
+ s.add_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
236
+ s.add_dependency(%q<bson>, ["= 1.2.0"])
237
+ s.add_dependency(%q<bson_ext>, ["= 1.2.0"])
238
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
239
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
240
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
241
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
242
+ s.add_dependency(%q<rcov>, [">= 0"])
243
+ s.add_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
244
+ s.add_dependency(%q<database_cleaner>, ["= 0.6.4"])
245
+ s.add_dependency(%q<bluecloth>, ["~> 2.1.0"])
246
+ end
247
+ end
248
+
@@ -0,0 +1,37 @@
1
+ class MongoidAlpha
2
+ include Mongoid::Document
3
+ include Mongoid::Mebla
4
+ field :name
5
+ field :value, :type => Integer
6
+ field :cost, :type => Float
7
+ field :hidden
8
+
9
+ self.whiny_indexing = true
10
+
11
+ search_in :name, :cost, :value
12
+ end
13
+
14
+ class MongoidBeta
15
+ include Mongoid::Document
16
+ include Mongoid::Mebla
17
+ field :name
18
+
19
+ self.whiny_indexing = true
20
+
21
+ embeds_many :mongoid_gammas
22
+
23
+ search_in :name => {:boost => 2.0, :analyzer => 'snowball'}
24
+ end
25
+
26
+ class MongoidGamma
27
+ include Mongoid::Document
28
+ include Mongoid::Mebla
29
+ field :name
30
+ field :value, :type => Integer
31
+
32
+ self.whiny_indexing = true
33
+
34
+ embedded_in :mongoid_beta
35
+
36
+ search_in :name, :embedded_in => :mongoid_beta
37
+ end
@@ -0,0 +1,3 @@
1
+ username: ''
2
+ password: ''
3
+ host: localhost
@@ -0,0 +1,63 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Mebla" do
4
+ describe "indexing" do
5
+ it "should index existing records" do
6
+ Mebla.context.drop_index
7
+
8
+ fdocument = nil
9
+ ldocument = nil
10
+
11
+ MongoidAlpha.without_indexing do
12
+ fdocument = MongoidAlpha.create! :name => "Testing indexing bulkly", :value => 1, :cost => 1.0
13
+ ldocument = MongoidAlpha.create! :name => "Testing indexing bulkly other one", :value => 2, :cost => 2.0
14
+ end
15
+
16
+ Mebla.context.index_data
17
+
18
+ lambda {Mebla.context.slingshot_index.retrieve(:mongoid_alpha, fdocument.id.to_s)}.should_not raise_error
19
+ lambda {Mebla.context.slingshot_index.retrieve(:mongoid_alpha, ldocument.id.to_s)}.should_not raise_error
20
+ end
21
+
22
+ it "should delete the existing index and create a new one" do
23
+ Mebla.context.rebuild_index.should_not == false
24
+ end
25
+
26
+ it "should create the index with proper mapping" do
27
+ maps = Mebla.context.slingshot_index.mapping["mongoid_alpha"]["properties"]
28
+ maps["name"]["type"].should == "string"
29
+ maps["value"]["type"].should == "integer"
30
+ maps["cost"]["type"].should == "float"
31
+ end
32
+
33
+ describe "embedded documents" do
34
+ it "should index existing records" do
35
+ Mebla.context.drop_index
36
+
37
+ beta = nil
38
+ gamma = nil
39
+
40
+ MongoidBeta.without_indexing do
41
+ beta = MongoidBeta.create! :name => "Embedor parent"
42
+ MongoidGamma.without_indexing do
43
+ gamma = beta.mongoid_gammas.create :name => "Embedded", :value => 1
44
+ end
45
+ end
46
+
47
+ Mebla.context.index_data
48
+
49
+ lambda {
50
+ Slingshot::Configuration.client.get "#{Mebla::Configuration.instance.url}/#{Mebla.context.slingshot_index_name}/mongoid_gamma/#{gamma.id.to_s}?routing=#{beta.id.to_s}"
51
+ }.should_not raise_error
52
+ end
53
+
54
+ it "should create the index with proper parent mapping" do
55
+ mappings = Mebla.context.slingshot_index.mapping["mongoid_gamma"]
56
+ routing = mappings["_routing"]
57
+ parent = mappings["_parent"]
58
+ routing["path"].should == "mongoid_beta_id"
59
+ parent["type"].should == "mongoid_beta"
60
+ end
61
+ end
62
+ end
63
+ end