diff options
-rw-r--r-- | web/lib/api/v4/search.rb | 11 | ||||
-rw-r--r-- | web/public/js/taginfo.js | 4 | ||||
-rw-r--r-- | web/views/layout.erb | 2 |
3 files changed, 16 insertions, 1 deletions
diff --git a/web/lib/api/v4/search.rb b/web/lib/api/v4/search.rb index e2015c5..c159563 100644 --- a/web/lib/api/v4/search.rb +++ b/web/lib/api/v4/search.rb @@ -143,6 +143,17 @@ class Taginfo < Sinatra::Base }) do query = params[:query] + # searching for the empty string is very expensive, so we'll just return an empty result + if query == '' + return JSON.generate({ + :page => 0, + :rp => 0, + :total => 0, + :url => request.url, + :data => [] + }, json_opts(params[:format])) + end + total = @db.count('search.ftsearch'). condition_if("value MATCH ?", query). get_first_value().to_i diff --git a/web/public/js/taginfo.js b/web/public/js/taginfo.js index c37f29e..c800f2f 100644 --- a/web/public/js/taginfo.js +++ b/web/public/js/taginfo.js @@ -804,6 +804,10 @@ jQuery(document).ready(function() { } }); + jQuery('#search_form').bind('submit', function(event) { + return jQuery('input#search').val() != ''; + }); + jQuery(window).resize(function() { resize_box(); resize_grid(current_grid); diff --git a/web/views/layout.erb b/web/views/layout.erb index 36817a3..1596ffa 100644 --- a/web/views/layout.erb +++ b/web/views/layout.erb @@ -22,7 +22,7 @@ <% end %> </select> </form> - <form action="/search"><input type="text" id="search" name="q" value="<%= h(params[:q]) %>"/></form> + <form id="search_form" action="/search"><input type="text" id="search" name="q" value="<%= h(params[:q]) %>"/></form> </div> <div id="header_logo"> <a href="/"><img width="49" height="49" src="<%= TaginfoConfig.get('instance.icon', '/img/logo/world.png') %>" alt="taginfo"/></a> |