rails-ext 0.3.11 → 0.3.12
Sign up to get free protection for your applications and to get access to all the features.
- data/.git/COMMIT_EDITMSG +1 -1
- data/.git/index +0 -0
- data/.git/logs/HEAD +1 -0
- data/.git/logs/refs/heads/master +1 -0
- data/.git/logs/refs/remotes/origin/master +1 -0
- data/.git/objects/0b/1a882513f514fe05177cc54f4480141b195956 +0 -0
- data/.git/objects/0b/b62f25b6636b2ce32ebd4551120f5765b787e1 +0 -0
- data/.git/objects/2f/af7acb8454f4b248d928b9a92f09571302a174 +0 -0
- data/.git/objects/7b/469d63569dcc92c82f90fc7a48793c31365f9a +0 -0
- data/.git/objects/90/a3187c0cfd6ae0de236633da361820a4cf1b19 +0 -0
- data/.git/objects/92/debcedcd81c328806dc7506b3cd91990bb9775 +0 -0
- data/.git/objects/e5/18de391d5b9dee87ec6f749900785f3b24dad0 +1 -0
- data/.git/objects/f7/be86378738705bbd1f97dd8be92c3cc7d54a66 +0 -0
- data/.git/refs/heads/master +1 -1
- data/.git/refs/remotes/origin/master +1 -1
- data/Rakefile +1 -1
- data/lib/sunspot/mongo_mapper/adapters.rb +79 -0
- data/lib/sunspot/mongo_mapper/searchable.rb +412 -0
- metadata +13 -3
data/.git/COMMIT_EDITMSG
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
add solr sunspot search
|
data/.git/index
CHANGED
Binary file
|
data/.git/logs/HEAD
CHANGED
@@ -62,3 +62,4 @@ a3ece30fb5827ed20d26a75253bb4854f657055a 0538f41ddebf7fa8c71ebe99c5288d5e11c3fb8
|
|
62
62
|
b4343d9284a89e2971022f8d4acf7865d8341c6d 824ac01aecaa766ea8a7b10ef9d9f67810fdff40 alex <alex@amac.local> 1270516451 +0400 commit: upd
|
63
63
|
824ac01aecaa766ea8a7b10ef9d9f67810fdff40 83b834761b24c759d71e6fb8121dcf127290454e alex <alex@amac.local> 1270519846 +0400 commit: upd
|
64
64
|
83b834761b24c759d71e6fb8121dcf127290454e bc8c233044e9ab4299af036c0602bab06d3a5349 alex <alex@amac.local> 1271850978 +0400 commit: upd
|
65
|
+
bc8c233044e9ab4299af036c0602bab06d3a5349 f7be86378738705bbd1f97dd8be92c3cc7d54a66 alex <alex@amac.local> 1271938860 +0400 commit: add solr sunspot search
|
data/.git/logs/refs/heads/master
CHANGED
@@ -62,3 +62,4 @@ a3ece30fb5827ed20d26a75253bb4854f657055a 0538f41ddebf7fa8c71ebe99c5288d5e11c3fb8
|
|
62
62
|
b4343d9284a89e2971022f8d4acf7865d8341c6d 824ac01aecaa766ea8a7b10ef9d9f67810fdff40 alex <alex@amac.local> 1270516451 +0400 commit: upd
|
63
63
|
824ac01aecaa766ea8a7b10ef9d9f67810fdff40 83b834761b24c759d71e6fb8121dcf127290454e alex <alex@amac.local> 1270519846 +0400 commit: upd
|
64
64
|
83b834761b24c759d71e6fb8121dcf127290454e bc8c233044e9ab4299af036c0602bab06d3a5349 alex <alex@amac.local> 1271850978 +0400 commit: upd
|
65
|
+
bc8c233044e9ab4299af036c0602bab06d3a5349 f7be86378738705bbd1f97dd8be92c3cc7d54a66 alex <alex@amac.local> 1271938860 +0400 commit: add solr sunspot search
|
@@ -48,3 +48,4 @@ a3ece30fb5827ed20d26a75253bb4854f657055a 0538f41ddebf7fa8c71ebe99c5288d5e11c3fb8
|
|
48
48
|
b4343d9284a89e2971022f8d4acf7865d8341c6d 824ac01aecaa766ea8a7b10ef9d9f67810fdff40 alex <alex@amac.local> 1270516459 +0400 update by push
|
49
49
|
824ac01aecaa766ea8a7b10ef9d9f67810fdff40 83b834761b24c759d71e6fb8121dcf127290454e alex <alex@amac.local> 1270519856 +0400 update by push
|
50
50
|
83b834761b24c759d71e6fb8121dcf127290454e bc8c233044e9ab4299af036c0602bab06d3a5349 alex <alex@amac.local> 1271850990 +0400 update by push
|
51
|
+
bc8c233044e9ab4299af036c0602bab06d3a5349 f7be86378738705bbd1f97dd8be92c3cc7d54a66 alex <alex@amac.local> 1271938911 +0400 update by push
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
x+)JMU�0`040031QHLI,(I-*�+Jb���P�*�U�樿K���ddTYqjbQrFbRN*H�{{ޞm<�ѐ{< �����K���
|
Binary file
|
data/.git/refs/heads/master
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
f7be86378738705bbd1f97dd8be92c3cc7d54a66
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
f7be86378738705bbd1f97dd8be92c3cc7d54a66
|
data/Rakefile
CHANGED
@@ -18,7 +18,7 @@ require 'fileutils'
|
|
18
18
|
|
19
19
|
spec = Gem::Specification.new do |s|
|
20
20
|
s.name = "rails-ext"
|
21
|
-
s.version = "0.3.
|
21
|
+
s.version = "0.3.12"
|
22
22
|
s.summary = "Set of common Ruby on Rails extensions"
|
23
23
|
s.description = "Set of common Ruby on Rails extensions"
|
24
24
|
s.author = "Alexey Petrushin"
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Sunspot #:nodoc:
|
2
|
+
module MongoMapper #:nodoc:
|
3
|
+
#
|
4
|
+
# This module provides Sunspot Adapter implementations for MongoMapper
|
5
|
+
# models.
|
6
|
+
#
|
7
|
+
module Adapters
|
8
|
+
class MongoMapperInstanceAdapter < Sunspot::Adapters::InstanceAdapter
|
9
|
+
#
|
10
|
+
# Return the primary key for the adapted instance
|
11
|
+
#
|
12
|
+
# ==== Returns
|
13
|
+
#
|
14
|
+
# Integer:: Database ID of model
|
15
|
+
#
|
16
|
+
def id
|
17
|
+
@instance.id
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class MongoMapperDataAccessor < Sunspot::Adapters::DataAccessor
|
22
|
+
# options for the find
|
23
|
+
attr_accessor :include, :select
|
24
|
+
|
25
|
+
#
|
26
|
+
# Set the fields to select from the database. This will be passed
|
27
|
+
# to MongoMapper.
|
28
|
+
#
|
29
|
+
# ==== Parameters
|
30
|
+
#
|
31
|
+
# value<Mixed>:: String of comma-separated columns or array of columns
|
32
|
+
#
|
33
|
+
def select=(value)
|
34
|
+
value = value.join(', ') if value.respond_to?(:join)
|
35
|
+
@select = value
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Get one MongoMapper instance out of the database by ID
|
40
|
+
#
|
41
|
+
# ==== Parameters
|
42
|
+
#
|
43
|
+
# id<String>:: Database ID of model to retreive
|
44
|
+
#
|
45
|
+
# ==== Returns
|
46
|
+
#
|
47
|
+
# MongoMapper::Base:: MongoMapper model
|
48
|
+
#
|
49
|
+
def load(id)
|
50
|
+
@clazz.first(options_for_find.merge(:id => id))
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# Get a collection of MongoMapper instances out of the database by ID
|
55
|
+
#
|
56
|
+
# ==== Parameters
|
57
|
+
#
|
58
|
+
# ids<Array>:: Database IDs of models to retrieve
|
59
|
+
#
|
60
|
+
# ==== Returns
|
61
|
+
#
|
62
|
+
# Array:: Collection of MongoMapper models
|
63
|
+
#
|
64
|
+
def load_all(ids)
|
65
|
+
@clazz.all(options_for_find.merge(:id => ids))
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def options_for_find
|
71
|
+
returning({}) do |options|
|
72
|
+
options[:include] = @include unless @include.blank?
|
73
|
+
options[:select] = @select unless @select.blank?
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,412 @@
|
|
1
|
+
module Sunspot #:nodoc:
|
2
|
+
module MongoMapper #:nodoc:
|
3
|
+
#
|
4
|
+
# This module adds Sunspot functionality to MongoMapper models. As well as
|
5
|
+
# providing class and instance methods, it optionally adds lifecycle hooks
|
6
|
+
# to automatically add and remove models from the Solr index as they are
|
7
|
+
# created and destroyed.
|
8
|
+
#
|
9
|
+
module Searchable
|
10
|
+
class <<self
|
11
|
+
def included(base) #:nodoc:
|
12
|
+
base.module_eval do
|
13
|
+
extend(ActsAsMethods)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module ActsAsMethods
|
19
|
+
#
|
20
|
+
# Makes a class searchable if it is not already, or adds search
|
21
|
+
# configuration if it is. Note that the options passed in are only used
|
22
|
+
# the first time this method is called for a particular class; so,
|
23
|
+
# search should be defined before activating any mixins that extend
|
24
|
+
# search configuration.
|
25
|
+
#
|
26
|
+
# The block passed into this method is evaluated by the
|
27
|
+
# <code>Sunspot.setup</code> method. See the Sunspot documentation for
|
28
|
+
# complete information on the functionality provided by that method.
|
29
|
+
#
|
30
|
+
# ==== Options (+options+)
|
31
|
+
#
|
32
|
+
# :auto_index<Boolean>::
|
33
|
+
# Automatically index models in Solr when they are saved.
|
34
|
+
# Default: true
|
35
|
+
# :auto_remove<Boolean>::
|
36
|
+
# Automatically remove models from the Solr index when they are
|
37
|
+
# destroyed. <b>Setting this option to +false+ is not recommended
|
38
|
+
# </b>(see the README).
|
39
|
+
# :ignore_attribute_changes_of<Array>::
|
40
|
+
# Define attributes, that should not trigger a reindex of that
|
41
|
+
# object. Usual suspects are updated_at or counters.
|
42
|
+
# :include<Mixed>::
|
43
|
+
# Define default MongoMapper includes, set this to allow MongoMapper
|
44
|
+
# to load required associations when indexing. See MongoMapper's
|
45
|
+
# documentation on eager-loading for examples on how to set this
|
46
|
+
# Default: []
|
47
|
+
#
|
48
|
+
# ==== Example
|
49
|
+
#
|
50
|
+
# class Post < MongoMapper::Base
|
51
|
+
# searchable do
|
52
|
+
# text :title, :body
|
53
|
+
# string :sort_title do
|
54
|
+
# title.downcase.sub(/^(an?|the)/, '')
|
55
|
+
# end
|
56
|
+
# integer :blog_id
|
57
|
+
# time :updated_at
|
58
|
+
# end
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
def searchable(options = {}, &block)
|
62
|
+
Sunspot.setup(self, &block)
|
63
|
+
|
64
|
+
if searchable?
|
65
|
+
sunspot_options[:include].concat(Util::Array(options[:include]))
|
66
|
+
else
|
67
|
+
extend ClassMethods
|
68
|
+
include InstanceMethods
|
69
|
+
|
70
|
+
class_inheritable_hash :sunspot_options
|
71
|
+
|
72
|
+
unless options[:auto_index] == false
|
73
|
+
before_save :maybe_mark_for_auto_indexing
|
74
|
+
after_save :maybe_auto_index
|
75
|
+
end
|
76
|
+
|
77
|
+
unless options[:auto_remove] == false
|
78
|
+
after_destroy do |searchable|
|
79
|
+
searchable.remove_from_index
|
80
|
+
end
|
81
|
+
end
|
82
|
+
options[:include] = Util::Array(options[:include])
|
83
|
+
|
84
|
+
self.sunspot_options = options
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
#
|
89
|
+
# This method is defined on all MongoMapper::Base subclasses. It
|
90
|
+
# is false for classes on which #searchable has not been called, and
|
91
|
+
# true for classes on which #searchable has been called.
|
92
|
+
#
|
93
|
+
# ==== Returns
|
94
|
+
#
|
95
|
+
# +false+
|
96
|
+
#
|
97
|
+
def searchable?
|
98
|
+
false
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
module ClassMethods
|
103
|
+
def self.extended(base) #:nodoc:
|
104
|
+
class <<base
|
105
|
+
alias_method :search, :solr_search unless method_defined? :search
|
106
|
+
alias_method :search_ids, :solr_search_ids unless method_defined? :search_ids
|
107
|
+
alias_method :remove_all_from_index, :solr_remove_all_from_index unless method_defined? :remove_all_from_index
|
108
|
+
alias_method :remove_all_from_index!, :solr_remove_all_from_index! unless method_defined? :remove_all_from_index!
|
109
|
+
alias_method :reindex, :solr_reindex unless method_defined? :reindex
|
110
|
+
alias_method :index, :solr_index unless method_defined? :index
|
111
|
+
alias_method :index_orphans, :solr_index_orphans unless method_defined? :index_orphans
|
112
|
+
alias_method :clean_index_orphans, :solr_clean_index_orphans unless method_defined? :clean_index_orphans
|
113
|
+
end
|
114
|
+
end
|
115
|
+
#
|
116
|
+
# Search for instances of this class in Solr. The block is delegated to
|
117
|
+
# the Sunspot.search method - see the Sunspot documentation for the full
|
118
|
+
# API.
|
119
|
+
#
|
120
|
+
# ==== Example
|
121
|
+
#
|
122
|
+
# Post.search(:include => [:blog]) do
|
123
|
+
# keywords 'best pizza'
|
124
|
+
# with :blog_id, 1
|
125
|
+
# order :updated_at, :desc
|
126
|
+
# facet :category_ids
|
127
|
+
# end
|
128
|
+
#
|
129
|
+
# ==== Options
|
130
|
+
#
|
131
|
+
# :include:: Specify associations to eager load
|
132
|
+
# :select:: Specify columns to select from database when loading results
|
133
|
+
#
|
134
|
+
# ==== Returns
|
135
|
+
#
|
136
|
+
# Sunspot::Search:: Object containing results, totals, facets, etc.
|
137
|
+
#
|
138
|
+
def solr_search(options = {}, &block)
|
139
|
+
solr_execute_search(options) do
|
140
|
+
Sunspot.new_search(self, &block)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
#
|
145
|
+
# Get IDs of matching results without loading the result objects from
|
146
|
+
# the database. This method may be useful if search is used as an
|
147
|
+
# intermediate step in a larger find operation. The block is the same
|
148
|
+
# as the block provided to the #search method.
|
149
|
+
#
|
150
|
+
# ==== Returns
|
151
|
+
#
|
152
|
+
# Array:: Array of IDs, in the order returned by the search
|
153
|
+
#
|
154
|
+
def solr_search_ids(&block)
|
155
|
+
solr_execute_search_ids do
|
156
|
+
solr_search(&block)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
#
|
161
|
+
# Remove instances of this class from the Solr index.
|
162
|
+
#
|
163
|
+
def solr_remove_all_from_index
|
164
|
+
Sunspot.remove_all(self)
|
165
|
+
end
|
166
|
+
|
167
|
+
#
|
168
|
+
# Remove all instances of this class from the Solr index and immediately
|
169
|
+
# commit.
|
170
|
+
#
|
171
|
+
#
|
172
|
+
def solr_remove_all_from_index!
|
173
|
+
Sunspot.remove_all!(self)
|
174
|
+
end
|
175
|
+
|
176
|
+
#
|
177
|
+
# Completely rebuild the index for this class. First removes all
|
178
|
+
# instances from the index, then loads records and indexes them.
|
179
|
+
#
|
180
|
+
# See #index for information on options, etc.
|
181
|
+
#
|
182
|
+
def solr_reindex(options = {})
|
183
|
+
solr_remove_all_from_index
|
184
|
+
solr_index(options)
|
185
|
+
end
|
186
|
+
|
187
|
+
#
|
188
|
+
# Add/update all existing records in the Solr index. The
|
189
|
+
# +batch_size+ argument specifies how many records to load out of the
|
190
|
+
# database at a time. The default batch size is 500; if nil is passed,
|
191
|
+
# records will not be indexed in batches. By default, a commit is issued
|
192
|
+
# after each batch; passing +false+ for +batch_commit+ will disable
|
193
|
+
# this, and only issue a commit at the end of the process. If associated
|
194
|
+
# objects need to indexed also, you can specify +include+ in format
|
195
|
+
# accepted by MongoMapper to improve your sql select performance
|
196
|
+
#
|
197
|
+
# ==== Options (passed as a hash)
|
198
|
+
#
|
199
|
+
# batch_size<Integer>:: Batch size with which to load records. Passing
|
200
|
+
# 'nil' will skip batches. Default is 500.
|
201
|
+
# batch_commit<Boolean>:: Flag signalling if a commit should be done after
|
202
|
+
# after each batch is indexed, default is 'true'
|
203
|
+
# include<Mixed>:: include option to be passed to the MongoMapper find,
|
204
|
+
# used for including associated objects that need to be
|
205
|
+
# indexed with the parent object, accepts all formats
|
206
|
+
# MongoMapper::Base.find does
|
207
|
+
# first_id:: The lowest possible ID for this class. Defaults to 0, which
|
208
|
+
# is fine for integer IDs; string primary keys will need to
|
209
|
+
# specify something reasonable here.
|
210
|
+
#
|
211
|
+
# ==== Examples
|
212
|
+
#
|
213
|
+
# # index in batches of 500, commit after each
|
214
|
+
# Post.index
|
215
|
+
#
|
216
|
+
# # index all rows at once, then commit
|
217
|
+
# Post.index(:batch_size => nil)
|
218
|
+
#
|
219
|
+
# # index in batches of 500, commit when all batches complete
|
220
|
+
# Post.index(:batch_commit => false)
|
221
|
+
#
|
222
|
+
# # include the associated +author+ object when loading to index
|
223
|
+
# Post.index(:include => :author)
|
224
|
+
#
|
225
|
+
def solr_index(opts={})
|
226
|
+
options = { :batch_size => 500, :batch_commit => true, :include => self.sunspot_options[:include], :first_id => 0}.merge(opts)
|
227
|
+
unless options[:batch_size]
|
228
|
+
Sunspot.index!(all(:include => options[:include]))
|
229
|
+
else
|
230
|
+
offset = 0
|
231
|
+
counter = 1
|
232
|
+
record_count = count
|
233
|
+
last_id = options[:first_id]
|
234
|
+
while(offset < record_count)
|
235
|
+
solr_benchmark options[:batch_size], counter do
|
236
|
+
records = all(:include => options[:include], :conditions => ["#{table_name}.#{primary_key} > ?", last_id], :limit => options[:batch_size], :order => primary_key)
|
237
|
+
Sunspot.index(records)
|
238
|
+
last_id = records.last.id
|
239
|
+
end
|
240
|
+
Sunspot.commit if options[:batch_commit]
|
241
|
+
offset += options[:batch_size]
|
242
|
+
counter += 1
|
243
|
+
end
|
244
|
+
Sunspot.commit unless options[:batch_commit]
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
#
|
249
|
+
# Return the IDs of records of this class that are indexed in Solr but
|
250
|
+
# do not exist in the database. Under normal circumstances, this should
|
251
|
+
# never happen, but this method is provided in case something goes
|
252
|
+
# wrong. Usually you will want to rectify the situation by calling
|
253
|
+
# #clean_index_orphans or #reindex
|
254
|
+
#
|
255
|
+
# ==== Returns
|
256
|
+
#
|
257
|
+
# Array:: Collection of IDs that exist in Solr but not in the database
|
258
|
+
def solr_index_orphans
|
259
|
+
count = self.count
|
260
|
+
indexed_ids = solr_search_ids { paginate(:page => 1, :per_page => count) }.to_set
|
261
|
+
all(:select => 'id').each do |object|
|
262
|
+
indexed_ids.delete(object.id)
|
263
|
+
end
|
264
|
+
indexed_ids.to_a
|
265
|
+
end
|
266
|
+
|
267
|
+
#
|
268
|
+
# Find IDs of records of this class that are indexed in Solr but do not
|
269
|
+
# exist in the database, and remove them from Solr. Under normal
|
270
|
+
# circumstances, this should not be necessary; this method is provided
|
271
|
+
# in case something goes wrong.
|
272
|
+
#
|
273
|
+
def solr_clean_index_orphans
|
274
|
+
solr_index_orphans.each do |id|
|
275
|
+
new do |fake_instance|
|
276
|
+
fake_instance.id = id
|
277
|
+
end.solr_remove_from_index
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
#
|
282
|
+
# Classes that have been defined as searchable return +true+ for this
|
283
|
+
# method.
|
284
|
+
#
|
285
|
+
# ==== Returns
|
286
|
+
#
|
287
|
+
# +true+
|
288
|
+
#
|
289
|
+
def searchable?
|
290
|
+
true
|
291
|
+
end
|
292
|
+
|
293
|
+
def solr_execute_search(options = {})
|
294
|
+
options.assert_valid_keys(:include, :select)
|
295
|
+
search = yield
|
296
|
+
unless options.empty?
|
297
|
+
search.build do |query|
|
298
|
+
if options[:include]
|
299
|
+
query.data_accessor_for(self).include = options[:include]
|
300
|
+
end
|
301
|
+
if options[:select]
|
302
|
+
query.data_accessor_for(self).select = options[:select]
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
306
|
+
search.execute
|
307
|
+
end
|
308
|
+
|
309
|
+
def solr_execute_search_ids(options = {})
|
310
|
+
search = yield
|
311
|
+
search.raw_results.map { |raw_result| raw_result.primary_key.to_i }
|
312
|
+
end
|
313
|
+
|
314
|
+
protected
|
315
|
+
|
316
|
+
#
|
317
|
+
# Does some logging for benchmarking indexing performance
|
318
|
+
#
|
319
|
+
def solr_benchmark(batch_size, counter, &block)
|
320
|
+
start = Time.now
|
321
|
+
logger.info("[#{Time.now}] Start Indexing")
|
322
|
+
yield
|
323
|
+
elapsed = Time.now-start
|
324
|
+
logger.info("[#{Time.now}] Completed Indexing. Rows indexed #{counter * batch_size}. Rows/sec: #{batch_size/elapsed.to_f} (Elapsed: #{elapsed} sec.)")
|
325
|
+
end
|
326
|
+
|
327
|
+
end
|
328
|
+
|
329
|
+
module InstanceMethods
|
330
|
+
def self.included(base) #:nodoc:
|
331
|
+
base.module_eval do
|
332
|
+
alias_method :index, :solr_index unless method_defined? :index
|
333
|
+
alias_method :index!, :solr_index! unless method_defined? :index!
|
334
|
+
alias_method :remove_from_index, :solr_remove_from_index unless method_defined? :remove_from_index
|
335
|
+
alias_method :remove_from_index!, :solr_remove_from_index! unless method_defined? :remove_from_index!
|
336
|
+
alias_method :more_like_this, :solr_more_like_this unless method_defined? :more_like_this
|
337
|
+
alias_method :more_like_this_ids, :solr_more_like_this_ids unless method_defined? :more_like_this_ids
|
338
|
+
end
|
339
|
+
end
|
340
|
+
#
|
341
|
+
# Index the model in Solr. If the model is already indexed, it will be
|
342
|
+
# updated. Using the defaults, you will usually not need to call this
|
343
|
+
# method, as models are indexed automatically when they are created or
|
344
|
+
# updated. If you have disabled automatic indexing (see
|
345
|
+
# ClassMethods#searchable), this method allows you to manage indexing
|
346
|
+
# manually.
|
347
|
+
#
|
348
|
+
def solr_index
|
349
|
+
Sunspot.index(self)
|
350
|
+
end
|
351
|
+
|
352
|
+
#
|
353
|
+
# Index the model in Solr and immediately commit. See #index
|
354
|
+
#
|
355
|
+
def solr_index!
|
356
|
+
Sunspot.index!(self)
|
357
|
+
end
|
358
|
+
|
359
|
+
#
|
360
|
+
# Remove the model from the Solr index. Using the defaults, this should
|
361
|
+
# not be necessary, as models will automatically be removed from the
|
362
|
+
# index when they are destroyed. If you disable automatic removal
|
363
|
+
# (which is not recommended!), you can use this method to manage removal
|
364
|
+
# manually.
|
365
|
+
#
|
366
|
+
def solr_remove_from_index
|
367
|
+
Sunspot.remove(self)
|
368
|
+
end
|
369
|
+
|
370
|
+
#
|
371
|
+
# Remove the model from the Solr index and commit immediately. See
|
372
|
+
# #remove_from_index
|
373
|
+
#
|
374
|
+
def solr_remove_from_index!
|
375
|
+
Sunspot.remove!(self)
|
376
|
+
end
|
377
|
+
|
378
|
+
def solr_more_like_this(*args, &block)
|
379
|
+
options = args.extract_options!
|
380
|
+
self.class.solr_execute_search(options) do
|
381
|
+
Sunspot.new_more_like_this(self, *args, &block)
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
def solr_more_like_this_ids(&block)
|
386
|
+
self.class.solr_execute_search_ids do
|
387
|
+
solr_more_like_this(&block)
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
391
|
+
private
|
392
|
+
|
393
|
+
def maybe_mark_for_auto_indexing
|
394
|
+
@marked_for_auto_indexing =
|
395
|
+
if !new_record? && ignore_attributes = self.class.sunspot_options[:ignore_attribute_changes_of]
|
396
|
+
@marked_for_auto_indexing = !(changed.map { |attr| attr.to_sym } - ignore_attributes).blank?
|
397
|
+
else
|
398
|
+
true
|
399
|
+
end
|
400
|
+
true
|
401
|
+
end
|
402
|
+
|
403
|
+
def maybe_auto_index
|
404
|
+
if @marked_for_auto_indexing
|
405
|
+
solr_index
|
406
|
+
remove_instance_variable(:@marked_for_auto_indexing)
|
407
|
+
end
|
408
|
+
end
|
409
|
+
end
|
410
|
+
end
|
411
|
+
end
|
412
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 12
|
9
|
+
version: 0.3.12
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Alexey Petrushin
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-22 00:00:00 +04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -81,8 +81,10 @@ files:
|
|
81
81
|
- .git/objects/08/bba6f68e3626f05fcfa8bcd10714aac9943407
|
82
82
|
- .git/objects/08/f5dafa9123b7f8d1f22a796c4cba4a4063ad0d
|
83
83
|
- .git/objects/09/20505d42c0044b31ff7b1f86cec6e282e13414
|
84
|
+
- .git/objects/0b/1a882513f514fe05177cc54f4480141b195956
|
84
85
|
- .git/objects/0b/3b3d1048f25fdc0de3f680cdbbd867a42b5a95
|
85
86
|
- .git/objects/0b/68897860be3a4a765d6f1788ea4a0e91ff8c6c
|
87
|
+
- .git/objects/0b/b62f25b6636b2ce32ebd4551120f5765b787e1
|
86
88
|
- .git/objects/0b/e101a0586410212b4ee5905881ad726b7b4907
|
87
89
|
- .git/objects/0c/4df6bee8ffbfd79927b23a070a4c9a41991152
|
88
90
|
- .git/objects/0d/aa3468e187093eff222b8094a6e702dea9ba4e
|
@@ -161,6 +163,7 @@ files:
|
|
161
163
|
- .git/objects/2d/043376f1bc26b2dad3e79fc72ea14341ea437d
|
162
164
|
- .git/objects/2e/3e3fc8e46949a9b944da3c36207c444aa2c9b7
|
163
165
|
- .git/objects/2e/f02adc5485c579d75dfacf7034b20760f2fdf4
|
166
|
+
- .git/objects/2f/af7acb8454f4b248d928b9a92f09571302a174
|
164
167
|
- .git/objects/30/69d4978bbdfacf4402c4339438b29657275f2c
|
165
168
|
- .git/objects/30/e5bf9c61cc450f8024ab7029a490d7fb9f3ff7
|
166
169
|
- .git/objects/31/2f74fcf97e832a3493accaf640f001d6d85170
|
@@ -309,6 +312,7 @@ files:
|
|
309
312
|
- .git/objects/79/4750e930e297c9616e902898f684967c2760c7
|
310
313
|
- .git/objects/79/f570c126c66576fc1a5eaa52f003cf1b24e0d2
|
311
314
|
- .git/objects/7a/d62f1e2a8e4af39d293ce70c5dca999263ab4e
|
315
|
+
- .git/objects/7b/469d63569dcc92c82f90fc7a48793c31365f9a
|
312
316
|
- .git/objects/7b/f12fa27542b09a968ac9b1ceedc1a71bfd6ce8
|
313
317
|
- .git/objects/7c/d6496ed2dbb6dc550d2080954a5485bff16e7f
|
314
318
|
- .git/objects/7c/ecdf8b52167f490bafb6948b0413855923e3d4
|
@@ -351,9 +355,11 @@ files:
|
|
351
355
|
- .git/objects/90/57dd59aea225dd8f4b1dfa3e10c6096671fab9
|
352
356
|
- .git/objects/90/5fe8a081a30b8d3d198590c434e8d0e3b0a4a2
|
353
357
|
- .git/objects/90/8c06f1a239ced6b5784c851e30c8df6780fcce
|
358
|
+
- .git/objects/90/a3187c0cfd6ae0de236633da361820a4cf1b19
|
354
359
|
- .git/objects/90/ad7b150bde29d3a30f4a8ddd2463249e6c4418
|
355
360
|
- .git/objects/90/ca84ea326afab5fcc92a50469c2052ebc46f11
|
356
361
|
- .git/objects/92/dc044f4d69a5cb3a6a3109c2ce6b7f90bac2ab
|
362
|
+
- .git/objects/92/debcedcd81c328806dc7506b3cd91990bb9775
|
357
363
|
- .git/objects/92/e1c250edfca72ed0932934257ef3cfc7122ec5
|
358
364
|
- .git/objects/92/e1f3936e7c33007d0a466b836804450992a1eb
|
359
365
|
- .git/objects/93/f9a6b596879347290cde161b03052bb22021de
|
@@ -525,6 +531,7 @@ files:
|
|
525
531
|
- .git/objects/e3/cde2715e3e3870a5d7312cac9bbf6e24259e0f
|
526
532
|
- .git/objects/e4/1d46e33f52e07b836b966d58677fc2a864a4a4
|
527
533
|
- .git/objects/e4/d7cacac2d7e66df5a7c21eaae71c0a90f1439d
|
534
|
+
- .git/objects/e5/18de391d5b9dee87ec6f749900785f3b24dad0
|
528
535
|
- .git/objects/e5/7fa5fd7f10f6f532742b0cc2dc3edaed6c0763
|
529
536
|
- .git/objects/e6/4d9b4d86a001e4f882a9842a8dd4368001c470
|
530
537
|
- .git/objects/e6/ed7d272f8c48a28904007d653837bfe761be36
|
@@ -567,6 +574,7 @@ files:
|
|
567
574
|
- .git/objects/f6/b9bcda0a6940c634c0ac0d6ac626028927e1da
|
568
575
|
- .git/objects/f7/32b167a61d8db0328f0196af00b55147ebf756
|
569
576
|
- .git/objects/f7/b177b2c6b25dd886d23d6be87bcf802af9b513
|
577
|
+
- .git/objects/f7/be86378738705bbd1f97dd8be92c3cc7d54a66
|
570
578
|
- .git/objects/f8/9eb17d4ff10a745b70063cf5b8ff76ec66e102
|
571
579
|
- .git/objects/f9/8d0f95460a7a3f63ab4c08ad5508fd32d1b5c2
|
572
580
|
- .git/objects/f9/cf98993bf7067d5b45b0f06dc36fdedba5ffcf
|
@@ -651,6 +659,8 @@ files:
|
|
651
659
|
- lib/rails_ext/micelaneous/rails_require.rb
|
652
660
|
- lib/rails_ext/micelaneous/safe_hash.rb
|
653
661
|
- lib/rails_ext/micelaneous.rb
|
662
|
+
- lib/sunspot/mongo_mapper/adapters.rb
|
663
|
+
- lib/sunspot/mongo_mapper/searchable.rb
|
654
664
|
- spec/mongo_mapper_ext/micelaneous_plugin_spec.rb
|
655
665
|
- spec/mongo_mapper_ext/micelaneous_spec.rb
|
656
666
|
- spec/mongo_mapper_ext/mongo_mapper_migration_spec.rb
|