Forum: Ferret imdex.update is 10 times slower than index.add_doc. Normal?

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.
28c65753eb8f8288f2d97c9d86fb5d02?d=identicon&s=25 Sergei Serdyuk (Guest)
on 2006-05-19 22:04
Hi,

I am seeing that

doc = index['mykey']
index.update 'mykey', doc

is about 10 times slower than
doc = Document.new
doc['id'] = 'mykey'
index << doc

It looks like #update is _much_ slower that #<<. Is it as expected?

Sergei.
B5e329ffa0cc78efbfc7ae2d084c149f?d=identicon&s=25 David Balmain (Guest)
on 2006-05-20 02:11
(Received via mailing list)
On 5/20/06, Sergei Serdyuk <sergei@redleafsoft.com> wrote:
> index << doc
>
> It looks like #update is _much_ slower that #<<. Is it as expected?

Hi Sergei,

Yes, it is expected. When you use update it  has to lookup the
document with the same id. It then checks each field in the document
to see which fields have been changed and updates then. It deletes the
old document and adds the new one.  This also means that it has to
open an IndexReader and then closes it and opens an IndexWriter. This
is a lot of processing. If you want fast update then you need to do it
yourself. Just adding a document doesn't even open and IndexReader so
it is going to be faster then updating a document no matter how you do
it. The fastest way to update documents is in a batch. So if you want
to update 10 documents., delete all 10 together, then add the 10
updated documents together.

Hope that helps,
Dave
This topic is locked and can not be replied to.