Guest User

Untitled

a guest
May 21st, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. # Hook our MongoMapper model into Solr
  2. module MongoAdapter
  3. class InstanceAdapter < Sunspot::Adapters::InstanceAdapter
  4. def id
  5. @instance.id
  6. end
  7. end
  8.  
  9. class DataAccessor < Sunspot::Adapters::DataAccessor
  10. def load(id)
  11. @clazz.find(id)
  12. end
  13. end
  14. end
  15.  
  16. Sunspot::Adapters::DataAccessor.register(MongoAdapter::DataAccessor, User)
  17. Sunspot::Adapters::InstanceAdapter.register(MongoAdapter::InstanceAdapter, User)
  18.  
  19. Sunspot.setup(User) do
  20. text :name
  21. text :screen_name
  22. text :description
  23.  
  24. string :screen_name
  25.  
  26. string :flists, :multiple => true do
  27. listed_on.map{|l| l.keys.first.downcase.split(/-|_|\//)}.flatten
  28. end
  29.  
  30. dynamic_text :lists do
  31. count = 0
  32. listed_on.inject({}) do |hash, l|
  33. hash["#{count}_#{l.keys.first}".to_sym] = {
  34. :value => l.keys.first,
  35. :boost => l.values.first == 0 ? 1 : l.values.first
  36. }
  37. count += 1
  38. hash
  39. end
  40. end
  41. end
Add Comment
Please, Sign In to add comment