Class: Gitlab::Search::ParsedQuery

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/search/parsed_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(term, filters) ⇒ ParsedQuery

Returns a new instance of ParsedQuery.


10
11
12
13
# File 'lib/gitlab/search/parsed_query.rb', line 10

def initialize(term, filters)
  @term = term
  @filters = filters
end

Instance Attribute Details

#filtersObject (readonly)

Returns the value of attribute filters


8
9
10
# File 'lib/gitlab/search/parsed_query.rb', line 8

def filters
  @filters
end

#termObject (readonly)

Returns the value of attribute term


8
9
10
# File 'lib/gitlab/search/parsed_query.rb', line 8

def term
  @term
end

Instance Method Details

#filter_results(results) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gitlab/search/parsed_query.rb', line 15

def filter_results(results)
  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