Class: Gitlab::SearchResults

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/search_results.rb

Direct Known Subclasses

ProjectSearchResults, SnippetSearchResults

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_user, limit_projects, query) ⇒ SearchResults

Returns a new instance of SearchResults


9
10
11
12
13
# File 'lib/gitlab/search_results.rb', line 9

def initialize(current_user, limit_projects, query)
  @current_user = current_user
  @limit_projects = limit_projects || Project.all
  @query = Shellwords.shellescape(query) if query.present?
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user


3
4
5
# File 'lib/gitlab/search_results.rb', line 3

def current_user
  @current_user
end

#limit_projectsObject (readonly)

Limit search results by passed projects It allows us to search only for projects user has access to


7
8
9
# File 'lib/gitlab/search_results.rb', line 7

def limit_projects
  @limit_projects
end

#queryObject (readonly)

Returns the value of attribute query


3
4
5
# File 'lib/gitlab/search_results.rb', line 3

def query
  @query
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)

51
52
53
# File 'lib/gitlab/search_results.rb', line 51

def empty?
  total_count.zero?
end

#issues_countObject


39
40
41
# File 'lib/gitlab/search_results.rb', line 39

def issues_count
  @issues_count ||= issues.count
end

#merge_requests_countObject


43
44
45
# File 'lib/gitlab/search_results.rb', line 43

def merge_requests_count
  @merge_requests_count ||= merge_requests.count
end

#milestones_countObject


47
48
49
# File 'lib/gitlab/search_results.rb', line 47

def milestones_count
  @milestones_count ||= milestones.count
end

#objects(scope, page = nil) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gitlab/search_results.rb', line 15

def objects(scope, page = nil)
  case scope
  when 'projects'
    projects.page(page).per(per_page)
  when 'issues'
    issues.page(page).per(per_page)
  when 'merge_requests'
    merge_requests.page(page).per(per_page)
  when 'milestones'
    milestones.page(page).per(per_page)
  else
    Kaminari.paginate_array([]).page(page).per(per_page)
  end
end

#projects_countObject


35
36
37
# File 'lib/gitlab/search_results.rb', line 35

def projects_count
  @projects_count ||= projects.count
end

#total_countObject


30
31
32
33
# File 'lib/gitlab/search_results.rb', line 30

def total_count
  @total_count ||= projects_count + issues_count + merge_requests_count +
    milestones_count
end