Carl Youngblood
2005-Dec-09 01:57 UTC
[Ferret-talk] Index returning ids that are one less than they should be
I''m saving records to an index like so: index << {:id => id, :email => email, :contents => contents, :date => found_on} In debugging my code, it appears that whatever I set a record''s id to, when I find that record in a search, it returns the id minus 1, so if the first record I store in my database has an id of one and I store its counterpart in my index, then when I retrieve it from the index it has an id of zero. Has anybody seen this before? Thanks, Carl
David Balmain
2005-Dec-09 03:23 UTC
[Ferret-talk] Index returning ids that are one less than they should be
On 12/9/05, Carl Youngblood <carl at youngbloods.org> wrote:> I''m saving records to an index like so: > > index << {:id => id, :email => email, :contents => contents, :date => found_on} > > In debugging my code, it appears that whatever I set a record''s id to, > when I find that record in a search, it returns the id minus 1, so if > the first record I store in my database has an id of one and I store > its counterpart in my index, then when I retrieve it from the index it > has an id of zero. Has anybody seen this before?Hi Carl, I think you are talking about the internal index of the document in the Index. The internal indexing of the documents starts from zero and is independent of the id field in your document. The id field in your document is just like any of the other fields as far as the index is concerned. It''s only the Index::Index class that allows you to do special operations on that field. So to see the id field you need to retrieve it like this; index.search_each("your query") do |doc, score| id = index[doc][:id] # do something with the id here. end Hope that helps. You might also want to check out the code here for some more ideas; http://ferret.davebalmain.com/trac/wiki/FerretOnRails Cheers, Dave> Thanks, > Carl > > _______________________________________________ > Ferret-talk mailing list > Ferret-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/ferret-talk >