Sha256: b6d11d621657698b0feb5493449b45dc48df961992ac29825ccf0818843f359d

Contents?: true

Size: 2 KB

Versions: 1

Compression:

Stored size: 2 KB

Contents

require 'active_support/concern'
require 'active_model'
require 'elasticsearch/model'

module Elasticsearch
  module Git
    module Model
      extend ActiveSupport::Concern

      included do
        extend ActiveModel::Naming
        include ActiveModel::Model
        include Elasticsearch::Model

        env = if defined?(::Rails)
                ::Rails.env.to_s
              else
                nil
              end

        index_name [self.name.downcase, 'index', env].compact.join('-')

        settings \
          index: {
          analysis: {
            analyzer: {
              path_analyzer: {
                type: 'custom',
                tokenizer: 'path_tokenizer',
                filter: %w(lowercase asciifolding)
              },
              sha_analyzer: {
                type: 'custom',
                tokenizer: 'sha_tokenizer',
                filter: %w(lowercase asciifolding)
              },
              code_analyzer: {
                type: 'custom',
                tokenizer: 'standard',
                filter: %w(code lowercase asciifolding),
                char_filter: ["code_mapping"]
              }
            },
            tokenizer: {
              sha_tokenizer: {
                type: "edgeNGram",
                min_gram: 5,
                max_gram: 40,
                token_chars: %w(letter digit)
              },
              path_tokenizer: {
                type: 'path_hierarchy',
                reverse: true
              },
            },
            filter: {
              code: {
                type: "pattern_capture",
                preserve_original: 1,
                patterns: [
                  "(\\p{Ll}+|\\p{Lu}\\p{Ll}+|\\p{Lu}+)",
                  "(\\d+)"
                ]
              }
            },
            char_filter: {
              code_mapping: {
                type: "mapping",
                mappings: [
                  ". => ' '"
                ]
              }
            },
          }
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gitlab-elasticsearch-git-0.0.16 lib/elasticsearch/git/model.rb