Cannot delete for id of type Array

Hello list,

I have a little weird error when deleting documents from the index.

I’m using the following code.

ferret_index = Ferret::Index::Index.new(:path => FERRET_INDEX_PATH)
query = Ferret::Search::TermQuery.new(:fk_file_id, “#{_fk_file_id}”)
ferret_index.search_each(query) do | id |
ferret_index.delete(id)
end

And I get the following error
Cannot delete for id of type Array

As I see it the only way this could happened is if search_each
returns an Array of ID’s but it couldn’t right?

I’m using version 0.11.3.

Regards,
Henrik

On Wed, Mar 21, 2007 at 10:56:42PM +0100, Henrik Z. wrote:

end

And I get the following error
Cannot delete for id of type Array

As I see it the only way this could happened is if search_each
returns an Array of ID’s but it couldn’t right?

from the api docs:
search_each(query, options = {}) {|doc, score| …}

you see that ferret hands you two arguments into the block.

Now if you only accept one parameter, Ruby guesses that you want
all parameters as an array. This should yield a warning like
‘multiple values for a block parameter (2 for 1)’
somewhere in your logs.

So just use |id, score| and everything should be fine :slight_smile:

cheers,
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
[email protected] | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa

21 mar 2007 kl. 23:17 skrev Jens K.:

ferret_index.delete(id)
search_each(query, options = {}) {|doc, score| …}

you see that ferret hands you two arguments into the block.

Now if you only accept one parameter, Ruby guesses that you want
all parameters as an array. This should yield a warning like
‘multiple values for a block parameter (2 for 1)’
somewhere in your logs.

So just use |id, score| and everything should be fine :slight_smile:
So its that ruby magic trying to figure out what I want again. =)
I was afraid that only using id and not score could be the problem
but I couldn’t see why. Now I know!

Thanks!

Henrik Z. wrote:

ferret_index = Ferret::Index::Index.new(:path => FERRET_INDEX_PATH)
query = Ferret::Search::TermQuery.new(:fk_file_id, “#{_fk_file_id}”)
ferret_index.search_each(query) do | id |
ferret_index.delete(id)
end

This way is a little more direct (untested):

ferret_index = Ferret::Index::IndexWriter.new(:path =>FERRET_INDEX_PATH)
ferret_index.delete(:fk_file_id, _fk_file_id)

Does not work. Delete method only takes 1 argument.

Cheers
22 mar 2007 kl. 01:46 skrev Caleb C.:

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