Global index and write lock issues

I’m attempting to get ferret working with Ruby on Rails. I’ve declared
an index in a custom environment:

module FerretConfig
include Ferret
INDEX = Index::Index.new(:path => File.join(RAILS_ROOT, ‘search’))
end

And I access this index through my Document model:

def after_save
index = FerretConfig::INDEX
index << self.to_doc
index.optimize
end

This works fine with the first document I upload and index. But when I
attempt to upload a second document:

: Error occured at <index_rw.c>:703
Error: exception 6 not handled: Could not obtain write lock when trying
to write index

It seems that an index must be closed before it will give up its write
lock. Is that accurate? Does the index have to be reinitialised every
time one wishes to write to it? Would it be better to do something like:

def after_save
index = Index::Index.new(:path => File.join(RAILS_ROOT, ‘search’))
index << self.to_doc
index.optimize
index.close
end

And if so, wouldn’t that be somewhat inefficient, if the index is being
continually opened and closed?

Thanks in advance,

  • James Reeves

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs