Class: Documentation::SearchResult

Inherits:
Object
  • Object
show all
Defined in:
lib/documentation/search_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSearchResult

Returns a new instance of SearchResult.



12
13
14
15
16
17
18
# File 'lib/documentation/search_result.rb', line 12

def initialize
  @time = nil
  @raw_results = {}
  @page = 1
  @total_pages = 1
  @per_page = nil
end

Instance Attribute Details

#pageObject

Returns the value of attribute page.



8
9
10
# File 'lib/documentation/search_result.rb', line 8

def page
  @page
end

#per_pageObject

Returns the value of attribute per_page.



9
10
11
# File 'lib/documentation/search_result.rb', line 9

def per_page
  @per_page
end

#queryObject

Returns the value of attribute query.



4
5
6
# File 'lib/documentation/search_result.rb', line 4

def query
  @query
end

#raw_resultsObject

Returns the value of attribute raw_results.



6
7
8
# File 'lib/documentation/search_result.rb', line 6

def raw_results
  @raw_results
end

#resultsObject

Return the pages



23
24
25
# File 'lib/documentation/search_result.rb', line 23

def results
  @results
end

#timeObject

Returns the value of attribute time.



5
6
7
# File 'lib/documentation/search_result.rb', line 5

def time
  @time
end

#total_resultsObject

Returns the value of attribute total_results.



10
11
12
# File 'lib/documentation/search_result.rb', line 10

def total_results
  @total_results
end

Instance Method Details

#empty?Boolean

Is the result set empty?

Returns:

  • (Boolean)


44
45
46
# File 'lib/documentation/search_result.rb', line 44

def empty?
  self.results.empty?
end

#end_result_numberObject

The number of the last result on the current page



65
66
67
# File 'lib/documentation/search_result.rb', line 65

def end_result_number
  start_result_number + (results.size) - 1
end

#excerpt_for(page) ⇒ Object

Return the highlight string for a given page



33
34
35
36
37
38
39
# File 'lib/documentation/search_result.rb', line 33

def excerpt_for(page)
  if @raw_results[page.id] && hl = @raw_results[page.id][:highlights]
    ERB::Util.html_escape((hl.join("..."))).gsub('{{{', "<mark>").gsub("}}}", "</mark>").html_safe
  else
    page.content[0,255].gsub(/[\n\r]/, '') + "..."
  end
end

#first_page?Boolean

Is this the first page of the result set?

Returns:

  • (Boolean)


72
73
74
# File 'lib/documentation/search_result.rb', line 72

def first_page?
  page == 1
end

#last_page?Boolean

Is this the last page of the result set?

Returns:

  • (Boolean)


79
80
81
# File 'lib/documentation/search_result.rb', line 79

def last_page?
  page == total_pages
end

#start_result_numberObject

The number of the first result on the current page



58
59
60
# File 'lib/documentation/search_result.rb', line 58

def start_result_number
  ((page - 1) * per_page) + 1
end

#total_pagesObject

The total number of pages in the result set



51
52
53
# File 'lib/documentation/search_result.rb', line 51

def total_pages
  (total_results / per_page.to_f).ceil
end