Raul Murciano
2006-Aug-24 17:34 UTC
[Ferret-talk] [0.10.0 - acts_as_ferret] Problem while saving new items
Disclaimer: ferret newbie here, don''t blame too hard. Hi, I''m trying to apply acts_as_ferret to apply search to my Person model: class Person < ActiveRecord::Base validates_presence_of :name, :surname acts_as_ferret :fields => [ ''name'', ''surname'' ] ... But when I try to save a new Person instance I get this error: ferret_create/update: Person : 20 creating doc for class: Person, id: 20 Adding field name with value ''Paul'' to index Adding field surname with value ''Smith'' to index [4;36;1mSQL (0.000755) [0;1mROLLBACK NoMethodError (You have a nil object when you didn''t expect it! The error occured while evaluating nil.commit): /usr/local/lib/ruby/gems/1.8/gems/ferret-0.10.0/lib/ferret/index.rb:203:in `<<'' /usr/local/lib/ruby/1.8/monitor.rb:229:in `synchronize'' /usr/local/lib/ruby/gems/1.8/gems/ferret-0.10.0/lib/ferret/index.rb:186:in `<<'' /vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb:564:in `ferret_create'' Any idea? I''m working with ferret 0.10.0 and the new acts_as_ferret version. Thanks in advance. -- Posted via http://www.ruby-forum.com/.
Raul Murciano
2006-Aug-24 19:47 UTC
[Ferret-talk] [0.10.0 - acts_as_ferret] Problem while saving new items
Well, It seems to work simply replacing this line (203) on /ferret-0.10.0/lib/ferret/index.rb: @writer.commit # original @writer.commit if @writer # patched I''m not sure if the problem comes from acts_as_ferret or is a problem on ferret itself. It''s strange that I am the only affected (saving ActiveRecord items is a so-common operation that acts_as_ferret team have surely tested it before releasing the new version). Can anybody confirm if the patch is needed? And, if so, is it correct? Thanks in advance. -- Posted via http://www.ruby-forum.com/.
Jens Kraemer
2006-Aug-24 20:06 UTC
[Ferret-talk] [0.10.0 - acts_as_ferret] Problem while saving new items
On Thu, Aug 24, 2006 at 09:47:04PM +0200, Raul Murciano wrote:> Well, It seems to work simply replacing this line (203) on > /ferret-0.10.0/lib/ferret/index.rb: > > @writer.commit # original > @writer.commit if @writer # patchedI might be wrong but this doesn''t look ok to me, because it prevents the change the index class intends to make to the index from being written. I have a patch (http://pastie.caboo.se/10032) for ferret''s index.rb file that fixes this issue by adding ensure_writer_open() before the line in question, which initializes the @writer variable if it''s not already present.> I''m not sure if the problem comes from acts_as_ferret or is a problem on > ferret itself. > > It''s strange that I am the only affected (saving ActiveRecord items is a > so-common operation that acts_as_ferret team have surely tested it > before releasing the new version).Well, Ferret 0.10 is still new (and acts_as_ferret is only compatible to it for a day or so) - so you''re probably the first on the list who tried it out :-) I discovered this bug when porting aaf to Ferret 0.10, and made the patch. I should have communicated that when announcing the 0.10 compatibility, but I forgot... I think Dave will release a fixed gem soon, so the patch won''t be necessary for a long time. Jens -- webit! Gesellschaft f?r neue Medien mbH www.webit.de Dipl.-Wirtschaftsingenieur Jens Kr?mer kraemer at webit.de Schnorrstra?e 76 Tel +49 351 46766 0 D-01069 Dresden Fax +49 351 46766 66
Jens Kraemer
2006-Aug-24 20:11 UTC
[Ferret-talk] [0.10.0 - acts_as_ferret] Problem while saving new items
On Thu, Aug 24, 2006 at 07:34:05PM +0200, Raul Murciano wrote:> Disclaimer: ferret newbie here, don''t blame too hard. > > Hi, I''m trying to apply acts_as_ferret to apply search to my Person > model: > > class Person < ActiveRecord::Base > validates_presence_of :name, :surname > acts_as_ferret :fields => [ ''name'', ''surname'' ]As of Ferret 0.10, you should use symbols only as field names. Jens -- webit! Gesellschaft f?r neue Medien mbH www.webit.de Dipl.-Wirtschaftsingenieur Jens Kr?mer kraemer at webit.de Schnorrstra?e 76 Tel +49 351 46766 0 D-01069 Dresden Fax +49 351 46766 66
Raul Murciano
2006-Aug-24 20:18 UTC
[Ferret-talk] [0.10.0 - acts_as_ferret] Problem while saving new items
> I might be wrong but this doesn''t look ok to me, because it prevents > the change the index class intends to make to the index from being > written.As a completely ruby/rails/ferret newbie I also thought that my try was wrong but I had to try ;)> I have a patch (http://pastie.caboo.se/10032) for ferret''s index.rb file > that fixes this issue by adding ensure_writer_open() before the line in > question, which initializes the @writer variable if it''s not already > present.Thanks for your patch! I will apply it until the new gem release.> I think Dave will release a fixed gem soon, so the patch won''t be > necessary for a long time.I hope so :)> As of Ferret 0.10, you should use symbols only as field names.Great tip! Thank you very much Jens! -- Posted via http://www.ruby-forum.com/.
David Balmain
2006-Aug-25 15:16 UTC
[Ferret-talk] [0.10.0 - acts_as_ferret] Problem while saving new items
On 8/25/06, Jens Kraemer <kraemer at webit.de> wrote:> On Thu, Aug 24, 2006 at 09:47:04PM +0200, Raul Murciano wrote: > > Well, It seems to work simply replacing this line (203) on > > /ferret-0.10.0/lib/ferret/index.rb: > > > > @writer.commit # original > > @writer.commit if @writer # patched > > I might be wrong but this doesn''t look ok to me, because it prevents > the change the index class intends to make to the index from being > written.Actually, as the code is now, I think Raul''s patch will also work. I would expect the error to be happening when :auto_flush is set to true which would cause @writer to be closed after the delete method has been called. The commit isn''t necessary if @writer has already been closed since a commit happens automatically when the writer is closed. It made me realize that I may as well call @writer''s delete method directly in the add_document method. Thank you both of you. Cheers, Dave