在我的应用程序中,我在mongoDB下创建了一个模型,然后使用sunspot_mongo将其重新索引到solr。我想从solr中搜索,我的模型是,
`require 'sunspot_mongo'
class Post
include Mongoid::Document
include Sunspot::Mongo
field :title
field :content
field :author, type: String
searchable do
text :title, :stored => true
text :content
end
end`我的控制器索引方法是,
def index
#@posts = Post.all
search=Post.search do
fulltext 'hello'
end
@posts = search.results
respond_to do |format|
format.html # index.html.erb
format.json { render json: @posts }
end结束,但它显示错误为,未初始化的常量Sunspot::Mongo::DataAccessor::BSON
我不能修复这个错误
发布于 2012-08-17 15:44:28
我在gem文件中使用了这个。
gem "sunspot_mongo", :git => "git://github.com/balexand/sunspot_mongo.git", :branch => "fix_rake_sunspot_reindex"你的模型看起来很好
如下所示更改您的控制器代码
def index
search=Post.solr_search do
fulltext params[:search]
end
@posts = search.results
respond_to do |format|
format.html # index.html.erb
format.json { render json: @posts }
end
endhttps://stackoverflow.com/questions/12000847
复制相似问题