# Two Shared Indices(sp?) in aaf.rb file (for Acts\_as\_ferret)

**URL:** <https://www.ruby-forum.com/t/two-shared-indices-sp-in-aaf-rb-file-for-acts-as-ferret/159164>\
**Category:** Ferret\
**Created:** [February 1, 2009, 6:19pm UTC](https://www.ruby-forum.com/t/two-shared-indices-sp-in-aaf-rb-file-for-acts-as-ferret/159164 "2009-02-01T18:19:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Philip\_Ingram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/58f4c7/32.png) [@Philip\_Ingram](https://www.ruby-forum.com/u/Philip_Ingram)\
**Post date:** [February 1, 2009, 6:19pm UTC](https://www.ruby-forum.com/t/two-shared-indices-sp-in-aaf-rb-file-for-acts-as-ferret/159164/1 "2009-02-01T18:19:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Philip\_Ingram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/58f4c7/32.png) [@Philip\_Ingram](https://www.ruby-forum.com/u/Philip_Ingram)\
**Post date:** [February 1, 2009, 9:03pm UTC](https://www.ruby-forum.com/t/two-shared-indices-sp-in-aaf-rb-file-for-acts-as-ferret/159164/2 "2009-02-01T21:03:14Z")

</div>

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  
> removed\_email\_address@domain.invalid  
> [http://rubyforge.org/mailman/listinfo/ferret-talk](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  
removed\_email\_address@domain.invalid | [www.webit.de](http://www.webit.de)

Amtsgericht Dresden | HRB 15422  
GF Sven Haubold

---

<div class="post-metadata">

**Author:** ![Philip\_Ingram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/58f4c7/32.png) [@Philip\_Ingram](https://www.ruby-forum.com/u/Philip_Ingram)\
**Post date:** [February 1, 2009, 10:15pm UTC](https://www.ruby-forum.com/t/two-shared-indices-sp-in-aaf-rb-file-for-acts-as-ferret/159164/3 "2009-02-01T22:15:02Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Philip\_Ingram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/58f4c7/32.png) [@Philip\_Ingram](https://www.ruby-forum.com/u/Philip_Ingram)\
**Post date:** [February 10, 2009, 10:46am UTC](https://www.ruby-forum.com/t/two-shared-indices-sp-in-aaf-rb-file-for-acts-as-ferret/159164/4 "2009-02-10T10:46:11Z")

</div>

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’…)  
> > > removed\_email\_address@domain.invalid  
> > > Amtsgericht Dresden | HRB 15422  
> > > Ferret-talk mailing list  
> > > removed\_email\_address@domain.invalid  
> > > [http://rubyforge.org/mailman/listinfo/ferret-talk](http://rubyforge.org/mailman/listinfo/ferret-talk)

–  
Jens KrÃ¤mer  
Finkenlust 14, 06449 Aschersleben, Germany  
VAT Id DE251962952  
[http://www.jkraemer.net/](http://www.jkraemer.net/) - Blog  
[http://www.omdb.org/](http://www.omdb.org/) - The new free film database

---

<div class="post-metadata">

**Author:** ![Philip\_Ingram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/58f4c7/32.png) [@Philip\_Ingram](https://www.ruby-forum.com/u/Philip_Ingram)\
**Post date:** [February 11, 2009, 10:58am UTC](https://www.ruby-forum.com/t/two-shared-indices-sp-in-aaf-rb-file-for-acts-as-ferret/159164/5 "2009-02-11T10:58:21Z")

</div>

Hi,

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

> no comma, worked like a charm.

great 🙂

> 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.](http://github.com/dbalmain/ferret/tree/master)

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/](http://www.jkraemer.net/) - Blog  
[http://www.omdb.org/](http://www.omdb.org/) - The new free film database

---

<div class="post-metadata">

**Author:** ![Philip\_Ingram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/58f4c7/32.png) [@Philip\_Ingram](https://www.ruby-forum.com/u/Philip_Ingram)\
**Post date:** [February 11, 2009, 5:51am UTC](https://www.ruby-forum.com/t/two-shared-indices-sp-in-aaf-rb-file-for-acts-as-ferret/159164/6 "2009-02-11T05:51:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Philip\_Ingram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/58f4c7/32.png) [@Philip\_Ingram](https://www.ruby-forum.com/u/Philip_Ingram)\
**Post date:** [February 24, 2009, 2:43am UTC](https://www.ruby-forum.com/t/two-shared-indices-sp-in-aaf-rb-file-for-acts-as-ferret/159164/7 "2009-02-24T02:43:41Z")

</div>

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.
