mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2023-06-08.git
synced 2024-08-15 00:53:38 +00:00
Declutter search bar to only show search query
This commit changes the way search filters are parsed. Instead of directly appending the data into the search query and creating k:v pairs, all of the search filters are now a URL parameter. This results in a clear look overall and hides much of the logic from the end user. Closes #1969
This commit is contained in:
parent
ded0b31f71
commit
527fa42170
3 changed files with 15 additions and 30 deletions
|
@ -244,7 +244,7 @@ module Invidious::Routes::Playlists
|
||||||
query = env.params.query["q"]?
|
query = env.params.query["q"]?
|
||||||
if query
|
if query
|
||||||
begin
|
begin
|
||||||
search_query, count, items, operators = process_search_query(query, page, user, region: nil)
|
search_query, count, items, operators = process_search_query(env.params.query, query, page, user, region: nil)
|
||||||
videos = items.select { |item| item.is_a? SearchVideo }.map { |item| item.as(SearchVideo) }
|
videos = items.select { |item| item.is_a? SearchVideo }.map { |item| item.as(SearchVideo) }
|
||||||
rescue ex
|
rescue ex
|
||||||
videos = [] of SearchVideo
|
videos = [] of SearchVideo
|
||||||
|
|
|
@ -169,7 +169,7 @@ def produce_channel_search_continuation(ucid, query, page)
|
||||||
return continuation
|
return continuation
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_search_query(query, page, user, region)
|
def process_search_query(url_params, query, page, user, region)
|
||||||
if user
|
if user
|
||||||
user = user.as(User)
|
user = user.as(User)
|
||||||
view_name = "subscriptions_#{sha256(user.email)}"
|
view_name = "subscriptions_#{sha256(user.email)}"
|
||||||
|
@ -183,13 +183,13 @@ def process_search_query(query, page, user, region)
|
||||||
sort = "relevance"
|
sort = "relevance"
|
||||||
subscriptions = nil
|
subscriptions = nil
|
||||||
|
|
||||||
operators = query.split(" ").select { |a| a.match(/\w+:[\w,]+/) }
|
# operators = url_params.split(" ").select { |a| a.match(/\w+:[\,]+/) }
|
||||||
operators.each do |operator|
|
url_params.each do |operator|
|
||||||
key, value = operator.downcase.split(":")
|
key, value = operator
|
||||||
|
|
||||||
case key
|
case key
|
||||||
when "channel", "user"
|
when "channel", "user"
|
||||||
channel = operator.split(":")[-1]
|
channel = value
|
||||||
when "content_type", "type"
|
when "content_type", "type"
|
||||||
content_type = value
|
content_type = value
|
||||||
when "date"
|
when "date"
|
||||||
|
@ -203,11 +203,11 @@ def process_search_query(query, page, user, region)
|
||||||
when "subscriptions"
|
when "subscriptions"
|
||||||
subscriptions = value == "true"
|
subscriptions = value == "true"
|
||||||
else
|
else
|
||||||
operators.delete(operator)
|
url_params.delete(key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
search_query = (query.split(" ") - operators).join(" ")
|
search_query = query
|
||||||
|
|
||||||
if channel
|
if channel
|
||||||
count, items = channel_search(search_query, page, channel)
|
count, items = channel_search(search_query, page, channel)
|
||||||
|
@ -232,20 +232,5 @@ def process_search_query(query, page, user, region)
|
||||||
count, items = search(search_query, search_params, region).as(Tuple)
|
count, items = search(search_query, search_params, region).as(Tuple)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Light processing to flatten search results out of Categories.
|
{search_query, count, items, url_params}
|
||||||
# They should ideally be supported in the future.
|
|
||||||
items_without_category = [] of SearchItem | ChannelVideo
|
|
||||||
items.each do |i|
|
|
||||||
if i.is_a? Category
|
|
||||||
i.contents.each do |nest_i|
|
|
||||||
if !nest_i.is_a? Video
|
|
||||||
items_without_category << nest_i
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
items_without_category << i
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
{search_query, items_without_category.size, items_without_category, operators}
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
<% if operator_hash.fetch("date", "all") == date %>
|
<% if operator_hash.fetch("date", "all") == date %>
|
||||||
<b><%= translate(locale, date) %></b>
|
<b><%= translate(locale, date) %></b>
|
||||||
<% else %>
|
<% else %>
|
||||||
<a href="/search?q=<%= HTML.escape(query.not_nil!.gsub(/ ?date:[a-z]+/, "") + " date:" + date) %>&page=<%= page %>">
|
<a href="/search?q=<%= HTML.escape(query.not_nil!) %>&page=<%= page %>&date=<%= date %>">
|
||||||
<%= translate(locale, date) %>
|
<%= translate(locale, date) %>
|
||||||
</a>
|
</a>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
<% if operator_hash.fetch("content_type", "all") == content_type %>
|
<% if operator_hash.fetch("content_type", "all") == content_type %>
|
||||||
<b><%= translate(locale, content_type) %></b>
|
<b><%= translate(locale, content_type) %></b>
|
||||||
<% else %>
|
<% else %>
|
||||||
<a href="/search?q=<%= HTML.escape(query.not_nil!.gsub(/ ?content_type:[a-z]+/, "") + " content_type:" + content_type) %>&page=<%= page %>">
|
<a href="/search?q=<%= HTML.escape(query.not_nil!) %>&page=<%= page %>&content_type=<%= content_type %>">
|
||||||
<%= translate(locale, content_type) %>
|
<%= translate(locale, content_type) %>
|
||||||
</a>
|
</a>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -53,7 +53,7 @@
|
||||||
<% if operator_hash.fetch("duration", "all") == duration %>
|
<% if operator_hash.fetch("duration", "all") == duration %>
|
||||||
<b><%= translate(locale, duration) %></b>
|
<b><%= translate(locale, duration) %></b>
|
||||||
<% else %>
|
<% else %>
|
||||||
<a href="/search?q=<%= HTML.escape(query.not_nil!.gsub(/ ?duration:[a-z]+/, "") + " duration:" + duration) %>&page=<%= page %>">
|
<a href="/search?q=<%= HTML.escape(query.not_nil!) %>&page=<%= page %>&duration=<%= duration %>">
|
||||||
<%= translate(locale, duration) %>
|
<%= translate(locale, duration) %>
|
||||||
</a>
|
</a>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -68,11 +68,11 @@
|
||||||
<% if operator_hash.fetch("features", "all").includes?(feature) %>
|
<% if operator_hash.fetch("features", "all").includes?(feature) %>
|
||||||
<b><%= translate(locale, feature) %></b>
|
<b><%= translate(locale, feature) %></b>
|
||||||
<% elsif operator_hash.has_key?("features") %>
|
<% elsif operator_hash.has_key?("features") %>
|
||||||
<a href="/search?q=<%= HTML.escape(query.not_nil!.gsub(/features:/, "features:" + feature + ",")) %>&page=<%= page %>">
|
<a href="/search?q=<%= HTML.escape(query.not_nil!) %>&page=<%= page %>&features=<%= HTML.escape(operator_hash["features"] + ",#{feature}") %>">
|
||||||
<%= translate(locale, feature) %>
|
<%= translate(locale, feature) %>
|
||||||
</a>
|
</a>
|
||||||
<% else %>
|
<% else %>
|
||||||
<a href="/search?q=<%= HTML.escape(query.not_nil! + " features:" + feature) %>&page=<%= page %>">
|
<a href="/search?q=<%= HTML.escape(query.not_nil!) %>&page=<%= page %>&features=<%= feature %>">
|
||||||
<%= translate(locale, feature) %>
|
<%= translate(locale, feature) %>
|
||||||
</a>
|
</a>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -87,7 +87,7 @@
|
||||||
<% if operator_hash.fetch("sort", "relevance") == sort %>
|
<% if operator_hash.fetch("sort", "relevance") == sort %>
|
||||||
<b><%= translate(locale, sort) %></b>
|
<b><%= translate(locale, sort) %></b>
|
||||||
<% else %>
|
<% else %>
|
||||||
<a href="/search?q=<%= HTML.escape(query.not_nil!.gsub(/ ?sort:[a-z]+/, "") + " sort:" + sort) %>&page=<%= page %>">
|
<a href="/search?q=<%= HTML.escape(query.not_nil!) %>&page=<%= page %>&sort=<%= sort %>">
|
||||||
<%= translate(locale, sort) %>
|
<%= translate(locale, sort) %>
|
||||||
</a>
|
</a>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
Loading…
Reference in a new issue