Class: SearchResult::QueryResult

Inherits:
Array
  • Object
show all
Defined in:
app/models/search_result.rb

Overview

Represents the entire result of the query

Constant Summary collapse

SORT_BY_DATE_PARAM =
"date:D:S:d1"
SORT_BY_RELEVANCE_PARAM =
"date:D:L:d1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(array = []) ⇒ QueryResult

Returns a new instance of QueryResult.



175
176
177
178
179
180
181
182
183
184
# File 'app/models/search_result.rb', line 175

def initialize(array=[])
  # Need to set defaults so an empty result set works.
  self.start = 0
  self.results_count=0
  self.key_matches = []
  self.synonyms = []
  self.num_pages = 1
  super(array)

end

Instance Attribute Details

#current_pageObject

Returns the value of attribute current_page.



168
169
170
# File 'app/models/search_result.rb', line 168

def current_page
  @current_page
end

#key_matchesObject

Returns the value of attribute key_matches.



168
169
170
# File 'app/models/search_result.rb', line 168

def key_matches
  @key_matches
end

#num_pagesObject

Returns the value of attribute num_pages.



168
169
170
# File 'app/models/search_result.rb', line 168

def num_pages
  @num_pages
end

#pagesObject

Returns a range of pages that should appear in the pager control. This is design to mimic GSA’s pager control, which will show up to 20 pages at a time, based on the ‘range’ of pages around the current page.

i.e. on page 12: < 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 >



203
204
205
# File 'app/models/search_result.rb', line 203

def pages
  @pages
end

#pathObject



186
187
188
# File 'app/models/search_result.rb', line 186

def path
  @path ? @path : "/search/search-results"
end

#queryObject

Returns the value of attribute query.



168
169
170
# File 'app/models/search_result.rb', line 168

def query
  @query
end

#results_countObject

Returns the value of attribute results_count.



168
169
170
# File 'app/models/search_result.rb', line 168

def results_count
  @results_count
end

#startObject

Returns the value of attribute start.



168
169
170
# File 'app/models/search_result.rb', line 168

def start
  @start
end

#synonymsObject

Returns the value of attribute synonyms.



168
169
170
# File 'app/models/search_result.rb', line 168

def synonyms
  @synonyms
end

Instance Method Details

#current_page?(page_num) ⇒ Boolean

Returns:

  • (Boolean)


218
219
220
# File 'app/models/search_result.rb', line 218

def current_page?(page_num)
  (page_num * 10 - 10 == start )
end

#key_matches?Boolean

Returns:

  • (Boolean)


261
262
263
# File 'app/models/search_result.rb', line 261

def key_matches?
  !key_matches.empty?
end

#next_page?Boolean

Returns:

  • (Boolean)


191
192
193
# File 'app/models/search_result.rb', line 191

def next_page?
  next_start < results_count      
end

#next_page_pathObject



249
250
251
# File 'app/models/search_result.rb', line 249

def next_page_path
  "#{path}?query=#{query}&start=#{next_start}"
end

#next_startObject



210
211
212
# File 'app/models/search_result.rb', line 210

def next_start
  start + 10
end

#page_path(page_num) ⇒ Object



257
258
259
# File 'app/models/search_result.rb', line 257

def page_path(page_num)
  "#{path}?query=#{query}&start=#{page_num * 10 - 10}"
end

#path_for(new_query) ⇒ Object



234
235
236
# File 'app/models/search_result.rb', line 234

def path_for(new_query)
  "#{path}?query=#{new_query}"
end

#previous_page?Boolean

Returns:

  • (Boolean)


195
196
197
# File 'app/models/search_result.rb', line 195

def previous_page?
  previous_start >= 0 && num_pages > 1
end

#previous_page_pathObject



253
254
255
# File 'app/models/search_result.rb', line 253

def previous_page_path
  "#{path}?query=#{query}&start=#{previous_start}"
end

#previous_startObject



214
215
216
# File 'app/models/search_result.rb', line 214

def previous_start
  start - 10
end

#sort_by_date_pathObject

Return the path to sort the current search results by date.

Based on code.google.com/apis/searchappliance/documentation/46/xml_reference.html#request_sort



240
241
242
# File 'app/models/search_result.rb', line 240

def sort_by_date_path
  "#{path}?query=#{query}&sort=#{SORT_BY_DATE_PARAM}"
end

#sort_by_relevance_pathObject

Returns the path to sort the current results by relevance (inverse of sort_by_date_path).



245
246
247
# File 'app/models/search_result.rb', line 245

def sort_by_relevance_path
  "#{path}?query=#{query}&sort=#{SORT_BY_RELEVANCE_PARAM}"
end

#sorting_by_date?(params) ⇒ Boolean

Determines the current Query is sorting by date.

Parameters:

  • params (Hash)

    The query parameter from the search page. (same as Rails params)

Returns:

  • (Boolean)


230
231
232
# File 'app/models/search_result.rb', line 230

def sorting_by_date?(params)
  params[:sort] == SearchResult::QueryResult::SORT_BY_DATE_PARAM
end

#synonyms?Boolean

Returns:

  • (Boolean)


265
266
267
# File 'app/models/search_result.rb', line 265

def synonyms?
  !synonyms.empty?
end