在我的应用程序中,我在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
我无法解决此错误
答案 0 :(得分:0)
我在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
end