简体   繁体   English

actions_as_ferret-如何将搜索范围限制为少数字段?

[英]acts_as_ferret - how to limit a search to a small number of fields?

I have a model School which is ferret-indexed on 10 or 12 different indexes. 我有一个模型学校,它在10或12个不同的索引上被雪貂索引。

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) 在一个特定的搜索中,我只想返回与以下字段之一中的搜索词匹配的学校: ["name", "postcode", "urn"] (urn是uid类型的字段)

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 谢谢,最大

万一有人用同样的问题用谷歌搜索它,我找到了答案(在雪貂文档中,doh)。

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

From the acts_as_ferret documentation: 从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 }
                                }
                              }
                            } )

Note the 'fields' definition 注意“字段”的定义

https://github.com/jkraemer/acts_as_ferret https://github.com/jkraemer/acts_as_ferret

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM