Sphinx 使用 OR 确定条件范围
我被困在这里,因为在 Rails 上使用 ruby 的 sphinx 范围有一个小问题。
问题是:
我需要在思考 sphinx 时执行此范围
scope :for_current_user, lambda{
{:conditions => ["documents.user_id = ? OR documents.state != 'draft'", User.current.id]}
}
我最常用的方法是:
sphinx_scope(:sphinx_for_current_user){
{ :conditions => {:user_id => "#{User.current.id }", :workflow_state => '!draft'}}
}
但是上面的这个 sphinx 范围是
“documents.user_id = 20 ANDworkflow_state!='草稿'”
但是,我真正需要的是
“documents.user_id = 20或workflow_state!='草稿'”
非常欢迎任何帮助。
谢谢。
I'm stuck here with a little problem with the scopes of sphinx using ruby on rails.
The problem is:
I need to do this scope in thinking sphinx
scope :for_current_user, lambda{
{:conditions => ["documents.user_id = ? OR documents.state != 'draft'", User.current.id]}
}
My most approach was:
sphinx_scope(:sphinx_for_current_user){
{ :conditions => {:user_id => "#{User.current.id }", :workflow_state => '!draft'}}
}
But this sphinx scope above do is a
" documents.user_id = 20 AND workflow_state != 'draft'"
but, what i really need is
" documents.user_id = 20 OR workflow_state != 'draft' "
Any help is well welcomed.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正确的查询 - 没有范围 - 需要手动构建,并且可能看起来像这样:
目前在 Thinking Sphinx 中,您无法将查询作为 sphinx 范围的一部分提供 - 仅选项。因此,虽然查询应该没问题,但范围不是一个选项。
The right query for this - without scopes - needs to be constructed manually, and might look something like this:
Currently in Thinking Sphinx, you can't supply the query as part of a sphinx scope - only options. So while the query should be fine, scopes aren't an option.