0

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

4

2 回答 2

0

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

School.find_with_ferret("name|postcode|urn:#{term}")
于 2012-11-26T12:08:04.697 回答
0

从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

于 2012-01-13T18:26:05.670 回答