Commit 2380546ea90ac7d6ccd80ed573063ef6809716a7
1 parent
561b6145
Exists in
master
and in
29 other branches
Removing full_text_search from set profile region lib
Showing
1 changed file
with
11 additions
and
7 deletions
Show diff stats
lib/set_profile_region_from_city_state.rb
| ... | ... | @@ -25,16 +25,20 @@ module SetProfileRegionFromCityState |
| 25 | 25 | |
| 26 | 26 | def region_from_city_and_state |
| 27 | 27 | if @change_region |
| 28 | - s = plugins.first(:find_by_contents, State, self.state)[:results].first | |
| 29 | - if s | |
| 30 | - c = plugins.first(:find_by_contents, City, self.city, {}, {:filter_queries => ["parent_id:#{s.id}"]})[:results].first | |
| 31 | - self.region = c | |
| 32 | - else | |
| 33 | - self.region = nil | |
| 34 | - end | |
| 28 | + self.region = nil | |
| 29 | + state = search_region(State, self.state) | |
| 30 | + region = search_region(City.where(:parent_id => state.id), self.city) if state | |
| 35 | 31 | end |
| 36 | 32 | end |
| 37 | 33 | |
| 34 | + private | |
| 35 | + | |
| 36 | + def search_region(scope, query) | |
| 37 | + return [] if !query | |
| 38 | + query = query.downcase.strip | |
| 39 | + scope.where(['lower(name)=? OR lower(abbreviation)=? OR lower(acronym)=?', query, query, query]).first | |
| 40 | + end | |
| 41 | + | |
| 38 | 42 | end |
| 39 | 43 | |
| 40 | 44 | end | ... | ... |