Rails 快速配置sunspot_Ruby_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > Ruby > Rails 快速配置sunspot

Rails 快速配置sunspot

 2013/1/25 11:09:47  尼亚的鬼屋  程序员俱乐部  我要评论(0)
  • 摘要:Step1:新建项目Step2:脚手架railsgeneratescaffoldPostname:stringtitle:stringcontent:textStep3:数据库变更rakedb:migrateStep4:加入gem包gem'sunspot_rails'gem'sunspot_solr'#optionalpre-packagedSolrdistributionforuseindevelopmentStep5:railsgeneratesunspot_rails
  • 标签:rails 配置 Sun
Step1:新建项目

Step2:脚手架
rails generate scaffold Post name:string title:string content:text 


Step3:数据库变更
rake db:migrate


Step4: 加入gem包
gem 'sunspot_rails'
gem 'sunspot_solr' # optional pre-packaged Solr distribution for use in development


Step5:
rails generate sunspot_rails:install


Step6:启动solr
bundle exec rake sunspot:solr:start # or sunspot:solr:run to start in foreground


Step7:修改models/post.rb
class Post < ActiveRecord::Base
  attr_accessible :content, :name, :title
    searchable do
    text :content, :name,:title
  end
end



Step8: 建立索引
方法1:
 
rake sunspot:reindex

方法2:
rails c 中
Post.reindex


Step9:search rails c 中
search =Post.search { fulltext 'a' } #search keyword a
search.total  #results count
results =search.results # results
发表评论
用户名: 匿名