sunspot 文档:https://github.com/sunspot/sunspot 配置:
class Project < ActiveRecord::Base
searchable do
text :name, :oneword, :description
integer :category_ids, multiple: true
integer :city_ids, multiple: true
boolean :published
end
end
数据库数据:
pry(main)> Project.all
Project Load (2.5ms) SELECT DISTINCT "projects".* FROM "projects" WHERE "projects"."deleted_at" IS NULL
=> [#<Project id: 1, name: "baidu", oneword: "Summary", description: "adf", stage: nil, industry: nil, city: "深圳", published: true, created_at: "2016-02-29 03:04:01", updated_at: "2016-02-29 10:30:18", team_story: nil, link: "liuzhen.me", status: "approved", deleted_at: nil>,
#<Project id: 2, name: "dd", oneword: "dd", description: "ddd", stage: nil, industry: nil, city: "dd", published: false, created_at: "2016-02-29 10:44:23", updated_at: "2016-02-29 10:44:23", team_story: nil, link: "liuzhen.me", status: "drafted", deleted_at: nil>]
执行查询:
Sunspot.search(Project) do
with(:published, true)
end.results
D, [2016-02-29T21:03:46.567622 #9580] DEBUG -- : SOLR Request (43.9ms) [ path=select parameters={fq: ["type:Project", "published_b:true"], start: 0, rows: 30, q: "*:*"} ]
=> []