Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def recover_search_results
- # if we have more than 4 terms, the do a NAME 'OR' search
- return SearchTypes::NAME, SearchModes::OR if search_terms.to_s.split.length >= 4
- # try to expand searched geography
- # if at nationwide, just give up all hope
- if expansion_factor && expansion_factor.to_i >= 4
- return SearchTypes::UNKNOWN, SearchModes::OR
- end
- if self.expansion_factor
- self.expansion_factor = self.expansion_factor.to_i + 1
- else
- self.expansion_factor = 1
- end
- search_request = Yellowpages::Search::SearchRequest.new(to_search_attributes)
- possible_type, possible_mode = SearchTypes.get_search_type_and_mode(search_request)
- raise "Critical Error Determining Search Type, Unrecognized Search Type #{possible_type}" unless SearchTypes.include?(possible_type)
- # if no results were found using our'recovery' methods, then we still want to return
- # a combo page. This is done by returning (Search::SearchTypes::UNKNOWN, Search::SearchModes::OR)
- # Also, don't forget to set teh expansion level back to the original value if expanding didn't find
- # results.
- return possible_type, possible_mode unless [SearchTypes::UNDETERMINED, SearchTypes::UNKNOWN_NO_RESULTS].include?(possible_type)
- self.expansion_factor -= 1
- return SearchTypes::UNKNOWN, SearchModes::OR if possible_type == SearchTypes::UNDETERMINED
- return SearchTypes::UNKNOWN_NO_RESULTS, SearchModes::OR
- end
Add Comment
Please, Sign In to add comment