Indexing models that are updated in background

28 views
Skip to first unread message

esdevs

unread,
May 23, 2012, 10:07:26 AM5/23/12
to Sunspot
So I am creating new records for a model in the background using
resque (rails app). After the job runs, the new records are not
automatically indexed. If on the front end, I go and edit one of the
new records, then all of the records are then indexed.

What I am looking to do is have the records indexed when they are
added during the background task (so I don't have to do the front end
edit)

Here is the code

background task (upload_data.rb)

class UploadData
@queue = :events_queue
def self.perform(event_id)
event = Event.find(event_id)
CSV.parse($redis.get(event.id)) do |row|
create_friends = event.friends.create(
:first_name => row[0],
:last_name => row[1],
:email => row[2]

etc.

The Friend model is the model that I want to index.

Any help would be greatly appreciated! Thanks!

fred.th...@gmail.com

unread,
May 24, 2012, 7:54:20 AM5/24/12
to ruby-s...@googlegroups.com
you could eve add another Job class to do the SOLR indexing. 


for example you can call this after you create the event

Event.find(event_id).solr_index

or even on the object itself

event.solr_index

Bruno Azisaka Maciel

unread,
May 24, 2012, 9:02:50 AM5/24/12
to ruby-s...@googlegroups.com
Just call event.index! or add an after_save :index! in you model. 

--
Bruno Azisaka Maciel

--
You received this message because you are subscribed to the Google Groups "Sunspot" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ruby-sunspot/-/CkWo5UZKXYQJ.
To post to this group, send email to ruby-s...@googlegroups.com.
To unsubscribe from this group, send email to ruby-sunspot...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ruby-sunspot?hl=en.

Reply all
Reply to author
Forward
0 new messages