Topic: Bulk Delete Records from both Search Index and Kete Application

Topic type:

If you have added a number of records by mistake (say during a bulk import) and want to remove them in one go, here's how. This tip requires that you are a technical support person for Kete with console access to the server that Kete resides one.

Have you had a bulk import go wrong?  Need to delete a large amount of items from your Kete site?  Here's how to do it if you are technically savvy.

Note: this assumes that you are trying to get one type of thing, images, otherwise known as records of class StillImage in Kete.  You'll have to adjust these directions to suit your needs if your circumstances differ.  There is absolutely no warranty on this guide, use at your own risk and back up everything first.  You are deleting things in bulk!

First, you need to connect to your site's "irb console".  See http://edgeguides.rubyonrails.org/command_line.html for details about what this means and how to connect to it.

In essence, if you are connecting to your production environment, first go to your apps rails root directory and do this:

$ script/console production

You should get a something like this:

Loading production environment (Rails 2.1.0)
...
>>

First, you have to choose which Zebra database is appropriate to delete from, in my case this is the 'public' db.  Then you have to compose what group of items.  In my case, that is records of type StillImage that have ids over the number 15.  Then I cycle through each and retrieve the record's xml from the search engine, tell the search engine to delete the record from the index and finally delete the active record instance from the Kete web application.  Here's the code:

Kete 1.1 or earlier

>> zoom_db = ZoomDb.find_by_database_name('public')
...
>> StillImage.find(:all, :conditions => "id > 15").each do |still_image|
?> results = zoom_db.process_query(:query => "@attr 1=12 \"StillImage:#{still_image.id.to_s}\"")
>> zoom_db.destroy_this(results[0], still_image.zoom_id.gsub("::", ":#{still_image.basket.urlified_name}:"))
>> still_image.destroy
>> end
>> exit

Kete 1.2 or later

>> zoom_db = ZoomDb.find_by_database_name('public')
>> StillImage.all(:conditions => "id > 15").each do |still_image|
?> zoom_db.destroy_identified_by(still_image.zoom_id)
?> still_image.destroy
>> end
>> exit

Clear Cache

Back in your app's rails root directory, you'll want to clear your caches if you are in production mode.  Like so:

$ rake tmp:cache:clear

Discuss This Topic

There are 0 comments in this discussion.

join this discussion

Tags

Creative Commons Attribution-Share Alike 3.0 New Zealand License
Bulk Delete Records from both Search Index and Kete Application by Walter McGinnis is licensed under a Creative Commons Attribution-Share Alike 3.0 New Zealand License