mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
refinements to search
This commit is contained in:
parent
44644cc7fa
commit
16fb3444fa
3 changed files with 82 additions and 44 deletions
|
@ -119,16 +119,24 @@ def browse_sites_dataset
|
||||||
ds
|
ds
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/browse/search' do
|
def daily_search_max?
|
||||||
if params[:q]
|
query_count = $redis_cache.get("search_query_count").to_i
|
||||||
@title = 'Search Results'
|
$redis_cache.expire("search_query_count", 86400) if query_count == 0
|
||||||
query_count = $redis_cache.get("search_query_count").to_i
|
return true if query_count >= $config['google_custom_search_query_limit']
|
||||||
if query_count >= $config['google_custom_search_query_limit']
|
false
|
||||||
halt 429, "Query limit reached. Please try again tomorrow."
|
end
|
||||||
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.incr("search_query_count")
|
||||||
$redis_cache.expire("search_query_count", 86400) if query_count == 0
|
|
||||||
|
|
||||||
@start = params[:start].to_i
|
@start = params[:start].to_i
|
||||||
@start = 0 if @start < 0
|
@start = 0 if @start < 0
|
||||||
|
@ -173,6 +181,7 @@ get '/browse/search' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@items = nil
|
||||||
@total_results = 0
|
@total_results = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -16,17 +16,17 @@
|
||||||
<label class="text-Label" for="sort_by">Sort by:</label>
|
<label class="text-Label" for="sort_by">Sort by:</label>
|
||||||
<div class="select-Container">
|
<div class="select-Container">
|
||||||
<select name="sort_by" id="sort_by" class="input-Select">
|
<select name="sort_by" id="sort_by" class="input-Select">
|
||||||
<option value="special_sauce" <%= params[:sort_by] == 'special_sauce' ? 'selected' : '' %>>Special Sauce</option>
|
<option value="special_sauce" <%= params[:sort_by] == 'special_sauce' ? 'selected' : '' %>>Special Sauce</option>
|
||||||
<option value="random" <%= params[:sort_by] == 'random' ? 'selected' : '' %>>Random</option>
|
<option value="random" <%= params[:sort_by] == 'random' ? 'selected' : '' %>>Random</option>
|
||||||
<option value="most_followed" <%= params[:sort_by] == 'most_followed' ? 'selected' : '' %>>Most Followed</option>
|
<option value="most_followed" <%= params[:sort_by] == 'most_followed' ? 'selected' : '' %>>Most Followed</option>
|
||||||
<option value="last_updated" <%= params[:sort_by] == 'last_updated' ? 'selected' : '' %>>Last Updated</option>
|
<option value="last_updated" <%= params[:sort_by] == 'last_updated' ? 'selected' : '' %>>Last Updated</option>
|
||||||
<option value="views" <%= params[:sort_by] == 'views' ? 'selected' : '' %>>Views</option>
|
<option value="views" <%= params[:sort_by] == 'views' ? 'selected' : '' %>>Views</option>
|
||||||
<option value="tipping_enabled" <%= params[:sort_by] == 'tipping_enabled' ? 'selected' : '' %>>Tipping Enabled</option>
|
<option value="tipping_enabled" <%= params[:sort_by] == 'tipping_enabled' ? 'selected' : '' %>>Tipping Enabled</option>
|
||||||
<% if signed_in? %>
|
<% if signed_in? %>
|
||||||
<option value="newest" <%= params[:sort_by] == 'newest' ? 'selected' : '' %>>Newest</option>
|
<option value="newest" <%= params[:sort_by] == 'newest' ? 'selected' : '' %>>Newest</option>
|
||||||
<% end %>
|
<% end %>
|
||||||
<option value="oldest" <%= params[:sort_by] == 'oldest' ? 'selected' : '' %>>Oldest</option>
|
<option value="oldest" <%= params[:sort_by] == 'oldest' ? 'selected' : '' %>>Oldest</option>
|
||||||
<!-- <option value="robots" <%= params[:sort_by] == 'robots' ? 'selected' : '' %>>Robots</option> -->
|
<!-- <option value="robots" <%= params[:sort_by] == 'robots' ? 'selected' : '' %>>Robots</option> -->
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -40,21 +40,20 @@
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
<div class="col col-50 filter">
|
<div class="col col-50 filter">
|
||||||
<form method="GET" action="browse">
|
|
||||||
<fieldset class="grouping">
|
<fieldset class="grouping">
|
||||||
<% unless is_education? %>
|
<% unless is_education? %>
|
||||||
<label class="text-Label" for="tag"><span class="hide-on-mobile">Filter by </span>Tag:</label>
|
<label class="text-Label" for="tag"><span class="hide-on-mobile">Filter by </span>Tag:</label>
|
||||||
<input class="input-Area typeahead" id="tag" name="tag" type="text" placeholder="pokemon" value="<%= params[:tag] %>" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" dir="auto">
|
<input class="input-Area typeahead" id="tag" name="tag" type="text" placeholder="pokemon" value="<%= params[:tag] %>" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" dir="auto">
|
||||||
<input style="vertical-align: -4px;margin-left: 4px;" type="submit" class="btn-Action" value="Filter">
|
<input style="vertical-align: -4px;margin-left: 4px;" type="submit" class="btn-Action" value="Filter">
|
||||||
<% else %>
|
<% else %>
|
||||||
<% if params[:tag] %>
|
<% if params[:tag] %>
|
||||||
<input name="tag" type="hidden" value="<%= params[:tag] %>">
|
<input name="tag" type="hidden" value="<%= params[:tag] %>">
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="browse-page">
|
<div class="browse-page">
|
||||||
|
@ -145,15 +144,24 @@
|
||||||
<% unless is_education? %>
|
<% unless is_education? %>
|
||||||
<%== erb :_browse_tags, layout: false %>
|
<%== erb :_browse_tags, layout: false %>
|
||||||
<div class="row content misc">
|
<div class="row content misc">
|
||||||
<h3>Text Search</h3>
|
<h3>Site Search</h3>
|
||||||
<form id="searchForm" method="GET" action="https://duckduckgo.com" class="content" onsubmit="return addSiteToSearch()">
|
|
||||||
<input name="csrf_token" type="hidden" value="<%= csrf_token %>">
|
<% if !daily_search_max? %>
|
||||||
<fieldset>
|
<form method="GET" action="/browse/search">
|
||||||
<input id="searchQuery" name="q" type="text" placeholder="keywords" class="input-Area" autocapitalize="off" autocorrect="off" value="<%= flash[:username] %>" style="width: 50%">
|
<fieldset>
|
||||||
<input class="btn btn-Action" type="submit" value="Search">
|
<input name="q" type="text" placeholder="keywords" class="input-Area" autocapitalize="off" autocorrect="off" style="width: 50%">
|
||||||
</fieldset>
|
<input class="btn btn-Action" type="submit" value="Search">
|
||||||
</form>
|
</fieldset>
|
||||||
<p>Search powered by <a href="https://duckduckgo.com/">Duck Duck Go</a></p>
|
</form>
|
||||||
|
<% else %>
|
||||||
|
<form id="searchForm" method="GET" action="https://duckduckgo.com" class="content" onsubmit="return addSiteToSearch()">
|
||||||
|
<fieldset>
|
||||||
|
<input id="searchQuery" name="q" type="text" placeholder="keywords" class="input-Area" autocapitalize="off" autocorrect="off" value="<%= flash[:username] %>" style="width: 50%">
|
||||||
|
<input class="btn btn-Action" type="submit" value="Search">
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
<p>Search powered by <a href="https://duckduckgo.com/">Duck Duck Go</a></p>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -65,22 +65,43 @@
|
||||||
color: #333;
|
color: #333;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
<div class="header-Outro">
|
<div class="header-Outro">
|
||||||
<div class="row content single-Col">
|
<div class="row content single-Col">
|
||||||
<h1>Neocities Search</h1>
|
<h1>Neocities Search</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="content single-Col misc-page">
|
-->
|
||||||
<h1>Search Results</h1>
|
|
||||||
|
|
||||||
<% if @items.empty? %>
|
|
||||||
|
|
||||||
|
<div class="header-Outro with-columns browse-page">
|
||||||
|
<div class="row content">
|
||||||
|
<div class="col col-100">
|
||||||
|
<h1>Site Search</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form id="search_criteria" action="/browse/search" method="GET">
|
||||||
|
<div class="col col-50 filter">
|
||||||
|
<fieldset class="grouping">
|
||||||
|
<input name="q" type="text" class="input-Area" value="<%= params[:q] %>">
|
||||||
|
<input style="vertical-align: 5px; margin-left: 4px;" type="submit" class="btn-Action" value="Search">
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="content single-Col misc-page">
|
||||||
|
<% if @daily_search_max_reached %>
|
||||||
|
Search temporarily unavailable, please try again tomorrow.
|
||||||
|
<% elsif @items == [] %>
|
||||||
No results.
|
No results.
|
||||||
<% else %>
|
<% elsif !@items.nil? %>
|
||||||
<div class="search-results">
|
<div class="search-results">
|
||||||
<% @items.each do |item| %>
|
<% @items.each do |item| %>
|
||||||
<div class="result-item">
|
<div class="result-item">
|
||||||
|
|
Loading…
Add table
Reference in a new issue