Reputation: 32943
I'm using ActsAsFerret which is a Rails wrapper for the Ruby-based Ferret search engine.
Sometimes it seems a record is deleted using SQL, rather than via ActiveRecord (ie record.destroy), and when this happens an index entry is left in the Ferret index.
I can see it in this example, where School #136574 has left a hanging index entry: In the search below I'm using the lazy
option, which says "Just get the data out of the Ferret index and don't bother hitting the database":
>> @schools = School.search(params)
=> [#<FerretResult wrapper for School with id 136574, #<FerretResult wrapper for School with id 55814]
>> @schools.collect(&:id)
ActiveRecord::RecordNotFound: Couldn't find School with ID=136574
This causes a serious problem because if you try and do anything with the results it does School.find(id) and you get an exception like above.
I did School.rebuild_index
, thinking that would fix it, but it hasn't.
I can work around it - it seems that calling .collect
on the results has been overridden to convert them into their corresponding object (causing the exception), and I can do something like this:
@schools = @schools.select{|result| School.find_by_id(result.id)};@schools.size
This does work, but it's slow, and a bit of a pain in the ass.
Does anyone know a way to delete the hanging index records?
Upvotes: 1
Views: 35