Forum: Ferret acts_as_ferret: dynamic index selection

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E74a88a96ce8caecbc7d265e4763e26c?d=identicon&s=25 Stuart Rackham (Guest)
on 2006-05-23 04:50
Hi

What is the be practice regards setting the index path dynamically?

My application needs to switch indexes based on the logged in user, I
put the following before_filter into my controller (the
Document.index_dir method calculates the user's index path):

before_filter { Document.ferret_configuration[:path] =
Document.index_dir }

It seems to work, the only rough edge is that the acts_as_ferret
declaration immediately creates a spurious index directory rather than
deferring until the index is actually accessed (and the index path
known), this also means the index directory is not automagically
created.

Cheers, Stuart
--
Stuart Rackham
E74a88a96ce8caecbc7d265e4763e26c?d=identicon&s=25 Stuart Rackham (Guest)
on 2006-05-25 00:14
Stuart Rackham wrote:
> Hi
>
> What is the be practice regards setting the index path dynamically?
>
> My application needs to switch indexes based on the logged in user, I
> put the following before_filter into my controller (the
> Document.index_dir method calculates the user's index path):
>
> before_filter { Document.ferret_configuration[:path] =
> Document.index_dir }
>
> It seems to work, the only rough edge is that the acts_as_ferret
> declaration immediately creates a spurious index directory rather than
> deferring until the index is actually accessed (and the index path
> known), this also means the index directory is not automagically
> created.

P.S. The above didn't quite work, needed to set index directory in two
places for it to function when adding to the index and searching:

In controller:

  before_filter { Document.set_index_dir }

In the model:

  # Set the Ferret index to that of the current users account.
  def self.set_index_dir
    # Two places are used internally by acts_as_ferret.
    Document.ferret_configuration[:path] = Document.index_dir
    Document.configuration[:index_dir] = Document.index_dir
  end

>
> Cheers, Stuart
> --
> Stuart Rackham
This topic is locked and can not be replied to.