Commit 022ec748 authored by Valery Sizov's avatar Valery Sizov

comments addressed

parent 535aeb80
......@@ -60,11 +60,16 @@ module Elastic
end
def es_parent
return project_id if respond_to?(:project_id)
project_id if respond_to?(:project_id)
end
end
module ClassMethods
# Should be overridden for all nested models
def nested?
false
end
def highlight_options(fields)
es_fields = fields.map { |field| field.split('^').first }.inject({}) do |memo, field|
memo[field.to_sym] = {}
......
......@@ -33,6 +33,10 @@ module Elastic
data
end
def self.nested?
true
end
def self.elastic_search(query, options: {})
if query =~ /#(\d+)\z/
query_hash = iid_query_hash(query_hash, $1)
......
......@@ -55,6 +55,10 @@ module Elastic
target_project_id
end
def self.nested?
true
end
def self.elastic_search(query, options: {})
if query =~ /#(\d+)\z/
query_hash = iid_query_hash(query_hash, $1)
......
......@@ -22,6 +22,10 @@ module Elastic
)
end
def self.nested?
true
end
def self.elastic_search(query, options: {})
options[:in] = %w(title^2 description)
......
......@@ -40,6 +40,10 @@ module Elastic
data
end
def self.nested?
true
end
def self.elastic_search(query, options: {})
options[:in] = ['note']
......
......@@ -5,7 +5,6 @@ class ElasticIndexerWorker
sidekiq_options queue: :elasticsearch
ISSUE_TRACKED_FIELDS = %w(assignee_id author_id confidential)
NOT_NESTED_ENTITIES = [Project, PersonalSnippet, ProjectSnippet, Snippet]
def perform(operation, class_name, record_id, options = {})
klass = class_name.constantize
......@@ -15,23 +14,23 @@ class ElasticIndexerWorker
record = klass.find(record_id)
record.__elasticsearch__.client = client
if NOT_NESTED_ENTITIES.include?(klass)
record.__elasticsearch__.__send__ "#{operation}_document"
else
if klass.nested?
record.__elasticsearch__.__send__ "#{operation}_document", parent: record.es_parent
else
record.__elasticsearch__.__send__ "#{operation}_document"
end
update_issue_notes(record, options["changed_fields"]) if klass == Issue
when /delete/
if NOT_NESTED_ENTITIES.include?(klass)
client.delete index: klass.index_name, type: klass.document_type, id: record_id
else
if klass.nested?
client.delete(
index: klass.index_name,
type: klass.document_type,
id: record_id,
parent: options["project_id"]
)
else
client.delete index: klass.index_name, type: klass.document_type, id: record_id
end
clear_project_indexes(record_id) if klass == Project
......
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