/artists: add wildcard, regex search to url field (#3900)
Allow searching the URL field by regex or by wildcard. If the query looks like `/twitter/` do a regex search, otherwise if it looks like `http://www.twitter.com/*` do a wildcard search, otherwise if it looks like an url do an artist finder search, lastly if it looks like `twitter` do a `*twitter*` search.
This commit is contained in:
@@ -153,7 +153,7 @@ module Sources
|
||||
end
|
||||
|
||||
def artists
|
||||
Artist.url_matches(normalize_for_artist_finder)
|
||||
Artist.find_artists(normalize_for_artist_finder)
|
||||
end
|
||||
|
||||
def file_url
|
||||
|
||||
@@ -147,7 +147,7 @@ class Artist < ApplicationRecord
|
||||
%r!\Ahttps?://(?:[a-zA-Z0-9_-]+\.)*#{domain}/\z!i
|
||||
end)
|
||||
|
||||
def url_matches(url)
|
||||
def find_artists(url)
|
||||
url = ArtistUrl.normalize(url)
|
||||
artists = []
|
||||
|
||||
@@ -469,6 +469,18 @@ class Artist < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def url_matches(query)
|
||||
if query =~ %r!\A/(.*)/\z!
|
||||
where(id: ArtistUrl.where_regex(:url, $1).select(:artist_id))
|
||||
elsif query.include?("*")
|
||||
where(id: ArtistUrl.where_like(:url, query).select(:artist_id))
|
||||
elsif query =~ %r!\Ahttps?://!i
|
||||
find_artists(query)
|
||||
else
|
||||
where(id: ArtistUrl.where_like(:url, "*#{query}*").select(:artist_id))
|
||||
end
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = super
|
||||
|
||||
|
||||
Reference in New Issue
Block a user