Improved es behaviours.
This commit is contained in:
parent
16ace88400
commit
604e0575dd
4 changed files with 53 additions and 29 deletions
|
@ -30,15 +30,19 @@ returns
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# for performance reasons, Model.search_index_reload will only collect if of object
|
||||||
|
# get whole data here
|
||||||
|
data = self.class.find(self.id)
|
||||||
|
|
||||||
# remove ignored attributes
|
# remove ignored attributes
|
||||||
attributes = self.attributes
|
attributes = data.attributes
|
||||||
ignore_attributes.each {|key, value|
|
ignore_attributes.each {|key, value|
|
||||||
next if value != true
|
next if value != true
|
||||||
attributes.delete( key.to_s )
|
attributes.delete( key.to_s )
|
||||||
}
|
}
|
||||||
|
|
||||||
# fill up with search data
|
# fill up with search data
|
||||||
attributes = search_index_attribute_lookup(attributes, self)
|
attributes = search_index_attribute_lookup(attributes, data)
|
||||||
return if !attributes
|
return if !attributes
|
||||||
|
|
||||||
# update backend
|
# update backend
|
||||||
|
|
|
@ -30,7 +30,12 @@ returns
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
attributes = self.attributes
|
# for performance reasons, Model.search_index_reload will only collect if of object
|
||||||
|
# get whole data here
|
||||||
|
ticket = self.class.find(self.id)
|
||||||
|
|
||||||
|
# remove ignored attributes
|
||||||
|
attributes = ticket.attributes
|
||||||
ignore_attributes.each {|key, value|
|
ignore_attributes.each {|key, value|
|
||||||
next if value != true
|
next if value != true
|
||||||
attributes.delete( key.to_s )
|
attributes.delete( key.to_s )
|
||||||
|
@ -42,43 +47,58 @@ returns
|
||||||
attributes[:tag] = tags
|
attributes[:tag] = tags
|
||||||
end
|
end
|
||||||
|
|
||||||
attributes = search_index_attribute_lookup( attributes, self )
|
# lookup attributes of ref. objects (normally name and note)
|
||||||
|
attributes = search_index_attribute_lookup( attributes, ticket )
|
||||||
|
|
||||||
# add article data
|
# list ignored file extentions
|
||||||
|
ignore_attachments = [ '.png', '.jpg', '.jpeg', '.mpeg', '.mov' ]
|
||||||
|
|
||||||
|
# collect article data
|
||||||
articles = Ticket::Article.where( :ticket_id => self.id )
|
articles = Ticket::Article.where( :ticket_id => self.id )
|
||||||
attributes['articles_all'] = []
|
attributes['articles_all'] = []
|
||||||
attributes['articles_external'] = []
|
|
||||||
articles.each {|article|
|
articles.each {|article|
|
||||||
article_attributes = article.attributes
|
article_attributes = article.attributes
|
||||||
article_attributes.delete('created_by_id')
|
|
||||||
article_attributes.delete('updated_by_id')
|
# remove note needed attributes
|
||||||
article_attributes.delete('updated_at')
|
ignore = ['created_by_id', 'updated_by_id', 'updated_at', 'references', 'message_id_md5', 'message_id', 'in_reply_to', 'ticket_id']
|
||||||
article_attributes.delete('references')
|
ignore.each {|attribute|
|
||||||
article_attributes.delete('message_id_md5')
|
article_attributes.delete( attribute )
|
||||||
article_attributes.delete('message_id')
|
}
|
||||||
article_attributes.delete('in_reply_to')
|
|
||||||
article_attributes.delete('ticket_id')
|
# lookup attributes of ref. objects (normally name and note)
|
||||||
article_attributes = search_index_attribute_lookup( article_attributes, article )
|
article_attributes = search_index_attribute_lookup( article_attributes, article )
|
||||||
|
|
||||||
|
# index raw text body
|
||||||
|
if article_attributes['content_type'] && article_attributes['content_type'] == 'text/html' && article_attributes['body']
|
||||||
|
article_attributes['body'] = article_attributes['body'].html2text
|
||||||
|
end
|
||||||
|
|
||||||
# lookup attachments
|
# lookup attachments
|
||||||
article.attachments.each {|attachment|
|
article.attachments.each {|attachment|
|
||||||
if !article_attributes['attachments']
|
if !attributes['attachments']
|
||||||
article_attributes['attachments'] = []
|
attributes['attachments'] = []
|
||||||
|
end
|
||||||
|
|
||||||
|
# check file size
|
||||||
|
|
||||||
|
# check ignored files
|
||||||
|
if attachment.filename
|
||||||
|
filename_extention = attachment.filename.downcase
|
||||||
|
filename_extention.gsub!(/^.*(\..+?)$/, "\\1")
|
||||||
|
if !ignore_attachments.include?( filename_extention.downcase )
|
||||||
|
data = {
|
||||||
|
"_name" => attachment.filename,
|
||||||
|
"content" => Base64.encode64( attachment.content )
|
||||||
|
}
|
||||||
|
attributes['attachments'].push data
|
||||||
|
end
|
||||||
end
|
end
|
||||||
data = {
|
|
||||||
"_name" => attachment.filename,
|
|
||||||
"content" => Base64.encode64( attachment.content )
|
|
||||||
}
|
|
||||||
article_attributes['attachments'].push data
|
|
||||||
}
|
}
|
||||||
attributes['articles_all'].push article_attributes
|
attributes['articles_all'].push article_attributes
|
||||||
if !article.internal
|
|
||||||
attributes['articles_external'].push article_attributes
|
|
||||||
end
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return if !attributes
|
return if !attributes
|
||||||
SearchIndexBackend.add(self.class.to_s, attributes)
|
SearchIndexBackend.add(self.class.to_s, attributes)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -21,7 +21,7 @@ namespace :searchindex do
|
||||||
:data => {
|
:data => {
|
||||||
:mappings => {
|
:mappings => {
|
||||||
:Ticket => {
|
:Ticket => {
|
||||||
:_source => { :excludes => [ 'articles_all.attachments', 'articles_external.attachments' ] },
|
:_source => { :excludes => [ 'articles_all.attachments' ] },
|
||||||
:properties => {
|
:properties => {
|
||||||
:articles_all => {
|
:articles_all => {
|
||||||
:type => 'nested',
|
:type => 'nested',
|
||||||
|
|
|
@ -56,10 +56,10 @@ class ElasticsearchTest < ActiveSupport::TestCase
|
||||||
:created_by_id => 1,
|
:created_by_id => 1,
|
||||||
)
|
)
|
||||||
customer2 = User.create_or_update(
|
customer2 = User.create_or_update(
|
||||||
:login => 'es-customer1@example.com',
|
:login => 'es-customer2@example.com',
|
||||||
:firstname => 'ES',
|
:firstname => 'ES',
|
||||||
:lastname => 'Customer1',
|
:lastname => 'Customer2',
|
||||||
:email => 'es-customer1@example.com',
|
:email => 'es-customer2@example.com',
|
||||||
:password => 'customerpw',
|
:password => 'customerpw',
|
||||||
:active => true,
|
:active => true,
|
||||||
:organization_id => organization1.id,
|
:organization_id => organization1.id,
|
||||||
|
|
Loading…
Reference in a new issue