search_index.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class User
  3. module SearchIndex
  4. =begin
  5. get data to store in search index
  6. user = User.find(2)
  7. result = user.search_index_data
  8. returns
  9. result = {
  10. attribute1: 'some value',
  11. attribute2: ['value 1', 'value 2'],
  12. ...
  13. }
  14. =end
  15. def search_index_data
  16. attributes = {}
  17. self.attributes.each { |key, value|
  18. next if key == 'created_at'
  19. next if key == 'updated_at'
  20. next if key == 'created_by_id'
  21. next if key == 'updated_by_id'
  22. next if key == 'preferences'
  23. next if key == 'password'
  24. next if !value
  25. next if value.respond_to?('empty?') && value.empty?
  26. attributes[key] = value
  27. }
  28. return if attributes.empty?
  29. if attributes['organization_id']
  30. organization = Organization.lookup(id: attributes['organization_id'])
  31. if organization
  32. attributes['organization'] = organization.name
  33. attributes['organization_ref'] = organization.search_index_data
  34. end
  35. end
  36. attributes
  37. end
  38. end
  39. end