Forum: Ferret Important issue with [AAF] and :select

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.
Manoel L. (Guest)
on 2007-04-01 23:29
This is important and may be affecting you if you use :select to
minimize the columns you need on big queries.

If you use :select to define which columns you need and you have not
included all the columns you defined in the :acts_as_ferret field
definitions you'll clear the content of those fields on the ferret
index. And that may corrupt your index.

So, if you have in your model:

Class Blog ...
  acts_as_ferret  :fields => {  :title                => {:boost => 2},
                                :sub_title            => {},
                                :url                  => {} }
End

You'll have issues if you do this:

b = Blog.find(:first, :select => "id, author")
b.save

If you want to use :select, you must include the fields AAF needs, like
this:

b = Blog.find(:first, :select => "id, author, title, sub_title, url")
b.save

[]s
John B. (Guest)
on 2007-04-02 00:35
(Received via mailing list)
Wow, that is a very significant issue.

Just to clarify: will saving the object  _overwrite_ previously
indexed columns?
Manoel L. (Guest)
on 2007-04-02 00:40
John B. wrote:
> Wow, that is a very significant issue.
>
> Just to clarify: will saving the object  _overwrite_ previously
> indexed columns?

Yep, in my case I was just updating a unique field in my whole database
and that cleared my index.
Jens K. (Guest)
on 2007-04-02 15:45
(Received via mailing list)
On Sun, Apr 01, 2007 at 10:40:57PM +0200, Manoel L. wrote:
> John B. wrote:
> > Wow, that is a very significant issue.
> >
> > Just to clarify: will saving the object  _overwrite_ previously
> > indexed columns?
>
> Yep, in my case I was just updating a unique field in my whole database
> and that cleared my index.

that's how Ferret works - you just can't update a document once it has
been indexed - aaf simulates updates by deleting the old version and
adding a new version based on the record's data as it is saved.

If anybody knows a way to find out that a record is not fully loaded
because of a :select option was present when it was found, a fix for
this would be easy.


Jens


--
Jens Krämer
webit! Gesellschaft für neue Medien mbH
Schnorrstraße 76 | 01069 Dresden
Telefon +49 351 46766-0 | Telefax +49 351 46766-66
removed_email_address@domain.invalid | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa
Manoel L. (Guest)
on 2007-04-02 15:58
Jens,

There is an easy way to fully load a record when it is not fully loaded
already.
However, I don't know if this is something nice to have as a default on
AAF, since being able to select fields is always good, imagine reloading
big BLOBS everytime you change something and you just want to update the
record name and description.

Maybe you should add a configuration on the field definition, if
:auto_reload => :yes, it will do automatically the full load.

model_object.reload will do the job.

[]s

Manoel
Jens K. (Guest)
on 2007-04-02 16:58
(Received via mailing list)
On Mon, Apr 02, 2007 at 01:58:24PM +0200, Manoel L. wrote:
> :auto_reload => :yes, it will do automatically the full load.
>
> model_object.reload will do the job.

well, I knew of that but of course I only wanted to do the reload if the
record has not been fully loaded initially.

What about that:
You could override the to_doc instance method to check if your record
has been completely loaded, and if not, call reload, and then call
super.

However if you always need to reload your record this way, you'd better
not use :select in the first place and save you the hassles.


Jens


--
Jens Krämer
webit! Gesellschaft für neue Medien mbH
Schnorrstraße 76 | 01069 Dresden
Telefon +49 351 46766-0 | Telefax +49 351 46766-66
removed_email_address@domain.invalid | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa
Manoel L. (Guest)
on 2007-04-02 17:35
Hi Jens, sorry, i didn't understood your question at the begin.
John B. (Guest)
on 2007-04-02 23:02
(Received via mailing list)
On Apr 2, 2007, at 7:44 AM, Jens K. wrote:

> If anybody knows a way to find out that a record is not fully loaded
> because of a :select option was present when it was found, a fix for
> this would be easy.
>

Do you mean, to find out which fields _were_ loaded, and then only
reindex those, maintaining the other previously indexed fields? Is
that possible?

j
John B. (Guest)
on 2007-04-02 23:23
(Received via mailing list)
On Apr 2, 2007, at 2:54 PM, John B. wrote:
> On Apr 2, 2007, at 7:44 AM, Jens K. wrote:
>> If anybody knows a way to find out that a record is not fully loaded
>> because of a :select option was present when it was found, a fix for
>> this would be easy.
> Do you mean, to find out which fields _were_ loaded, and then only
> reindex those, maintaining the other previously indexed fields? Is
> that possible?

If so, then how about:

   MyModel.columns.map(&:name) - myobject.attributes.map{ |k,v| k }

This will show all of the columns that should NOT be reindexed.

But actually, wouldn't it be easier to ONLY index the columns from:

   myobject.attributes.map{ |k,v| k }

?

Cheers,
John
Jens K. (Guest)
on 2007-04-03 12:26
(Received via mailing list)
On Mon, Apr 02, 2007 at 02:54:27PM -0400, John B. wrote:
> that possible?
No, we'll have to load the full record from db before indexing it.

Jens

--
Jens Krämer
webit! Gesellschaft für neue Medien mbH
Schnorrstraße 76 | 01069 Dresden
Telefon +49 351 46766-0 | Telefax +49 351 46766-66
removed_email_address@domain.invalid | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa
This topic is locked and can not be replied to.