From 20d120a4ef624f2a858d5da2ec70586f67642013 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 28 Jan 2014 08:55:11 +0100 Subject: [PATCH] Added generic lookup of data to store in ES. --- .../application_model/search_index_base.rb | 28 ++++++++++++++++--- app/models/user.rb | 1 + app/models/user/search_index.rb | 26 +++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 app/models/user/search_index.rb diff --git a/app/models/application_model/search_index_base.rb b/app/models/application_model/search_index_base.rb index 57535885f..b60b85c38 100644 --- a/app/models/application_model/search_index_base.rb +++ b/app/models/application_model/search_index_base.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 8de54f8c7..b7c8e5ce9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/models/user/search_index.rb b/app/models/user/search_index.rb new file mode 100644 index 000000000..eb4b8a9c7 --- /dev/null +++ b/app/models/user/search_index.rb @@ -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 \ No newline at end of file