<commit_before># Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/

module Ticket::SearchIndex

=begin

build and send data for search index to backend

  ticket = Ticket.find(123)
  result = ticket.search_index_update_backend

returns

  result = true # false

=end

  def search_index_update_backend
    return if !self.class.search_index_support_config

    # default ignored attributes
    ignore_attributes = {
      :created_at               => true,
      :updated_at               => true,
      :created_by_id            => true,
      :updated_by_id            => true,
      :active                   => true,
    }
    if self.class.search_index_support_config[:ignore_attributes]
      self.class.search_index_support_config[:ignore_attributes].each {|key, value|
        ignore_attributes[key] = value
      }
    end

    attributes = self.attributes
    ignore_attributes.each {|key, value|
      next if value != true
      attributes.delete( key.to_s )
    }
    attributes = search_index_attribute_lookup( attributes, self )

    # add article data
    articles = Ticket::Article.where( :ticket_id => self.id )
    attributes['articles_all'] = []
    attributes['articles_external'] = []
    articles.each {|article|
      article_attributes = article.attributes
      article_attributes.delete('created_by_id')
      article_attributes.delete('updated_by_id')
      article_attributes.delete('updated_at')
      article_attributes.delete('references')
      article_attributes.delete('message_id_md5')
      article_attributes.delete('message_id')
      article_attributes.delete('in_reply_to')
      article_attributes.delete('ticket_id')
      article_attributes = search_index_attribute_lookup( article_attributes, article )
      attributes['articles_all'].push article_attributes
      if !article.internal
        attributes['articles_external'].push article_attributes
      end<commit_msg>Added attachments to get indexed.<commit_after># Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/

module Ticket::SearchIndex

=begin

build and send data for search index to backend

  ticket = Ticket.find(123)
  result = ticket.search_index_update_backend

returns

  result = true # false

=end

  def search_index_update_backend
    return if !self.class.search_index_support_config

    # default ignored attributes
    ignore_attributes = {
      :created_by_id            => true,
      :updated_by_id            => true,
      :active                   => true,
    }
    if self.class.search_index_support_config[:ignore_attributes]
      self.class.search_index_support_config[:ignore_attributes].each {|key, value|
        ignore_attributes[key] = value
      }
    end

    attributes = self.attributes
    ignore_attributes.each {|key, value|
      next if value != true
      attributes.delete( key.to_s )
    }
    attributes = search_index_attribute_lookup( attributes, self )

    # add article data
    articles = Ticket::Article.where( :ticket_id => self.id )
    attributes['articles_all'] = []
    attributes['articles_external'] = []
    articles.each {|article|
      article_attributes = article.attributes
      article_attributes.delete('created_by_id')
      article_attributes.delete('updated_by_id')
      article_attributes.delete('updated_at')
      article_attributes.delete('references')
      article_attributes.delete('message_id_md5')
      article_attributes.delete('message_id')
      article_attributes.delete('in_reply_to')
      article_attributes.delete('ticket_id')
      article_attributes = search_index_attribute_lookup( article_attributes, article )

      # lookup attachments
      attachments = Store.list( :object => 'Ticket::Article', :o_id => article.id )
      attachments.each {|attachment|
        if !article_attributes['attachments']
          article_attributes['attachments'] = []
        end
        file = Store.find( attachment.id )
        data = {
            "_name"   => file.filename,
#            "_content_type" => file.preferences['Mime-Type'],
            "content" => Base64.encode64( file.store_file.data )
        }
        article_attributes['attachments'].push data
      }
      attributes['articles_all'].push article_attributes
      if !article.internal
        attributes['articles_external'].push article_attributes
      end
{'fraction_non_alphanumeric': 0.09629460201280879, 'fraction_numerical': 0.006404391582799634, 'mean_word_length': 3.121583411875589, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1862206', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1185, 'n_words': 230}