Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 21:42:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 21:42:06 +0300
commit6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch)
tree78be5963ec075d80116a932011d695dd33910b4e /lib/gitlab/search/parsed_query.rb
parent1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff)
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'lib/gitlab/search/parsed_query.rb')
-rw-r--r--lib/gitlab/search/parsed_query.rb45
1 files changed, 39 insertions, 6 deletions
diff --git a/lib/gitlab/search/parsed_query.rb b/lib/gitlab/search/parsed_query.rb
index 1f6e0519b4c..5d5d407c172 100644
--- a/lib/gitlab/search/parsed_query.rb
+++ b/lib/gitlab/search/parsed_query.rb
@@ -3,6 +3,8 @@
module Gitlab
module Search
class ParsedQuery
+ include Gitlab::Utils::StrongMemoize
+
attr_reader :term, :filters
def initialize(term, filters)
@@ -11,13 +13,44 @@ module Gitlab
end
def filter_results(results)
- filters = @filters.reject { |filter| filter[:matcher].nil? }
- return unless filters
+ with_matcher = ->(filter) { filter[:matcher].present? }
+
+ excluding = excluding_filters.select(&with_matcher)
+ including = including_filters.select(&with_matcher)
+
+ return unless excluding.any? || including.any?
+
+ results.select! do |result|
+ including.all? { |filter| filter[:matcher].call(filter, result) }
+ end
+
+ results.reject! do |result|
+ excluding.any? { |filter| filter[:matcher].call(filter, result) }
+ end
+
+ results
+ end
+
+ private
+
+ def including_filters
+ processed_filters(:including)
+ end
+
+ def excluding_filters
+ processed_filters(:excluding)
+ end
+
+ def processed_filters(type)
+ excluding, including = strong_memoize(:processed_filters) do
+ filters.partition { |filter| filter[:negated] }
+ end
- results.select do |result|
- filters.all? do |filter|
- filter[:matcher].call(filter, result)
- end
+ case type
+ when :including then including
+ when :excluding then excluding
+ else
+ raise ArgumentError.new(type)
end
end
end