Guest User

Untitled

a guest
May 25th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. def recover_search_results
  2. # if we have more than 4 terms, the do a NAME 'OR' search
  3. return SearchTypes::NAME, SearchModes::OR if search_terms.to_s.split.length >= 4
  4.  
  5. # try to expand searched geography
  6. # if at nationwide, just give up all hope
  7. if expansion_factor && expansion_factor.to_i >= 4
  8. return SearchTypes::UNKNOWN, SearchModes::OR
  9. end
  10.  
  11. if self.expansion_factor
  12. self.expansion_factor = self.expansion_factor.to_i + 1
  13. else
  14. self.expansion_factor = 1
  15. end
  16. search_request = Yellowpages::Search::SearchRequest.new(to_search_attributes)
  17. possible_type, possible_mode = SearchTypes.get_search_type_and_mode(search_request)
  18.  
  19. raise "Critical Error Determining Search Type, Unrecognized Search Type #{possible_type}" unless SearchTypes.include?(possible_type)
  20.  
  21. # if no results were found using our'recovery' methods, then we still want to return
  22. # a combo page. This is done by returning (Search::SearchTypes::UNKNOWN, Search::SearchModes::OR)
  23. # Also, don't forget to set teh expansion level back to the original value if expanding didn't find
  24. # results.
  25. return possible_type, possible_mode unless [SearchTypes::UNDETERMINED, SearchTypes::UNKNOWN_NO_RESULTS].include?(possible_type)
  26. self.expansion_factor -= 1
  27. return SearchTypes::UNKNOWN, SearchModes::OR if possible_type == SearchTypes::UNDETERMINED
  28. return SearchTypes::UNKNOWN_NO_RESULTS, SearchModes::OR
  29. end
Add Comment
Please, Sign In to add comment