太阳黑子可以在阵列内搜索吗? [英] Can sunspot search inside array?
本文介绍了太阳黑子可以在阵列内搜索吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下一个带有数组字段的模型:
I have the next model with a array field:
Class Invitation
include Mongoid::Document
include Mongoid::Timestamps::Created
include Sunspot::Mongo
field :recipients, :type => Array
attr_accessible :recipients
searchable do
text :recipients do
recipients.map { |recipient| recipient }
end
end
end
我的控制器中有:
def recipients
@invitation = Invitation.find(params[:id])
@search = Invitation.search do |s|
s.fulltext params[:search]
s.with(:recipients, @invitation.recipients)
end
@recipients = @search.results
respond_to do |format|
format.html
end
end
这个当我重新索引时没有显示错误但是:
This when I reindex not show error but:
这对我来说不太好.我在日志中收到下一个错误:
This not works fine for me. I get the next error in log:
Sunspot::UnrecognizedFieldError(没有为名为收件人"的邀请配置字段):
Sunspot::UnrecognizedFieldError (No field configured for Invitation with name 'recipients'):
我也试过了:
string :recipients do
recipients.map { |recipient| recipient }
end
但是当我重新索引时出现下一个错误:
But I get the next error when I reindex:
recipients is not a multiple-value field, so it cannot index values []
我能解决这个问题吗?
推荐答案
Invitation
模型与 recipients
有一个 has_many
关联.这意味着一个 invitation
可以有多个 recipients
.
The Invitation
model has a has_many
association with recipients
. This means an invitation
can have multiple recipients
.
所以,试试这个:
string :recipients, :multiple => true do
recipients.map { |recipient| recipient }
end
这篇关于太阳黑子可以在阵列内搜索吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文