条件“或”在思考狮身人面像搜索中

发布于 2024-10-31 14:47:37 字数 695 浏览 0 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

许仙没带伞 2024-11-07 14:47:37

Tass 做对了 - 通过您的 TS 搜索调用,它应该看起来像这样:

def show
  @city = City.find(params[:id])
  @shops = Shop.search "#{@city.name} @country #{@city.country} (@city #{@city.name} | @state #{@city.state})",
    :match_mode => :extended,
    :page       => params[:page],
    :per_page   => 100
    }
end

您会注意到我已经设置了匹配模式 - 如果您使用 :conditions 参数 - 但是当手动构造查询时,您需要自己设置它。

Tass has got it right - with your TS search call, it should look something like this:

def show
  @city = City.find(params[:id])
  @shops = Shop.search "#{@city.name} @country #{@city.country} (@city #{@city.name} | @state #{@city.state})",
    :match_mode => :extended,
    :page       => params[:page],
    :per_page   => 100
    }
end

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.

森林迷了鹿 2024-11-07 14:47:37

将您的原始搜索放在 Sphinx - 您应该在 TS 文档中找到正确的方法。 原始搜索参考。你可能想要类似的东西

"@city_country #{@city.country} (@city_name #{@city.name} | @city_state #{@city.state})"

(我不确定 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

"@city_country #{@city.country} (@city_name #{@city.name} | @city_state #{@city.state})"

(I'm not sure how TS names the indexes. Check that.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文