在我的Rails应用程序中,我使用太阳黑子来索引几个不同的模型。然后我有一个全球搜索表单,返回混合结果。这工作正常:Rails +太阳黑子:多模型搜索,但只有其中一个模型的某些领域?
Sunspot.search(Person, EmailAddress, PhoneNumber, PhysicalAddress) do
fulltext params[:q]
paginate :per_page => 10
end
我想添加一个额外的模型,说项目,这个搜索。项目模型有相当多的被索引:
class Project < ActiveRecord::Base
searchable do
string :category do
category.name.downcase if category = self.category
end
string :client do
client.name.downcase if client = self.client
end
string :status
text :tracking_number
text :description
integer :category_id, :references => Category
integer :client_id, :references => Client
integer :tag_ids, :multiple => true, :references => Tag
time :created_at, :trie => true
time :updated_at, :trie => true
time :received_at, :trie => true
time :completed_at, :trie => true
end
end
如何修改我原来Sunspot.search
呼吁增加仅由tracking_number
领域寻找项目记录和不的description
场?
感谢您的回复。是的,我应该使用'text'方法。但是,我的意思是关注如何在进行多模式搜索时将搜索限制在给定模型的一个字段中。我会更新这个问题,以便更加精确。 – robertwbradford 2012-04-25 16:02:25
我做了一个其他答案/解决方案 – Sebastien 2012-04-25 16:43:34
但如何显示它在视图? – brabertaser19 2014-04-02 21:17:31