aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2014-05-18 22:08:28 +0200
committerJochen Topf <jochen@topf.org>2014-05-18 22:08:28 +0200
commit19e5943636ade0f6dc1767005f13c6470bbfa96e (patch)
tree963234b573bf87e4cbe7684ee7554515847c44a3
parent7a944d65082af044888e3c38093bfadf0d0dbf3d (diff)
downloadtaginfo-19e5943636ade0f6dc1767005f13c6470bbfa96e.tar
taginfo-19e5943636ade0f6dc1767005f13c6470bbfa96e.tar.gz
Disable search when search field is empty.
-rw-r--r--web/lib/api/v4/search.rb11
-rw-r--r--web/public/js/taginfo.js4
-rw-r--r--web/views/layout.erb2
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>