I’m a novice to ferret, so far only used it via acts_as_ferret. My
question is about a recommended pattern for an ‘advanced search’, which
would be searching by all fields of a model and some fields from related
models, with range search, expression search and wildcards. The kind of
search in which a user is presented with a huge form that allows them to
set the variuos criteria.
is this something ferret (acts_as_ferret?) is suited for and is there a
clean way to do it?
is this something ferret (acts_as_ferret?) is suited for and is
there a
clean way to do it?
When I last checked, you could use Ferret’s advanced query syntax in
acts_as_ferret. So you can use wildcards, ranges, phrases, boolean
expressions and field qualifiers just as if you used Ferret directly.
If you haven’t used Ferret’s query language before, check out the
RDoc documentation for Ferret::QueryParser. It’s pretty well
explained there.
The ‘pattern’ for implementing an advanced search form would be to
gather the information from the form an build a query string from that.
As for indexing/searching fields from related models: This has been
extensively discussed on this list recently, so you might want to
consult the archives. In short, you provide an accessor method for
the field in the related model and index that.
If you haven’t used Ferret’s query language before, check out the
RDoc documentation for Ferret::QueryParser. It’s pretty well
explained there.
Hello,
Thank you, I’m definitely missing this part so far.
As for the advanced search pattern, I’m only worried that my code for
glueing the query from all sorts of fields will be very complex. That’s
why I’m trying to think of something easier to maintain.
So far I was thinking of a solution going along these lines:
data from the search form would be used to create a pattern object
the query would be constructed by iterating through all the
field_infos of the index
for each field_info add to the query a pair attribute : value of that
attribute from the pattern object
I’m considering whether it’s a good course to take, seems tempting
because of its dryness – no need to alter the search method after
extending the index. And it would make the search method a few lines
only, simple loop and not a terrifying sequence of ifs and concats
I’m trying to spot the weaknesses of this idea before I start coding. I
would be happy to hear your thoughts on this idea!
Agnieszka
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.