123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- module Ticket::SearchIndex
- def search_index_attribute_lookup
- attributes = super
- return if !attributes
-
-
- tags = Tag.tag_list(object: 'Ticket', o_id: id)
- if tags && !tags.empty?
- attributes[:tag] = tags
- end
-
- attachments_ignore = Setting.get('es_attachment_ignore') || [ '.png', '.jpg', '.jpeg', '.mpeg', '.mpg', '.mov', '.bin', '.exe' ]
-
- attachment_max_size_in_mb = Setting.get('es_attachment_max_size_in_mb') || 40
-
- articles = Ticket::Article.where(ticket_id: id)
- attributes['article'] = []
- articles.each { |article|
- article_attributes = article.attributes
-
- ignore = %w(message_id_md5)
- ignore.each { |attribute|
- article_attributes.delete(attribute)
- }
-
- article_attributes = article.search_index_attribute_lookup
-
- if article_attributes['content_type'] && article_attributes['content_type'] == 'text/html' && article_attributes['body']
- article_attributes['body'] = article_attributes['body'].html2text
- end
-
- article.attachments.each { |attachment|
- if !article_attributes['attachment']
- article_attributes['attachment'] = []
- end
-
- next if !attachment.content
- next if attachment.content.size / 1024 > attachment_max_size_in_mb * 1024
-
- next if !attachment.filename
- filename_extention = attachment.filename.downcase
- filename_extention.gsub!(/^.*(\..+?)$/, '\\1')
- next if attachments_ignore.include?(filename_extention.downcase)
- data = {
- '_name' => attachment.filename,
- '_content' => Base64.encode64(attachment.content)
- }
- article_attributes['attachment'].push data
- }
- attributes['article'].push article_attributes
- }
- attributes
- end
- end
|