【发布时间】:2014-07-07 06:27:34
【问题描述】:
在思考狮身人面像时如何使用conditional or?
情况是:
我有一个带有 sender_id 和 recipient_id 属性的Message 模型。我想编写这个查询:
Message.where("sender_id = ? OR recipient_id = ?", business_id, business_id)
现在,我搜索了两次,一次搜索所有有 recipient_id = business_id 的消息,另一个返回所有有 sender_id = business_id 的消息。然后我只是合并它们。
我觉得有一种更有效的方法来做到这一点。
EDIT - 添加索引文件
ThinkingSphinx::Index.define :message, with: :active_record, delta: ThinkingSphinx::Deltas::DelayedDelta do
# fields
indexes body
# attributes
has job_id
has sender_id
has recipient_id
end
【问题讨论】:
标签: mysql ruby-on-rails-3.2 thinking-sphinx