Refreshing indexes?

I am new to ferret and am just reading about it in the O’reilly
shortcuts as well as other web resources. My app is a Rails app and so
I am looking into acts_as_ferret as well. There are some questions for
which I couldn’t find answers in the material I have read so far so
I’d appreciate any help on these from the list.

A bit of a background. My app will have 10,000 - 50,000 documents.
These are ‘owned’ by users and the groups they belong to (like a file
system). So the queries will have to be restricted to those documents
owned by the groups the user belongs to. I have a group_id in each
record and the session has the group_id’s of the groups the user
belongs to in an array.

Question 1:
If I add acts_as_ferret :fields => [:group_id, :document_text] can I
do an activerecord search like…
Document.find(:all, :conditions => [‘group_id in (?)’,
session[:group_ids]) ?

Question 2:
These documents are dynamic, so they are deleted, updated, edited etc.
How do I handle indexing in these circumstances? Delete all and
recreate -or- is there a way to just delete an index by document_id
and recreate it just for that document.

I am going to try this in the app but before I took the plunge I
thought I’d ask first.

-tia,

bakki

PS: the app will be used by separate client companies, so on one
server we will host the app in multiple virtual hosts(separate rails
app instance for each). Can I share a drb for all clients or do I need
one per client.

Hey…

Question 1:
If I add acts_as_ferret :fields => [:group_id, :document_text] can I
do an activerecord search like…
Document.find(:all, :conditions => [‘group_id in (?)’, session
[:group_ids]) ?

yes, you can. Check the FQL. But i wouldn’t trust the ferret index, if
you plan to use this to fetch security-related objects.

Question 2:
These documents are dynamic, so they are deleted, updated, edited etc.
How do I handle indexing in these circumstances? Delete all and
recreate -or- is there a way to just delete an index by document_id
and recreate it just for that document.

use acts_as_ferret or check the way acts_as_ferret implements
after_save/after_destroy hooks[1]. But basically, if you use AAF,
you don’t need to think about that :slight_smile:
If you don’t use AAF, you need to implement hooks (like an
observer) on save/destroy, check [2] for an example (including
cache sweepers).

I am going to try this in the app but before I took the plunge I
thought I’d ask first.

good idea :slight_smile: Hope that helps …

Ben

[1] - http://projects.jkraemer.net/acts_as_ferret/browser/trunk/
plugin/acts_as_ferret/lib/act_methods.rb
[2] - http://bugs.omdb.org/browser/trunk/app/models/observers/
search_observer.rb

Ben,

Thank you very much. That cleared things up for me and I am in the
process of adding ferret to my project. However I am not clear on how
to use the Drb server when you have multiple instances of the app. It
is not the more common deployment scheme where you have multiple app
servers or mongrels but share the same data. Our app will be shared
but the database and the resources are private to each customer. So
can we use Drb to listen on separate ports for serve different
customers?

-bakki

Thank you very much. That cleared things up for me and I am in the
process of adding ferret to my project. However I am not clear on how
to use the Drb server when you have multiple instances of the app. It
is not the more common deployment scheme where you have multiple app
servers or mongrels but share the same data. Our app will be shared
but the database and the resources are private to each customer. So
can we use Drb to listen on separate ports for serve different
customers?

yes you can, check this [1]. Each app will have its own config file
(including a port setting) for the ferret drb server. You should
definitely use the drb server when using ferret.

Ben

[1] http://projects.jkraemer.net/acts_as_ferret/browser/trunk/plugin/
acts_as_ferret/config/ferret_server.yml

We WILL have different databases. So I will have to look into the aaf
source and see if I can patch it or find a way to pass in a path for
an index? Thank you again for your help. If I find a way to do this
I’ll post it here in case there are others who may have similar
requirements.

-bakki

on a 2nd thought… if you want one app with different databases,
you should think about using different indexes for each customer.
but i don’t think you can do this with aaf out of the box … so you just
need one drb server and a way to select the right index to index to.

Ben