Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UserSearch #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,28 @@

after_initialize do
# https://github.com/discourse/discourse/blob/master/lib/plugin/instance.rb
class ::UserSearch
module OverridingFilter
def filtered_by_term_users
if @term.blank?
scoped_users
elsif SiteSetting.enable_names? && @term !~ /[_\.-]/
query = Search.ts_query(term: @term, ts_config: "simple")

scoped_users
.includes(:user_search_data)
.where("user_search_data.search_data @@ #{query}")
.order(DB.sql_fragment("CASE WHEN INSTR(username_lower, ?) > 0 THEN 0 ELSE 1 END ASC", @term))
else
scoped_users.where("INSTR(username_lower, :term) > 0", term: @term)
end
end
end

singleton_class.prepend OverridingFilter

end

class ::Search
module OverridingPrepareData
def prepare_data(search_data, purpose = :query)
Expand Down