Hope you all are fine and doing good. Few weeks back, I was looking into solr to see if it index multiple attachments! The requirement was very simple: A user will upload multiple files and solr will index those. I tried finding the solutions on the internet but found very basic ones.
Now, I am sharing my experience with you all with some code snippet, which will tell how to index multiple documents/attachments with Solr.
accepts_nested_attributes_for :job_attachments, :allow_destroy => true
searchable :auto_index => false do
So what this code snippet does? Whenever you run
rake sunspot:reindex, it will index multiple files uploaded by a user.
Handling at controller side:
sunspot_str = params[:search]
search = Sunspot.search [Job, JobAttachment] do
fulltext sunspot_str, :minimum_match => 1
puts search_result = search.results
Hope this will help someone! Happy coding