acts_as_ferret-如何将搜索限制为少数字段



我有一个模型学校,它在10或12个不同的索引上进行了搜索索引。

在一个特定的搜索中,我想只返回与以下字段中的搜索项匹配的学校:["name", "postcode", "urn"](urn是uid类型的字段)

例如,搜索"grange"应返回名称中包含"grange"的学校,但不返回地址中包含"grange"的学校(当然,除非它也在他们的名称中)。

如果只有一个字段(例如名称),我可以通过实现

School.find_with_ferret("name:#{term}")

但是,我不知道如何使用字段列表来实现这一点。我想我可能可以使用"或"语法,比如

School.find_with_ferret("name:#{term} || postcode:#{term} || urn:#{term}")

School.find_with_ferret("name:#{term} or postcode:#{term} or urn:#{term}")

但这两者都不起作用。有人知道怎么做吗?谢谢,最大

来自acts_as_ferret文档:

ActsAsFerret::define_index( 'my_index',
                            :models => {
                              SomeModel => {
                                :fields => {
                                  :name => { :boost => 4, :store => :yes, :via => :ferret_title },
                                  :foo => { :store => :no,  :index => :untokenized },
                                  :baz => { :store => :yes, :via => :ferret_content }
                                }
                              }
                            } )

注意"字段"定义

https://github.com/jkraemer/acts_as_ferret

如果有人用谷歌搜索到这个问题,我会找到答案(在雪貂文档中,doh)。

School.find_with_ferret("name|postcode|urn:#{term}")

最新更新