diff --git a/app/browse.rb b/app/browse.rb index 024ed238..29d8f7b9 100644 --- a/app/browse.rb +++ b/app/browse.rb @@ -119,16 +119,24 @@ def browse_sites_dataset ds end -get '/browse/search' do - if params[:q] - @title = 'Search Results' - query_count = $redis_cache.get("search_query_count").to_i - if query_count >= $config['google_custom_search_query_limit'] - halt 429, "Query limit reached. Please try again tomorrow." - end +def daily_search_max? + query_count = $redis_cache.get("search_query_count").to_i + $redis_cache.expire("search_query_count", 86400) if query_count == 0 + return true if query_count >= $config['google_custom_search_query_limit'] + false +end +get '/browse/search' do + @title = 'Site Search' + + @daily_search_max_reached = daily_search_max? + + if @daily_search_max_reached + params[:q] = nil + end + + if !params[:q].blank? $redis_cache.incr("search_query_count") - $redis_cache.expire("search_query_count", 86400) if query_count == 0 @start = params[:start].to_i @start = 0 if @start < 0 @@ -173,6 +181,7 @@ get '/browse/search' do end end else + @items = nil @total_results = 0 end diff --git a/views/browse.erb b/views/browse.erb index d2cc26c7..7c1ec385 100644 --- a/views/browse.erb +++ b/views/browse.erb @@ -16,17 +16,17 @@
@@ -40,21 +40,20 @@
-
- <% unless is_education? %> - - - - <% else %> - <% if params[:tag] %> - + <% unless is_education? %> + + + + <% else %> + <% if params[:tag] %> + + <% end %> <% end %> - <% end %>
- +
@@ -145,15 +144,24 @@ <% unless is_education? %> <%== erb :_browse_tags, layout: false %>
-

Text Search

-
- -
- - -
-
-

Search powered by Duck Duck Go

+

Site Search

+ + <% if !daily_search_max? %> +
+
+ + +
+
+ <% else %> +
+
+ + +
+
+

Search powered by Duck Duck Go

+ <% end %>
<% end %>
diff --git a/views/search.erb b/views/search.erb index 34734f83..207128ed 100644 --- a/views/search.erb +++ b/views/search.erb @@ -65,22 +65,43 @@ color: #333; line-height: 1.5; } - - + + - <% if @items.empty? %> + + +
+
+
+

Site Search

+
+ +
+
+
+ + +
+
+
+ +
+ +
+ <% if @daily_search_max_reached %> + Search temporarily unavailable, please try again tomorrow. + <% elsif @items == [] %> No results. - <% else %> + <% elsif !@items.nil? %>
<% @items.each do |item| %>