Hi,
and sorry for the late reply.
On Wed, Apr 26, 2006 at 12:41:10PM +0200, Frank Rosquin wrote:
Hello,
Lets say you have a few models like Post, Article, Wiki, Comment, And
you want to use ferret to search all of them at once. How would I set up
the latest acts_as_ferret to accomplish this? And what would be fastest
for searches? 1 index for all models, or have an index per model?
Which would be fastest depends on the type of your queries. If most of
your queries search all models at once, a single index should be faster.
If you tend to query mainly a single model and queries across all models
are the exception, the index-per-model approach should be better suited.
However the difference won’t matter until you get to really big indexes.
If you go the multiple index route (declaring acts_as_ferret in each of
the models you want to search), you can use the
multi_search(query, additional_models = [], options = {})
method on any of these model classes, giving the list of all other model
classes to search through as the second parameter. the options hash is
the same as for find_by_contents. You have to add the
:store_class_name => true option to your acts_as_ferret calls. That
turns class name storage in the indexes on and let’s multi_search know
what class to query for a given hit.
For the single index route, using Rails single table inheritance is the
easiest approach. Just call acts_as_ferret once in your base class, and
use find_by_contents as usual. This is known to work, I use this with
Typo’s Content base class.
If this is no option for you, you can configure each model class to use
the same index directory. This approach should work but hasn’t got much
(if any) testing so far.
One problem here is that we use the id column as a key in ferret
indexes,
too. So the id has to be unique across the models you want to search.
In addition, you would be on your own for querying the index, I don’t
think any of the existing searching methods will work out of the box in
this scenario. The :store_class_name option to acts_as_ferret should
be useful in this contextm, too.
Patches regarding these issues would be very welcome - my
hacking time is quite constrained atm…
After all, I’d either suggest the STI approach or, if that doesn’t fit,
the multi-index route.
hope this helps,
Jens
–
webit! Gesellschaft für neue Medien mbH www.webit.de
Dipl.-Wirtschaftsingenieur Jens Krämer [email protected]
Schnorrstraße 76 Tel +49 351 46766 0
D-01069 Dresden Fax +49 351 46766 66