autocomplete: refactor javascript to use /autocomplete endpoint.
This refactors the autocomplete Javascript to use a single dedicated /autocomplete.json endpoint instead of a bunch of separate endpoints. This simplifies the autocomplete Javascript by making it so that instead of calling a different endpoint for each type of query (for users, wiki pages, pools, artists, etc), then having to parse the results of each call to get the data we need, we can call a single endpoint that returns exactly what we need. This also means we don't have to parse searches clientside in order to autocomplete metatags. Instead we can just pass the search term to the server and let it parse the search, which is easy to do serverside. Finally, this makes autocomplete easier to test, and it makes it easier to add more sophisticated autocomplete behavior, since most of the logic lives serverside.
This commit is contained in:
@@ -203,6 +203,10 @@ class Artist < ApplicationRecord
|
||||
end
|
||||
|
||||
module SearchMethods
|
||||
def name_matches(query)
|
||||
where_like(:name, normalize_name(query))
|
||||
end
|
||||
|
||||
def any_other_name_matches(regex)
|
||||
where(id: Artist.from("unnest(other_names) AS other_name").where_regex("other_name", regex))
|
||||
end
|
||||
|
||||
@@ -33,6 +33,10 @@ class WikiPage < ApplicationRecord
|
||||
where(title: normalize_title(title))
|
||||
end
|
||||
|
||||
def title_matches(title)
|
||||
where_like(:title, normalize_title(title))
|
||||
end
|
||||
|
||||
def other_names_include(name)
|
||||
name = normalize_other_name(name)
|
||||
subquery = WikiPage.from("unnest(other_names) AS other_name").where_iequals("other_name", name)
|
||||
|
||||
Reference in New Issue
Block a user