Added generic lookup of data to store in ES.

This commit is contained in:
Martin Edenhofer 2014-01-28 08:55:11 +01:00
parent e16a7be11d
commit 20d120a4ef
3 changed files with 51 additions and 4 deletions

View file

@ -55,6 +55,28 @@ returns
end
end
=begin
get data to store in search index
ticket = Ticket.find(123)
result = ticket.search_index_data
returns
result = true # false
=end
def search_index_data
data = []
['name', 'note'].each { |key|
data.push self[key] if self[key]
}
return data[0] if !data[1]
data
end
private
=begin
@ -92,10 +114,8 @@ returns
# get name of ref object
value = nil
if relation_model['name']
value = relation_model['name']
elsif relation_model.respond_to?('fullname')
value = relation_model.send('fullname')
if relation_model.respond_to?('search_index_data')
value = relation_model.send('search_index_data')
end
next if !value

View file

@ -5,6 +5,7 @@ require 'digest/md5'
class User < ApplicationModel
include User::Assets
extend User::Search
include User::SearchIndex
before_create :check_name, :check_email, :check_login, :check_image, :check_password
before_update :check_password, :check_image, :check_email, :check_login_update

View file

@ -0,0 +1,26 @@
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
module User::SearchIndex
=begin
get data to store in search index
user = User.find(123)
result = user.search_index_data
returns
result = true # false
=end
def search_index_data
data = []
data.push "#{ self['firstname'] } #{ self['lastname'] }"
['login', 'firstname', 'lastname', 'phone', 'email', 'city', 'country', 'note'].each { |key|
data.push self[key] if self[key]
}
data
end
end