mirror of
https://github.com/discourse/discourse.git
synced 2024-12-19 12:33:47 +08:00
14cf8eacf1
Currently, when doing `@mention` for users we have 0 tolerance for typos and misspellings. With this patch, if a user search doesn't return enough results we go and use `pg_trgm` features to try and find more matches based on trigrams of usernames and names. It also introduces GiST indexes on those fields in order to improve performance of this search, going from 130ms down to 15ms in my tests. This is all gated in a feature flag and can be enabled by running `SiteSetting.user_search_similar_results = true` in the rails console.
25 lines
508 B
Ruby
25 lines
508 B
Ruby
# frozen_string_literal: true
|
|
|
|
class AddTrigramIndexesToUsers < ActiveRecord::Migration[7.0]
|
|
disable_ddl_transaction!
|
|
|
|
def change
|
|
add_index(
|
|
:users,
|
|
:username_lower,
|
|
using: "gist",
|
|
opclass: :gist_trgm_ops,
|
|
algorithm: :concurrently,
|
|
name: "index_users_on_username_lower_trgm",
|
|
)
|
|
add_index(
|
|
:users,
|
|
:name,
|
|
using: "gist",
|
|
opclass: :gist_trgm_ops,
|
|
algorithm: :concurrently,
|
|
name: "index_users_on_name_trgm",
|
|
)
|
|
end
|
|
end
|