在我的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