0

私のアプリケーションでは、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 としてエラーが表示されます

このエラーを修正できませんでした

4

1 に答える 1

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
于 2012-08-17T07:44:28.103 に答える