按 ID 搜索,无需关键字。尝试使用:条件但没有结果输出
使用思维狮身人面像,Rails 2.3.8。
我没有要搜索的关键字,但我想通过已编入索引的 shop_id
进行搜索。这是我的代码:
@country = Country.search '', {
:with => {:shop_id => params[:shop_id]},
:group_by => 'state_id',
:group_function => :attr,
:page => params[:page]
}
上面的代码有效。但我认为 ''
相当多余。所以我用 :conditions
替换它,结果为:
@country = Country.search :conditions => {
:with => {:shop_id => params[:shop_id]},
:group_by => 'state_id',
:group_function => :attr,
:page => params[:page]
}
但随后它给出 0 结果。正确的代码是什么?
谢谢。
Using Thinking Sphinx, Rails 2.3.8.
I don't have a keyword to search, but I wanna search by shop_id
which is indexed. Here's my code:
@country = Country.search '', {
:with => {:shop_id => params[:shop_id]},
:group_by => 'state_id',
:group_function => :attr,
:page => params[:page]
}
The one above works. But I thought the ''
is rather redundant. So I replaced it with :conditions
resulting as:
@country = Country.search :conditions => {
:with => {:shop_id => params[:shop_id]},
:group_by => 'state_id',
:group_function => :attr,
:page => params[:page]
}
But then it gives 0 result. What is the correct code?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
进入控制台看看是否无法改变 :conditions。看起来,通过删除空白字符串,您只需为 gem 设置一个默认参数。在您的供应商处获取宝石并查看国家/地区类别以了解可接受的内容。
Have a go in the console and see if you cant shift the :conditions around. It looks like by removing the blank string you simply have set a default param for the gem. Get the Gem in your Vendor and have a look at the Country Class to see what is accepts.