Commit 9223e824 authored by Valery Sizov's avatar Valery Sizov

ES: satisfy flay

parent fa793dd9
...@@ -43,9 +43,7 @@ module MergeRequestsSearch ...@@ -43,9 +43,7 @@ module MergeRequestsSearch
end end
def self.elastic_search(query, options: {}) def self.elastic_search(query, options: {})
options[:in] = %w(title^2 description) query_hash = basic_query_hash(%w(title^2 description), query)
query_hash = basic_query_hash(options[:in], query)
if options[:projects_ids] if options[:projects_ids]
query_hash[:query][:filtered][:filter] = { query_hash[:query][:filtered][:filter] = {
......
...@@ -36,15 +36,9 @@ module SnippetsSearch ...@@ -36,15 +36,9 @@ module SnippetsSearch
end end
def self.elastic_search(query, options: {}) def self.elastic_search(query, options: {})
options[:in] = %w(title file_name) query_hash = basic_query_hash(%w(title file_name), query)
query_hash = basic_query_hash(options[:in], query) query_hash = limit_ids(query_hash, options[:ids])
if options[:ids]
query_hash[:query][:filtered][:filter] = {
and: [ { terms: { id: [options[:ids]].flatten } } ]
}
end
self.__elasticsearch__.search(query_hash) self.__elasticsearch__.search(query_hash)
end end
...@@ -58,11 +52,7 @@ module SnippetsSearch ...@@ -58,11 +52,7 @@ module SnippetsSearch
} }
} }
if options[:ids] query_hash = limit_ids(query_hash, options[:ids])
query_hash[:query][:filtered][:filter] = {
and: [ { terms: { id: [options[:ids]].flatten } } ]
}
end
query_hash[:sort] = [ query_hash[:sort] = [
{ updated_at_sort: { order: :desc, mode: :min } }, { updated_at_sort: { order: :desc, mode: :min } },
...@@ -73,5 +63,15 @@ module SnippetsSearch ...@@ -73,5 +63,15 @@ module SnippetsSearch
self.__elasticsearch__.search(query_hash) self.__elasticsearch__.search(query_hash)
end 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 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