条件“或”在思考狮身人面像搜索中
使用 RoR 2.3.8。
这是我的控制器代码:
class CitiesController < ApplicationController
def show
@city = City.find(params[:id])
@shops = Shop.search @city.name, {
:conditions => {:country => @city.country && (:city => @city.name || :state => @city.state)},
:page => params[:page],
:per_page => 100
}
end
end
:conditions => {:国家=> @city.country && (:city => @city.name || :state => @city.state)}
显然不起作用,因为我只是想解释我想要实现的目标。
:city
和 :state
将是 Spots
表中的列,而不是 Cities
表中的列。我希望结果返回其中之一满足条件。但不知道该怎么做。
谢谢。
Using RoR 2.3.8.
Here's my controller code:
class CitiesController < ApplicationController
def show
@city = City.find(params[:id])
@shops = Shop.search @city.name, {
:conditions => {:country => @city.country && (:city => @city.name || :state => @city.state)},
:page => params[:page],
:per_page => 100
}
end
end
The :conditions => {:country => @city.country && (:city => @city.name || :state => @city.state)}
obviously doesn't work because I am just trying to explain what I wanna achieve.
:city
and :state
will be columns from Spots
table, not Cities
table. I want results to return either one of them fulfills the condition. But have no clue how to do it.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Tass 做对了 - 通过您的 TS 搜索调用,它应该看起来像这样:
您会注意到我已经设置了匹配模式 - 如果您使用
:conditions 参数 - 但是当手动构造查询时,您需要自己设置它。
Tass has got it right - with your TS search call, it should look something like this:
You'll note I've set the match mode - Thinking Sphinx will do this automatically if you're using the
:conditions
argument - but when constructing the query manually, you need to set it yourself.将您的原始搜索放在 Sphinx - 您应该在 TS 文档中找到正确的方法。 原始搜索参考。你可能想要类似的东西
(我不确定 TS 如何命名索引。检查一下。)
Place your raw search to Sphinx - you should find the correct method in the TS docu. A reference for raw search. You probably want something like
(I'm not sure how TS names the indexes. Check that.)