From b4844d447739f7f5bcdb4a918a0dc6926ce63395 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 18 Nov 2014 14:32:13 +1100 Subject: [PATCH] FIX: correct old username index (in some cases search was not finding accounts) --- app/models/search_observer.rb | 2 +- db/migrate/20141118011735_correct_username_search.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20141118011735_correct_username_search.rb diff --git a/app/models/search_observer.rb b/app/models/search_observer.rb index 78233b249..7739801bc 100644 --- a/app/models/search_observer.rb +++ b/app/models/search_observer.rb @@ -66,7 +66,7 @@ class SearchObserver < ActiveRecord::Observer end end if obj.class == User && (obj.username_changed? || obj.name_changed?) - SearchObserver.update_users_index(obj.id, obj.username, obj.name) + SearchObserver.update_users_index(obj.id, obj.username_lower, obj.name.downcase) end if obj.class == Topic && obj.title_changed? diff --git a/db/migrate/20141118011735_correct_username_search.rb b/db/migrate/20141118011735_correct_username_search.rb new file mode 100644 index 000000000..fad33f0f1 --- /dev/null +++ b/db/migrate/20141118011735_correct_username_search.rb @@ -0,0 +1,11 @@ +class CorrectUsernameSearch < ActiveRecord::Migration + def up + execute "update user_search_data + set search_data = TO_TSVECTOR('simple', username_lower || ' ' || lower(name)) + from users + where users.id = user_search_data.user_id" + end + + def down + end +end