Streamline of index attributes.

This commit is contained in:
Martin Edenhofer 2015-10-18 17:20:09 +02:00
parent a6826a9166
commit 632d879e2c
4 changed files with 5 additions and 52 deletions

View file

@ -18,11 +18,7 @@ returns
return if !self.class.search_index_support_config return if !self.class.search_index_support_config
# default ignored attributes # default ignored attributes
ignore_attributes = { ignore_attributes = {}
created_by_id: true,
updated_by_id: true,
active: true,
}
if self.class.search_index_support_config[:ignore_attributes] if self.class.search_index_support_config[:ignore_attributes]
self.class.search_index_support_config[:ignore_attributes].each {|key, value| self.class.search_index_support_config[:ignore_attributes].each {|key, value|
ignore_attributes[key] = value ignore_attributes[key] = value
@ -45,15 +41,7 @@ returns
return if !attributes return if !attributes
# update backend # update backend
if self.class.column_names.include? 'active'
if active
SearchIndexBackend.add(self.class.to_s, attributes) SearchIndexBackend.add(self.class.to_s, attributes)
else
SearchIndexBackend.remove( self.class.to_s, id )
end
else
SearchIndexBackend.add( self.class.to_s, attributes )
end
end end
=begin =begin

View file

@ -18,11 +18,7 @@ returns
return if !self.class.search_index_support_config return if !self.class.search_index_support_config
# default ignored attributes # default ignored attributes
ignore_attributes = { ignore_attributes = {}
created_by_id: true,
updated_by_id: true,
active: true,
}
if self.class.search_index_support_config[:ignore_attributes] if self.class.search_index_support_config[:ignore_attributes]
self.class.search_index_support_config[:ignore_attributes].each {|key, value| self.class.search_index_support_config[:ignore_attributes].each {|key, value|
ignore_attributes[key] = value ignore_attributes[key] = value
@ -62,7 +58,7 @@ returns
article_attributes = article.attributes article_attributes = article.attributes
# remove note needed attributes # remove note needed attributes
ignore = %w(created_by_id updated_by_id updated_at references message_id_md5 message_id in_reply_to ticket_id) ignore = %w(message_id_md5)
ignore.each {|attribute| ignore.each {|attribute|
article_attributes.delete( attribute ) article_attributes.delete( attribute )
} }

View file

@ -28,7 +28,6 @@ class User < ApplicationModel
load 'user/assets.rb' load 'user/assets.rb'
include User::Assets include User::Assets
extend User::Search extend User::Search
include User::SearchIndex
before_create :check_name, :check_email, :check_login, :check_password before_create :check_name, :check_email, :check_login, :check_password
before_update :check_password, :check_email, :check_login before_update :check_password, :check_email, :check_login

View file

@ -1,30 +0,0 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class User
module 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
attributes = { 'fullname' => "#{self['firstname']} #{self['lastname']}" }
%w(login firstname lastname phone email address city country note created_at).each { |key|
if self[key] && (!self.respond_to?('empty?') || !self[key].empty?)
attributes[key] = self[key]
end
}
return if attributes.empty?
attributes
end
end
end