sunspot solr 小青年

Gemfile

gem 'sunspot_rails'

gem 'sunspot_solr'

然后执行

bundle

 之后就是rails g sunspot:solr:install生成一个config/sunspot.yml文件,不需要管理这个生成文件

然后执行

bundle exec rake sunspot:solr:start

class Post < ActiveRecord::Base   
searchable do
text :title, :body
text :comments do
comments.map { |comment| comment.body }
end
boolean :featured
integer :blog_id
integer :author_id
integer :category_ids, :multiple => true
double :average_rating
time :published_at
time :expired_at
string :sort_title do
title.downcase.gsub(/^(an?|the)/, '')
end
end
end

bundle exec rake sunspot:solr:reindex

参考: https://github.com/sunspot/sunspot

原文地址:https://www.cnblogs.com/perish/p/2779317.html