Commit 71184120 authored by Valery Sizov's avatar Valery Sizov

Merge branch 'es_refactoring' into 'master'

Move elastic modules to lib



See merge request !157
parents 63392cdc 2ccd6a30
module ApplicationSearch
extend ActiveSupport::Concern
included do
include Elasticsearch::Model
self.__elasticsearch__.client = Elasticsearch::Client.new(
host: Gitlab.config.elasticsearch.host,
port: Gitlab.config.elasticsearch.port
)
index_name [Rails.application.class.parent_name.downcase, self.name.downcase, Rails.env].join('-')
settings \
index: {
analysis: {
analyzer: {
default:{
tokenizer: "standard",
filter: ["standard", "lowercase", "my_stemmer"]
}
},
filter: {
my_stemmer: {
type: "stemmer",
name: "light_english"
}
}
}
}
if Gitlab.config.elasticsearch.enabled
after_commit on: :create do
ElasticIndexerWorker.perform_async(:index, self.class.to_s, self.id)
end
after_commit on: :update do
ElasticIndexerWorker.perform_async(:update, self.class.to_s, self.id)
end
after_commit on: :destroy do
ElasticIndexerWorker.perform_async(:delete, self.class.to_s, self.id)
end
end
end
module ClassMethods
def highlight_options(fields)
es_fields = fields.map { |field| field.split('^').first }.inject({}) do |memo, field|
memo[field.to_sym] = {}
memo
end
{ fields: es_fields }
end
def basic_query_hash(fields, query)
query_hash = if query.present?
{
query: {
filtered: {
query: {
multi_match: {
fields: fields,
query: query,
operator: :and
}
},
},
}
}
else
{
query: {
filtered: {
query: { match_all: {} }
}
},
track_scores: true
}
end
query_hash[:sort] = [
{ updated_at_sort: { order: :desc, mode: :min } },
:_score
]
query_hash[:highlight] = highlight_options(fields)
query_hash
end
def project_ids_filter(query_hash, project_ids)
if project_ids
query_hash[:query][:filtered][:filter] = {
and: [ { terms: { project_id: project_ids } } ]
}
end
query_hash
end
end
end
module IssuesSearch
extend ActiveSupport::Concern
included do
include ApplicationSearch
mappings do
indexes :id, type: :integer
indexes :iid, type: :integer, index: :not_analyzed
indexes :title, type: :string,
index_options: 'offsets'
indexes :description, type: :string,
index_options: 'offsets'
indexes :created_at, type: :date
indexes :updated_at, type: :date
indexes :state, type: :string
indexes :project_id, type: :integer
indexes :author_id, type: :integer
indexes :project, type: :nested
indexes :author, type: :nested
indexes :updated_at_sort, type: :date, index: :not_analyzed
end
def as_indexed_json(options = {})
as_json(
include: {
project: { only: :id },
author: { only: :id }
}
).merge({ updated_at_sort: updated_at })
end
def self.elastic_search(query, options: {})
options[:in] = %w(title^2 description)
query_hash = basic_query_hash(options[:in], query)
query_hash = project_ids_filter(query_hash, options[:projects_ids])
self.__elasticsearch__.search(query_hash)
end
end
end
module MergeRequestsSearch
extend ActiveSupport::Concern
included do
include ApplicationSearch
mappings do
indexes :id, type: :integer
indexes :iid, type: :integer
indexes :target_branch, type: :string,
index_options: 'offsets'
indexes :source_branch, type: :string,
index_options: 'offsets'
indexes :title, type: :string,
index_options: 'offsets'
indexes :description, type: :string,
index_options: 'offsets'
indexes :created_at, type: :date
indexes :updated_at, type: :date
indexes :state, type: :string
indexes :merge_status, type: :string
indexes :source_project_id, type: :integer
indexes :target_project_id, type: :integer
indexes :author_id, type: :integer
indexes :source_project, type: :nested
indexes :target_project, type: :nested
indexes :author, type: :nested
indexes :updated_at_sort, type: :string, index: 'not_analyzed'
end
def as_indexed_json(options = {})
as_json(
include: {
source_project: { only: :id },
target_project: { only: :id },
author: { only: :id }
}
).merge({ updated_at_sort: updated_at })
end
def self.elastic_search(query, options: {})
query_hash = basic_query_hash(%w(title^2 description), query)
if options[:projects_ids]
query_hash[:query][:filtered][:filter] = {
and: [
{
terms: {
target_project_id: [options[:projects_ids]].flatten
}
}
]
}
end
self.__elasticsearch__.search(query_hash)
end
end
end
module MilestonesSearch
extend ActiveSupport::Concern
included do
include ApplicationSearch
mappings do
indexes :id, type: :integer
indexes :title, type: :string,
index_options: 'offsets'
indexes :description, type: :string,
index_options: 'offsets'
indexes :project_id, type: :integer
indexes :created_at, type: :date
indexes :updated_at_sort, type: :string, index: 'not_analyzed'
end
def as_indexed_json(options = {})
as_json.merge({ updated_at_sort: updated_at })
end
def self.elastic_search(query, options: {})
options[:in] = %w(title^2 description)
query_hash = basic_query_hash(options[:in], query)
query_hash = project_ids_filter(query_hash, options[:projects_ids])
self.__elasticsearch__.search(query_hash)
end
end
end
module NotesSearch
extend ActiveSupport::Concern
included do
include ApplicationSearch
mappings do
indexes :id, type: :integer
indexes :note, type: :string,
index_options: 'offsets'
indexes :project_id, type: :integer
indexes :created_at, type: :date
indexes :updated_at_sort, type: :string, index: 'not_analyzed'
end
def as_indexed_json(options = {})
as_json.merge({ updated_at_sort: updated_at })
end
def self.elastic_search(query, options: {})
options[:in] = ["note"]
query_hash = {
query: {
filtered: {
query: { match: { note: query } },
},
}
}
if query.blank?
query_hash[:query][:filtered][:query] = { match_all: {} }
query_hash[:track_scores] = true
end
query_hash = project_ids_filter(query_hash, options[:projects_ids])
query_hash[:sort] = [
{ updated_at_sort: { order: :desc, mode: :min } },
:_score
]
query_hash[:highlight] = highlight_options(options[:in])
self.__elasticsearch__.search(query_hash)
end
end
end
module ProjectsSearch
extend ActiveSupport::Concern
included do
include ApplicationSearch
mappings do
indexes :id, type: :integer
indexes :name, type: :string,
index_options: 'offsets'
indexes :path, type: :string,
index_options: 'offsets'
indexes :name_with_namespace, type: :string,
index_options: 'offsets'
indexes :path_with_namespace, type: :string,
index_options: 'offsets'
indexes :description, type: :string,
index_options: 'offsets'
indexes :namespace_id, type: :integer
indexes :created_at, type: :date
indexes :archived, type: :boolean
indexes :visibility_level, type: :integer
indexes :last_activity_at, type: :date
indexes :last_pushed_at, type: :date
end
def as_indexed_json(options = {})
as_json.merge({
name_with_namespace: name_with_namespace,
path_with_namespace: path_with_namespace
})
end
def self.elastic_search(query, options: {})
options[:in] = %w(name^10 name_with_namespace^2 path_with_namespace path^9)
query_hash = basic_query_hash(options[:in], query)
filters = []
if options[:abandoned]
filters << {
range: {
last_pushed_at: {
lte: "now-6M/m"
}
}
}
end
if options[:with_push]
filters << {
not: {
missing: {
field: :last_pushed_at,
existence: true,
null_value: true
}
}
}
end
if options[:namespace_id]
filters << {
terms: {
namespace_id: [options[:namespace_id]].flatten
}
}
end
if options[:non_archived]
filters << {
terms: {
archived: [!options[:non_archived]].flatten
}
}
end
if options[:visibility_levels]
filters << {
terms: {
visibility_level: [options[:visibility_levels]].flatten
}
}
end
if !options[:owner_id].blank?
filters << {
nested: {
path: :owner,
filter: {
term: { "owner.id" => options[:owner_id] }
}
}
}
end
if options[:pids]
filters << {
ids: {
values: options[:pids]
}
}
end
query_hash[:query][:filtered][:filter] = { and: filters }
query_hash[:sort] = [:_score]
self.__elasticsearch__.search(query_hash)
end
end
end
module RepositoriesSearch
extend ActiveSupport::Concern
included do
include Elasticsearch::Git::Repository
self.__elasticsearch__.client = Elasticsearch::Client.new(
host: Gitlab.config.elasticsearch.host,
port: Gitlab.config.elasticsearch.port
)
def repository_id
project.id
end
def self.repositories_count
Project.count
end
def client_for_indexing
self.__elasticsearch__.client
end
def self.import
Repository.__elasticsearch__.create_index!
Project.find_each do |project|
if project.repository.exists? && !project.repository.empty?
project.repository.index_commits
project.repository.index_blobs
end
end
end
end
end
module SnippetsSearch
extend ActiveSupport::Concern
included do
include ApplicationSearch
mappings do
indexes :id, type: :integer
indexes :title, type: :string,
index_options: 'offsets'
indexes :file_name, type: :string,
index_options: 'offsets'
indexes :content, type: :string,
index_options: 'offsets'
indexes :created_at, type: :date
indexes :updated_at, type: :date
indexes :state, type: :string
indexes :project_id, type: :integer
indexes :author_id, type: :integer
indexes :project, type: :nested
indexes :author, type: :nested
indexes :updated_at_sort, type: :date, index: :not_analyzed
end
def as_indexed_json(options = {})
as_json(
include: {
project: { only: :id },
author: { only: :id }
}
)
end
def self.elastic_search(query, options: {})
query_hash = basic_query_hash(%w(title file_name), query)
query_hash = limit_ids(query_hash, options[:ids])
self.__elasticsearch__.search(query_hash)
end
def self.elastic_search_code(query, options: {})
query_hash = {
query: {
filtered: {
query: { match: { content: query } },
},
}
}
query_hash = limit_ids(query_hash, options[:ids])
query_hash[:sort] = [
{ updated_at_sort: { order: :desc, mode: :min } },
:_score
]
query_hash[:highlight] = { fields: { content: {} } }
self.__elasticsearch__.search(query_hash)
end
def self.limit_ids(query_hash, ids)
if ids
query_hash[:query][:filtered][:filter] = {
and: [ { terms: { id: ids } } ]
}
end
query_hash
end
end
end
module WikiRepositoriesSearch
extend ActiveSupport::Concern
included do
include Elasticsearch::Git::Repository
self.__elasticsearch__.client = Elasticsearch::Client.new(
host: Gitlab.config.elasticsearch.host,
port: Gitlab.config.elasticsearch.port
)
def repository_id
"wiki_#{project.id}"
end
def self.repositories_count
Project.where(wiki_enabled: true).count
end
def client_for_indexing
self.__elasticsearch__.client
end
def self.import
ProjectWiki.__elasticsearch__.create_index!
Project.where(wiki_enabled: true).find_each do |project|
unless project.wiki.empty?
project.wiki.index_blobs
end
end
end
end
end
...@@ -27,7 +27,7 @@ class Issue < ActiveRecord::Base ...@@ -27,7 +27,7 @@ class Issue < ActiveRecord::Base
include Referable include Referable
include Sortable include Sortable
include Taskable include Taskable
include IssuesSearch include Elastic::IssuesSearch
WEIGHT_RANGE = 1..9 WEIGHT_RANGE = 1..9
......
...@@ -35,7 +35,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -35,7 +35,7 @@ class MergeRequest < ActiveRecord::Base
include Referable include Referable
include Sortable include Sortable
include Taskable include Taskable
include MergeRequestsSearch include Elastic::MergeRequestsSearch
belongs_to :target_project, foreign_key: :target_project_id, class_name: "Project" belongs_to :target_project, foreign_key: :target_project_id, class_name: "Project"
belongs_to :source_project, foreign_key: :source_project_id, class_name: "Project" belongs_to :source_project, foreign_key: :source_project_id, class_name: "Project"
......
...@@ -24,7 +24,7 @@ class Milestone < ActiveRecord::Base ...@@ -24,7 +24,7 @@ class Milestone < ActiveRecord::Base
include Sortable include Sortable
include Referable include Referable
include StripAttribute include StripAttribute
include MilestonesSearch include Elastic::MilestonesSearch
belongs_to :project belongs_to :project
has_many :issues has_many :issues
......
...@@ -26,7 +26,7 @@ class Note < ActiveRecord::Base ...@@ -26,7 +26,7 @@ class Note < ActiveRecord::Base
include Gitlab::CurrentSettings include Gitlab::CurrentSettings
include Participable include Participable
include Mentionable include Mentionable
include NotesSearch include Elastic::NotesSearch
default_value_for :system, false default_value_for :system, false
......
...@@ -52,7 +52,7 @@ class Project < ActiveRecord::Base ...@@ -52,7 +52,7 @@ class Project < ActiveRecord::Base
include AfterCommitQueue include AfterCommitQueue
include CaseSensitivity include CaseSensitivity
include TokenAuthenticatable include TokenAuthenticatable
include ProjectsSearch include Elastic::ProjectsSearch
extend Gitlab::ConfigHelper extend Gitlab::ConfigHelper
......
class ProjectWiki class ProjectWiki
include Gitlab::ShellAdapter include Gitlab::ShellAdapter
include WikiRepositoriesSearch include Elastic::WikiRepositoriesSearch
MARKUPS = { MARKUPS = {
'Markdown' => :md, 'Markdown' => :md,
......
require 'securerandom' require 'securerandom'
class Repository class Repository
include RepositoriesSearch include Elastic::RepositoriesSearch
class CommitError < StandardError; end class CommitError < StandardError; end
......
...@@ -21,7 +21,7 @@ class Snippet < ActiveRecord::Base ...@@ -21,7 +21,7 @@ class Snippet < ActiveRecord::Base
include Participable include Participable
include Referable include Referable
include Sortable include Sortable
include SnippetsSearch include Elastic::SnippetsSearch
default_value_for :visibility_level, Snippet::PRIVATE default_value_for :visibility_level, Snippet::PRIVATE
......
...@@ -16,8 +16,7 @@ module Gitlab ...@@ -16,8 +16,7 @@ module Gitlab
#{config.root}/app/models/hooks #{config.root}/app/models/hooks
#{config.root}/app/models/concerns #{config.root}/app/models/concerns
#{config.root}/app/models/project_services #{config.root}/app/models/project_services
#{config.root}/app/models/members #{config.root}/app/models/members))
#{config.root}/app/elastic))
# Only load the plugins named here, in the order given (default is alphabetical). # Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named. # :all can be used as a placeholder for all plugins not explicitly named.
......
module Elastic
module ApplicationSearch
extend ActiveSupport::Concern
included do
include Elasticsearch::Model
self.__elasticsearch__.client = Elasticsearch::Client.new(
host: Gitlab.config.elasticsearch.host,
port: Gitlab.config.elasticsearch.port
)
index_name [Rails.application.class.parent_name.downcase, self.name.downcase, Rails.env].join('-')
settings \
index: {
analysis: {
analyzer: {
default:{
tokenizer: "standard",
filter: ["standard", "lowercase", "my_stemmer"]
}
},
filter: {
my_stemmer: {
type: "stemmer",
name: "light_english"
}
}
}
}
if Gitlab.config.elasticsearch.enabled
after_commit on: :create do
ElasticIndexerWorker.perform_async(:index, self.class.to_s, self.id)
end
after_commit on: :update do
ElasticIndexerWorker.perform_async(:update, self.class.to_s, self.id)
end
after_commit on: :destroy do
ElasticIndexerWorker.perform_async(:delete, self.class.to_s, self.id)
end
end
end
module ClassMethods
def highlight_options(fields)
es_fields = fields.map { |field| field.split('^').first }.inject({}) do |memo, field|
memo[field.to_sym] = {}
memo
end
{ fields: es_fields }
end
def basic_query_hash(fields, query)
query_hash = if query.present?
{
query: {
filtered: {
query: {
multi_match: {
fields: fields,
query: query,
operator: :and
}
},
},
}
}
else
{
query: {
filtered: {
query: { match_all: {} }
}
},
track_scores: true
}
end
query_hash[:sort] = [
{ updated_at_sort: { order: :desc, mode: :min } },
:_score
]
query_hash[:highlight] = highlight_options(fields)
query_hash
end
def project_ids_filter(query_hash, project_ids)
if project_ids
query_hash[:query][:filtered][:filter] = {
and: [ { terms: { project_id: project_ids } } ]
}
end
query_hash
end
end
end
end
module Elastic
module IssuesSearch
extend ActiveSupport::Concern
included do
include ApplicationSearch
mappings do
indexes :id, type: :integer
indexes :iid, type: :integer, index: :not_analyzed
indexes :title, type: :string,
index_options: 'offsets'
indexes :description, type: :string,
index_options: 'offsets'
indexes :created_at, type: :date
indexes :updated_at, type: :date
indexes :state, type: :string
indexes :project_id, type: :integer
indexes :author_id, type: :integer
indexes :project, type: :nested
indexes :author, type: :nested
indexes :updated_at_sort, type: :date, index: :not_analyzed
end
def as_indexed_json(options = {})
as_json(
include: {
project: { only: :id },
author: { only: :id }
}
).merge({ updated_at_sort: updated_at })
end
def self.elastic_search(query, options: {})
options[:in] = %w(title^2 description)
query_hash = basic_query_hash(options[:in], query)
query_hash = project_ids_filter(query_hash, options[:projects_ids])
self.__elasticsearch__.search(query_hash)
end
end
end
end
module Elastic
module MergeRequestsSearch
extend ActiveSupport::Concern
included do
include ApplicationSearch
mappings do
indexes :id, type: :integer
indexes :iid, type: :integer
indexes :target_branch, type: :string,
index_options: 'offsets'
indexes :source_branch, type: :string,
index_options: 'offsets'
indexes :title, type: :string,
index_options: 'offsets'
indexes :description, type: :string,
index_options: 'offsets'
indexes :created_at, type: :date
indexes :updated_at, type: :date
indexes :state, type: :string
indexes :merge_status, type: :string
indexes :source_project_id, type: :integer
indexes :target_project_id, type: :integer
indexes :author_id, type: :integer
indexes :source_project, type: :nested
indexes :target_project, type: :nested
indexes :author, type: :nested
indexes :updated_at_sort, type: :string, index: 'not_analyzed'
end
def as_indexed_json(options = {})
as_json(
include: {
source_project: { only: :id },
target_project: { only: :id },
author: { only: :id }
}
).merge({ updated_at_sort: updated_at })
end
def self.elastic_search(query, options: {})
query_hash = basic_query_hash(%w(title^2 description), query)
if options[:projects_ids]
query_hash[:query][:filtered][:filter] = {
and: [
{
terms: {
target_project_id: [options[:projects_ids]].flatten
}
}
]
}
end
self.__elasticsearch__.search(query_hash)
end
end
end
end
module Elastic
module MilestonesSearch
extend ActiveSupport::Concern
included do
include ApplicationSearch
mappings do
indexes :id, type: :integer
indexes :title, type: :string,
index_options: 'offsets'
indexes :description, type: :string,
index_options: 'offsets'
indexes :project_id, type: :integer
indexes :created_at, type: :date
indexes :updated_at_sort, type: :string, index: 'not_analyzed'
end
def as_indexed_json(options = {})
as_json.merge({ updated_at_sort: updated_at })
end
def self.elastic_search(query, options: {})
options[:in] = %w(title^2 description)
query_hash = basic_query_hash(options[:in], query)
query_hash = project_ids_filter(query_hash, options[:projects_ids])
self.__elasticsearch__.search(query_hash)
end
end
end
end
module Elastic
module NotesSearch
extend ActiveSupport::Concern
included do
include ApplicationSearch
mappings do
indexes :id, type: :integer
indexes :note, type: :string,
index_options: 'offsets'
indexes :project_id, type: :integer
indexes :created_at, type: :date
indexes :updated_at_sort, type: :string, index: 'not_analyzed'
end
def as_indexed_json(options = {})
as_json.merge({ updated_at_sort: updated_at })
end
def self.elastic_search(query, options: {})
options[:in] = ["note"]
query_hash = {
query: {
filtered: {
query: { match: { note: query } },
},
}
}
if query.blank?
query_hash[:query][:filtered][:query] = { match_all: {} }
query_hash[:track_scores] = true
end
query_hash = project_ids_filter(query_hash, options[:projects_ids])
query_hash[:sort] = [
{ updated_at_sort: { order: :desc, mode: :min } },
:_score
]
query_hash[:highlight] = highlight_options(options[:in])
self.__elasticsearch__.search(query_hash)
end
end
end
end
module Elastic
module ProjectsSearch
extend ActiveSupport::Concern
included do
include ApplicationSearch
mappings do
indexes :id, type: :integer
indexes :name, type: :string,
index_options: 'offsets'
indexes :path, type: :string,
index_options: 'offsets'
indexes :name_with_namespace, type: :string,
index_options: 'offsets'
indexes :path_with_namespace, type: :string,
index_options: 'offsets'
indexes :description, type: :string,
index_options: 'offsets'
indexes :namespace_id, type: :integer
indexes :created_at, type: :date
indexes :archived, type: :boolean
indexes :visibility_level, type: :integer
indexes :last_activity_at, type: :date
indexes :last_pushed_at, type: :date
end
def as_indexed_json(options = {})
as_json.merge({
name_with_namespace: name_with_namespace,
path_with_namespace: path_with_namespace
})
end
def self.elastic_search(query, options: {})
options[:in] = %w(name^10 name_with_namespace^2 path_with_namespace path^9)
query_hash = basic_query_hash(options[:in], query)
filters = []
if options[:abandoned]
filters << {
range: {
last_pushed_at: {
lte: "now-6M/m"
}
}
}
end
if options[:with_push]
filters << {
not: {
missing: {
field: :last_pushed_at,
existence: true,
null_value: true
}
}
}
end
if options[:namespace_id]
filters << {
terms: {
namespace_id: [options[:namespace_id]].flatten
}
}
end
if options[:non_archived]
filters << {
terms: {
archived: [!options[:non_archived]].flatten
}
}
end
if options[:visibility_levels]
filters << {
terms: {
visibility_level: [options[:visibility_levels]].flatten
}
}
end
if !options[:owner_id].blank?
filters << {
nested: {
path: :owner,
filter: {
term: { "owner.id" => options[:owner_id] }
}
}
}
end
if options[:pids]
filters << {
ids: {
values: options[:pids]
}
}
end
query_hash[:query][:filtered][:filter] = { and: filters }
query_hash[:sort] = [:_score]
self.__elasticsearch__.search(query_hash)
end
end
end
end
module Elastic
module RepositoriesSearch
extend ActiveSupport::Concern
included do
include Elasticsearch::Git::Repository
self.__elasticsearch__.client = Elasticsearch::Client.new(
host: Gitlab.config.elasticsearch.host,
port: Gitlab.config.elasticsearch.port
)
def repository_id
project.id
end
def self.repositories_count
Project.count
end
def client_for_indexing
self.__elasticsearch__.client
end
def self.import
Repository.__elasticsearch__.create_index!
Project.find_each do |project|
if project.repository.exists? && !project.repository.empty?
project.repository.index_commits
project.repository.index_blobs
end
end
end
end
end
end
module Elastic
module SnippetsSearch
extend ActiveSupport::Concern
included do
include ApplicationSearch
mappings do
indexes :id, type: :integer
indexes :title, type: :string,
index_options: 'offsets'
indexes :file_name, type: :string,
index_options: 'offsets'
indexes :content, type: :string,
index_options: 'offsets'
indexes :created_at, type: :date
indexes :updated_at, type: :date
indexes :state, type: :string
indexes :project_id, type: :integer
indexes :author_id, type: :integer
indexes :project, type: :nested
indexes :author, type: :nested
indexes :updated_at_sort, type: :date, index: :not_analyzed
end
def as_indexed_json(options = {})
as_json(
include: {
project: { only: :id },
author: { only: :id }
}
)
end
def self.elastic_search(query, options: {})
query_hash = basic_query_hash(%w(title file_name), query)
query_hash = limit_ids(query_hash, options[:ids])
self.__elasticsearch__.search(query_hash)
end
def self.elastic_search_code(query, options: {})
query_hash = {
query: {
filtered: {
query: { match: { content: query } },
},
}
}
query_hash = limit_ids(query_hash, options[:ids])
query_hash[:sort] = [
{ updated_at_sort: { order: :desc, mode: :min } },
:_score
]
query_hash[:highlight] = { fields: { content: {} } }
self.__elasticsearch__.search(query_hash)
end
def self.limit_ids(query_hash, ids)
if ids
query_hash[:query][:filtered][:filter] = {
and: [ { terms: { id: ids } } ]
}
end
query_hash
end
end
end
end
module Elastic
module WikiRepositoriesSearch
extend ActiveSupport::Concern
included do
include Elasticsearch::Git::Repository
self.__elasticsearch__.client = Elasticsearch::Client.new(
host: Gitlab.config.elasticsearch.host,
port: Gitlab.config.elasticsearch.port
)
def repository_id
"wiki_#{project.id}"
end
def self.repositories_count
Project.where(wiki_enabled: true).count
end
def client_for_indexing
self.__elasticsearch__.client
end
def self.import
ProjectWiki.__elasticsearch__.create_index!
Project.where(wiki_enabled: true).find_each do |project|
unless project.wiki.empty?
project.wiki.index_blobs
end
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment