Class: SearchResult::QueryResult
- Inherits:
-
Array
- Object
- Array
- SearchResult::QueryResult
- Defined in:
- app/models/search_result.rb
Overview
Represents the entire result of the query
Constant Summary collapse
- SORT_BY_DATE_PARAM =
For what these codes mean, see code.google.com/apis/searchappliance/documentation/46/xml_reference.html#request_sort
"date:D:S:d1"
- SORT_BY_RELEVANCE_PARAM =
"date:D:L:d1"
Instance Attribute Summary collapse
-
#current_page ⇒ Object
Returns the value of attribute current_page.
-
#key_matches ⇒ Object
Returns the value of attribute key_matches.
-
#num_pages ⇒ Object
Returns the value of attribute num_pages.
-
#pages ⇒ Object
Returns a range of pages that should appear in the pager control.
- #path ⇒ Object
-
#query ⇒ Object
Returns the value of attribute query.
-
#results_count ⇒ Object
Returns the value of attribute results_count.
-
#start ⇒ Object
Returns the value of attribute start.
-
#synonyms ⇒ Object
Returns the value of attribute synonyms.
Instance Method Summary collapse
- #current_page?(page_num) ⇒ Boolean
-
#initialize(array = []) ⇒ QueryResult
constructor
A new instance of QueryResult.
- #key_matches? ⇒ Boolean
- #next_page? ⇒ Boolean
- #next_page_path ⇒ Object
- #next_start ⇒ Object
- #page_path(page_num) ⇒ Object
- #path_for(new_query) ⇒ Object
- #previous_page? ⇒ Boolean
- #previous_page_path ⇒ Object
- #previous_start ⇒ Object
-
#sort_by_date_path ⇒ Object
Return the path to sort the current search results by date.
-
#sort_by_relevance_path ⇒ Object
Returns the path to sort the current results by relevance (inverse of sort_by_date_path).
-
#sorting_by_date?(params) ⇒ Boolean
Determines the current Query is sorting by date.
- #synonyms? ⇒ Boolean
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_page ⇒ Object
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_matches ⇒ Object
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_pages ⇒ Object
Returns the value of attribute num_pages.
168 169 170 |
# File 'app/models/search_result.rb', line 168 def num_pages @num_pages end |
#pages ⇒ Object
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 |
#path ⇒ Object
186 187 188 |
# File 'app/models/search_result.rb', line 186 def path @path ? @path : "/search/search-results" end |
#query ⇒ Object
Returns the value of attribute query.
168 169 170 |
# File 'app/models/search_result.rb', line 168 def query @query end |
#results_count ⇒ Object
Returns the value of attribute results_count.
168 169 170 |
# File 'app/models/search_result.rb', line 168 def results_count @results_count end |
#start ⇒ Object
Returns the value of attribute start.
168 169 170 |
# File 'app/models/search_result.rb', line 168 def start @start end |
#synonyms ⇒ Object
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
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
261 262 263 |
# File 'app/models/search_result.rb', line 261 def key_matches? !key_matches.empty? end |
#next_page? ⇒ Boolean
191 192 193 |
# File 'app/models/search_result.rb', line 191 def next_page? next_start < results_count end |
#next_page_path ⇒ Object
249 250 251 |
# File 'app/models/search_result.rb', line 249 def next_page_path "#{path}?query=#{query}&start=#{next_start}" end |
#next_start ⇒ Object
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
195 196 197 |
# File 'app/models/search_result.rb', line 195 def previous_page? previous_start >= 0 && num_pages > 1 end |
#previous_page_path ⇒ Object
253 254 255 |
# File 'app/models/search_result.rb', line 253 def previous_page_path "#{path}?query=#{query}&start=#{previous_start}" end |
#previous_start ⇒ Object
214 215 216 |
# File 'app/models/search_result.rb', line 214 def previous_start start - 10 end |
#sort_by_date_path ⇒ Object
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_path ⇒ Object
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.
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
265 266 267 |
# File 'app/models/search_result.rb', line 265 def synonyms? !synonyms.empty? end |