Search sold edition,rake sunspot:solr:run. NewsBulletin.solr_search,NewsBulletin.solr_reindex. Not working
This commit is contained in:
1 parent
8dd1ab32c1
commit
cb17fe0825
46 files changed
+2597
-263
No files matched your search
@@ -0,0 +1,36 @@
|
||||
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
||||
require 'sunspot_mongoid'
|
||||
|
||||
Mongoid.configure do |config|
|
||||
config.master = Mongo::Connection.new.db('sunspot-mongoid-test')
|
||||
end
|
||||
|
||||
# model
|
||||
class Post
|
||||
include Mongoid::Document
|
||||
field :title
|
||||
|
||||
include Sunspot::Mongoid
|
||||
searchable do
|
||||
text :title
|
||||
end
|
||||
end
|
||||
|
||||
# remove old indexes
|
||||
Post.destroy_all
|
||||
|
||||
# indexing
|
||||
Post.create(:title => 'foo')
|
||||
Post.create(:title => 'foo bar')
|
||||
Post.create(:title => 'bar baz')
|
||||
|
||||
# commit
|
||||
Sunspot.commit
|
||||
|
||||
# search
|
||||
search = Post.search do
|
||||
keywords 'foo'
|
||||
end
|
||||
search.each_hit_with_result do |hit, post|
|
||||
p post
|
||||
end
|
||||
Reference in new issue
Block a user