Add pattern matching for domain name field in search #2122

This commit is contained in:
Martin Lensment 2015-07-30 14:26:23 +03:00
parent 31d19ff64e
commit 4b9e082712
3 changed files with 12 additions and 3 deletions

View file

@ -15,6 +15,16 @@ class Admin::DomainsController < AdminController
normalize_search_parameters do
@q = domains.search(params[:q])
@domains = @q.result.page(params[:page])
if @domains.count == 1
redirect_to [:admin, @domains.first] and return
elsif @domains.count == 0 && params[:q][:name_matches] !~ /^%.+%$/
# if we do not get any results, add wildcards to the name field and search again
n_cache = params[:q][:name_matches]
params[:q][:name_matches] = "%#{params[:q][:name_matches]}%"
@q = domains.search(params[:q])
@domains = @q.result.page(params[:page])
params[:q][:name_matches] = n_cache # we don't want to show wildcards in search form
end
end
end