Two Shared Indices(sp?) in aaf.rb file (for Acts_as_ferret)

Hi all,

I’m trying to add two shared indices to the aaf.rb file, however it is
not working. I currently have one shared index, but that index has a
condition on it, and i’m not sure how to go about creating another
index without this condition in it for my forum, which i want to
search only the forum, topics and messages.

Within aaf.rb i tried to comma separate thecode: eg.g

ActsAsFerret::define_index (‘one’…), ActsAsFerret::define_index
(‘two’…)

To no avail.

I also tried to add another aaf2.rb file to the original call when
aaf.rb, and include both of these files when aaf.rb is loaded but no
dice either.

thoughts?

Hi,

I’m not sure if this is what you’re trying, but having the same model
belong to two or more index is impossible with acts_as_ferret.

Cheers,
Jens

On 01.02.2009, at 16:49, Philip Ingram wrote:

ActsAsFerret::define_index (‘one’…), ActsAsFerret::define_index
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk


Jens Krämer
webit! Gesellschaft für neue Medien mbH
Schnorrstraße 76 | 01069 Dresden
Telefon +49351467660 | Telefax +493514676666
[email protected] | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold

Hi Jens,

No, but i didn’t know that either, so thank you.

What i’m trying is to do the following, All of this code below is in
aaf.rb (hopefully the formatting shows up in this email).
ActsAsFerret::define_index(‘site_index’,
:models => {
Product => {:fields => [:name, :company]},
Post => {:fields => [:title, :body]},
Prategory => {:fields => [:name]}
},
:ferret => {
:default_fields => [:name, :company, :title, :body, :name]
}
),
ActsAsFerret::define_index(‘forumindex’,
:models => {
Topics => {:fields => [:title]},
Messages => {:fields => [:title, :content]}
},
:ferret => {
:default_fields => [:title, :title, :content]
}
)

Now, i get errors when i try to do this, but essentially i want to
somehow use ‘site_Index’ to search those models across all of my site,
and only ‘forumindex’ when i put the search fields on the forum.

IN my Search_controller.rb file i have:
def search
per_page = 15
@results = ActsAsFerret.find(params[:q], ‘site_index’, {:page =>
params[:page], :per_page => per_page}, :conditions => [“account_id
= ?”, current_account.id] )
end

def forum
per_page = 30
@results = ActsAsFerret.find(params[:q], ‘forumindex’, {:page =>
params[:page], :per_page => per_page})
end

Notice that i have a condition statement for current_account’s on
site_index. Am i doing this wrong? Is there a better way to add
conditions that i’m unaware of?

I do love the benefits of a shared index, but i’m wondering if more
then on index can be written at a time?

thoughts?

Hi Phillip,

basically what you have there should work if you removed the comma
(aaf.rb is a standard ruby file, and each define_index call is just a
statement, so a newline or ‘;’ is what you should use for separation
of these two calls).

If this doesn’t help - what’s the exact error you get (and when - at
application startup, when indexing or when searching?)

Cheers,
Jens

On 01.02.2009, at 22:04, Philip Ingram wrote:

Prategory => {:fields => [:name]}
:ferret => {
per_page = 15

Hi all,
ActsAsFerret::define_index (‘two’…)
[email protected]
Amtsgericht Dresden | HRB 15422
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk


Jens Krämer
Finkenlust 14, 06449 Aschersleben, Germany
VAT Id DE251962952
http://www.jkraemer.net/ - Blog
http://www.omdb.org/ - The new free film database

Hi,

On 11.02.2009, at 05:11, Philip Ingram wrote:

no comma, worked like a charm.

great :slight_smile:

All the hip kids are using sphinx and there was a rumour out there
that ferret hasn’t been worked on for like 2 years. is that true?
if you want to email me directly, i’m fine with that too, but would
love to hear about the direction of the project, and if it’s not
long term, i might as well go with sphinx, rake tasks and delta
indexes and all… i’m launching a new site where search is going
to be prevalent in it, hence these questions.

As you can see on github, the last commit to Ferret’s code base was on
Jan 02 this year: GitHub - dbalmain/ferret: Ferret: the extensible information retrieval library for ruby.

I’m personally using aaf in several projects, among them a knowledge
management system where search also is a key part of the application,
so I’ll for sure continue maintenance and development of the plugin
(as time permits, which in the last few months for sure has been a
problem). Patches are always welcome of course. I also plan to do a
major rewrite of the whole plugin as soon as possible.

Regarding sphinx - while it might be an ok solution for really simple
use cases and also might beat aaf regarding re-indexing time, it
simply doesn’t suit my needs when it comes to more complex scenarios.
Ferret is much more capable regarding supported queries and IR
features in general, and aaf’s Rails integration saves you much of the
maintenance hassles you mentioned. And you aren’t limited to content
stored in the database with Ferret and aaf - I have a project where I
crawl static html via rdig and index a product database, and all can
be searched at once through a simple search form…

Cheers,
Jens


Jens Krämer
Finkenlust 14, 06449 Aschersleben, Germany
VAT Id DE251962952
http://www.jkraemer.net/ - Blog
http://www.omdb.org/ - The new free film database

Thanks Jens,

no comma, worked like a charm.

i now have two shared indexes in aaf.rb.

I’m looking for some reassurance from you and this project. are you
still going to maintain it? i’d love to help down the road, if you’d
let me of course, as ferret/aaf rebuilds the search index when new
items are added, automagically. i’m sure it’s more complicated then
that of course, however, i don’t need to run a rake task and try to
guess when i should run it, depending on how busy my site is.

All the hip kids are using sphinx and there was a rumour out there
that ferret hasn’t been worked on for like 2 years. is that true? if
you want to email me directly, i’m fine with that too, but would love
to hear about the direction of the project, and if it’s not long
term, i might as well go with sphinx, rake tasks and delta indexes and
all… i’m launching a new site where search is going to be prevalent
in it, hence these questions.

thanks again jens,
keep up the great work.
phil

Jens, thanks again for the words.

i’ve got one more question regarding searching by associations with
aaf. Is it possible?

for instance, i have an account model and a forum, with topics and
messages.

I’d love to search by current_account.topics for instance.

Using this shared index, can i do this (mind you it doesn’t work so
i’m wondering if you have any hints?!?!

ActsAsFerret::define_index(‘forumindex’,
:models => {
current_account.topics => {:fields => [:title]},
current_account.messages => {:fields => [:title, :content]}
},
:ferret => {
:default_fields => [:title, :title, :content]
}
)

Thoughts?

Addendum: Although current_account is a controller method in
application.rb, maybe that’s why it won’t work. i just don’t k now
enough to put it in the model however.

thanks
Phil.