acts_as_ferret - 如何将搜索限制为少量字段?
我有一所模型学校,它在 10 或 12 个不同的索引上进行了雪貂索引。
在一次特定搜索中,我只想返回与以下字段之一中的搜索词匹配的学校:["name", "postcode", "urn"]
(urn 是一种 uid例如
,搜索“grange”应返回名称中包含“grange”的学校,但不会返回地址中包含“grange”的学校(除非课程名称中也包含“grange”)。
如果只有一个字段(例如名称),我可以通过以下方式实现这一点,
School.find_with_ferret("name:#{term}")
但是,我无法弄清楚如何使用字段列表来做到这一点。我想我也许可以使用“或”语法,例如
School.find_with_ferret("name:#{term} || postcode:#{term} || urn:#{term}")
or
School.find_with_ferret("name:#{term} or postcode:#{term} or urn:#{term}")
但这些都不起作用。有人知道该怎么做吗?谢谢,麦克斯
I have a model School which is ferret-indexed on 10 or 12 different indexes.
In one particular search, i want to return only schools which match the search term in one of the following fields: ["name", "postcode", "urn"]
(urn is a uid kind of field)
For example, a search for "grange" should return schools with "grange" in their name but NOT return schools that have "grange" in their address (unless it's also in their name of course).
If there's just one field (eg name), i can achieve this by
School.find_with_ferret("name:#{term}")
But, i can't work out how to do this with a list of fields. I thought i might be able to use an "or" syntax, like
School.find_with_ferret("name:#{term} || postcode:#{term} || urn:#{term}")
or
School.find_with_ferret("name:#{term} or postcode:#{term} or urn:#{term}")
but neither of these work. Anyone know how to do this? Thanks, max
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自acts_as_ferret文档:
注意“字段”定义
https://github.com/jkraemer/acts_as_ferret
From the acts_as_ferret documentation:
Note the 'fields' definition
https://github.com/jkraemer/acts_as_ferret
如果有人用谷歌搜索到同样的问题,我找到了答案(在雪貂文档中,doh)。
In case anyone googles to this with the same problem, i found the answer (in the ferret documentation, doh).