Forum: Ferret Multiple Models w/ acts_as_ferret

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.
7a5ed48939fc288a4c70778140b203f6?d=identicon&s=25 A. Roth (Guest)
on 2006-02-28 06:58
I have multiple models all with:

acts_as_ferret :fields => [...]

(models = profiles, blogs, comments )


When I restart the server and perform any crud operation on one of the
above models, the index is created/updated.  If I then go and perform
any crud operation on ANOTHER model, ...the index from that first model
is being updated.

Any ideas? Can acts_as_ferret handle this?


Thanks
Adam
B5e329ffa0cc78efbfc7ae2d084c149f?d=identicon&s=25 David Balmain (Guest)
on 2006-02-28 12:09
(Received via mailing list)
On 2/28/06, A. Roth <adamjroth@gmail.com> wrote:
> is being updated.
>
> Any ideas? Can acts_as_ferret handle this?

Hi Adam,

I'm assuming here that you used the acts_as_ferret code on the lower
part of this page;

http://ferret.davebalmain.com/trac/wiki/FerretOnRails

There should only be one index for all models, not one index each.
Each document in the index contains a ferret_class field which will
contain the name of the model so searches on a specific model will
only find documents for that model. I hope that makes sense. Basically
there should be one index that gets updated whenever any of the models
are updated.

Cheers,
Dave
7a5ed48939fc288a4c70778140b203f6?d=identicon&s=25 Adam Roth (Guest)
on 2006-02-28 16:11
Hi David,

Yes.. that makes sense.  Why, however, are there directories created for
each model in RAILS_ROOT/index/RAILS_ENV if only one is needed?  The
first model hit will be the index that is written to for all models
(like I had mentioned). Is that correct? For example:

- I start up the server
- A "blog" page is hit and updated
- The index in RAILS_ROOT/index/Development/Blog is updated
- A "comment" page is updated
- The index is RAILS_ROOT/index/Development/Blog is updated again,
despite there being a /Development/Comment dir.

I'm probably missing something. I would appriciate if you could fill in
my understanding based on my comments above.

Thanks you in advance.

Adam




David Balmain wrote:
> On 2/28/06, A. Roth <adamjroth@gmail.com> wrote:
>> is being updated.
>>
>> Any ideas? Can acts_as_ferret handle this?
>
> Hi Adam,
>
> I'm assuming here that you used the acts_as_ferret code on the lower
> part of this page;
>
> http://ferret.davebalmain.com/trac/wiki/FerretOnRails
>
> There should only be one index for all models, not one index each.
> Each document in the index contains a ferret_class field which will
> contain the name of the model so searches on a specific model will
> only find documents for that model. I hope that makes sense. Basically
> there should be one index that gets updated whenever any of the models
> are updated.
>
> Cheers,
> Dave
7a5ed48939fc288a4c70778140b203f6?d=identicon&s=25 aroth (Guest)
on 2006-02-28 23:21
Also, I was using the version found here:

 https://svn.jkraemer.net/svn/projects/ferret-demo/...

His changelog mentions how the index per model structure... should I be
using the one on the wiki page?

Adam
B5e329ffa0cc78efbfc7ae2d084c149f?d=identicon&s=25 David Balmain (Guest)
on 2006-03-01 00:35
(Received via mailing list)
Hi Adam,

That version is supposed to work with seperate indexes. I had a quick
look at the code but I'm not sure what is wrong. Perhaps you could
drop Jens an email about it. Or you could try the other acts_as_ferret
plugin. Sorry I can't be of more help.

Cheers,
Dave
B5e329ffa0cc78efbfc7ae2d084c149f?d=identicon&s=25 David Balmain (Guest)
on 2006-03-01 00:37
(Received via mailing list)
One other thing. When you say the blog index is being updated when you
modify comments, does that mean only the blog index ever gets updated?
Does the comments index remains empty?
3801fd43acf8d326679ae27aa865a11c?d=identicon&s=25 Thomas Lockney (Guest)
on 2006-03-01 00:39
aroth wrote:
> Also, I was using the version found here:
>
>  https://svn.jkraemer.net/svn/projects/ferret-demo/...
>

Actually, I believe he merged bits and pieces from both versions on the
wiki along with some of his own changes. I haven't looked closely at the
code, yet, but I from an initial glance it looks like it incorporates my
additions pretty cleanly. I'm not quite certain why you would be seeing
the behavior described. Could you post some snippets from your code
(like the acts_as_ferret lines from each model and any configuration
from environment.rb)?

Jens just recently set up this SVN repository and gave Kasper and I
access to it for furthur updates -- this will be the source for future
versions of the plugin. One of us will hopefully be updating the wiki
soon to reflect this.

Thomas
7a5ed48939fc288a4c70778140b203f6?d=identicon&s=25 Adam Roth (Guest)
on 2006-03-01 06:50
David Balmain wrote:
> One other thing. When you say the blog index is being updated when you
> modify comments, does that mean only the blog index ever gets updated?
> Does the comments index remains empty?

I used the second block of code on the wiki and it now works with 1
index... however, I can't seem to get any results back. Editing any of
the models forces the index to update, so I know something is going on.
Hopefully you guys can answer a few questions:

1. Are all the "fields" of a model indexed? When I used that
acts_as_ferret code from the svn repository, I had to specify the
fields. And despite the problems, I was also getting results back.

2. Is there a way to limit the results that you get back? (IE, limit to
10, or pass a limit/offset for paging).

