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 Zagerholm wrote:> 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?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 :-) 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 kraemer at webit.de | www.webit.de Amtsgericht Dresden | HRB 15422 GF Sven Haubold, Hagen Malessa
Henrik Zagerholm 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) > endThis 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)
21 mar 2007 kl. 23:17 skrev Jens Kraemer:> On Wed, Mar 21, 2007 at 10:56:42PM +0100, Henrik Zagerholm wrote: >> 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? > > 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 :-)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!> > 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 > kraemer at webit.de | www.webit.de > > Amtsgericht Dresden | HRB 15422 > GF Sven Haubold, Hagen Malessa > _______________________________________________ > Ferret-talk mailing list > Ferret-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/ferret-talk
Does not work. Delete method only takes 1 argument. Cheers 22 mar 2007 kl. 01:46 skrev Caleb Clausen:> Henrik Zagerholm 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) > _______________________________________________ > Ferret-talk mailing list > Ferret-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/ferret-talk