3. Is there a way I can "dump" the information Ferret has indexed so
that I can see if the correct data is there? I'd like to figure out why
no results are coming back from:

  def test_ferret
    @results = Comment.find_by_contents( params['query'] )
    render_text @results.inspect
  end

Thanks again.
Adam
C9dd93aa135988cabf9183d3210665ca?d=identicon&s=25 Jens Kraemer (Guest)
on 2006-03-01 15:23
(Received via mailing list)
On Wed, Mar 01, 2006 at 06:50:46AM +0100, Adam Roth wrote:
>
> 3. Is there a way I can "dump" the information Ferret has indexed so
> that I can see if the correct data is there? I'd like to figure out why
> no results are coming back from:
>
>   def test_ferret
>     @results = Comment.find_by_contents( params['query'] )
>     render_text @results.inspect
>   end

you can use Luke (http://www.getopt.org/luke/) to inspect an existing
ferret index.

I'll try to reproduce and fix the problems you had concerning multiple
indexes/classes with the acts_as_ferret version from the svn repository.

Jens

--
webit! Gesellschaft für neue Medien mbH          www.webit.de
Dipl.-Wirtschaftsingenieur Jens Krämer       kraemer@webit.de
Schnorrstraße 76                         Tel +49 351 46766  0
D-01069 Dresden                          Fax +49 351 46766 66
33c532e9698faf94d565f5c7ca37b041?d=identicon&s=25 Lee Marlow (Guest)
on 2006-03-01 18:19
(Received via mailing list)
We have also been using our own version of acts_as_ferret, put
together from the wiki and a version that was on the rails mailing
list.  We added a simple rake task for rebuilding the index and
pagination.  We kept the one index for all models as I expect Ferret
to be fast enough to handle it and maybe we'll want to query across
models one day.

I tried to checkout the code from
https://svn.jkraemer.net/svn/projects/ferret-demo/...
but it is requiring a username and password, even though I can access
it fine through the web.  I was hoping I could send you some diffs for
some of the things we've done.  Is there a guest account I could use
to checkout?

Thanks

-Lee
C9dd93aa135988cabf9183d3210665ca?d=identicon&s=25 Jens Kraemer (Guest)
on 2006-03-01 19:07
(Received via mailing list)
On Wed, Mar 01, 2006 at 10:18:10AM -0700, Lee Marlow wrote:
> it fine through the web.  I was hoping I could send you some diffs for
> some of the things we've done.  Is there a guest account I could use
> to checkout?

Ooops, my mistake, read-only access via svn should work now without any
authentication.

patches are welcome of course :-)

btw: I just fixed the issue reported in this thread.

Jens



--
webit! Gesellschaft für neue Medien mbH          www.webit.de
Dipl.-Wirtschaftsingenieur Jens Krämer       kraemer@webit.de
Schnorrstraße 76                         Tel +49 351 46766  0
D-01069 Dresden                          Fax +49 351 46766 66
C9dd93aa135988cabf9183d3210665ca?d=identicon&s=25 Jens Kraemer (Guest)
on 2006-03-01 23:14
(Received via mailing list)
On Wed, Mar 01, 2006 at 06:50:46AM +0100, Adam Roth wrote:
[..]
> 1. Are all the "fields" of a model indexed? When I used that
> acts_as_ferret code from the svn repository, I had to specify the
> fields. And despite the problems, I was also getting results back.

You have to specify the fields when using the second code snippet from
the wiki, too. If no fields are specified, only the id and the class
name will be indexed.

> 2. Is there a way to limit the results that you get back? (IE, limit to
> 10, or pass a limit/offset for paging).

I just added this to the svn version of the plugin.
You can have a look at test/unit/content_test.rb from the demo project
(https://svn.jkraemer.net/svn/projects/ferret-demo/...)
for an example.

As the other issue concerning multiple indexes is now fixed, too, you
could give the svn version another try.

Regards,
Jens

--
webit! Gesellschaft für neue Medien mbH          www.webit.de
Dipl.-Wirtschaftsingenieur Jens Krämer       kraemer@webit.de
Schnorrstraße 76                         Tel +49 351 46766  0
D-01069 Dresden                          Fax +49 351 46766 66
7a5ed48939fc288a4c70778140b203f6?d=identicon&s=25 aroth (Guest)
on 2006-03-02 18:49
Jens,

Your fix works great. Thank you. Another quick question. I notice the
"rebuild_index.rb" in the plugin dir. If I try to run this directly, it
doesnt want to run (complains about not being able to require 'ferret').
Anyway, I'd like to know how I can use Ferret or acts_as_ferret to index
all of my existing content based on the fields/models I have declared as
'acts_as_ferret'. Right now, they are added to the index after any CRUD
operation -- is there a way to force this outside of the scope of the
web?

Thanks
Adam
33c532e9698faf94d565f5c7ca37b041?d=identicon&s=25 Lee Marlow (Guest)
on 2006-03-03 00:24
(Received via mailing list)
Here is our rake task which uses a slightly different version of
acts_as_ferret.  It will try to load up all models in app/models and
call ferret_update on each instance.
Abb249055208c7af4d35568e422dfd63?d=identicon&s=25 Guest (Guest)
on 2006-07-11 19:28
So is it correct then that you have to use inheritance to get it to work
across multiple models?

Lee Marlow wrote:
> Here is our rake task which uses a slightly different version of
> acts_as_ferret.  It will try to load up all models in app/models and
> call ferret_update on each instance.
This topic is locked and can not be replied to.