diff --git a/src/invidious/routes/playlists.cr b/src/invidious/routes/playlists.cr
index 21126d7e..631ca8d4 100644
--- a/src/invidious/routes/playlists.cr
+++ b/src/invidious/routes/playlists.cr
@@ -244,7 +244,7 @@ module Invidious::Routes::Playlists
query = env.params.query["q"]?
if query
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(SearchVideo).map(&.as(SearchVideo))
rescue ex
videos = [] of SearchVideo
diff --git a/src/invidious/routes/search.cr b/src/invidious/routes/search.cr
index 3f1e219f..8ee486c0 100644
--- a/src/invidious/routes/search.cr
+++ b/src/invidious/routes/search.cr
@@ -54,16 +54,19 @@ module Invidious::Routes::Search
user = env.get? "user"
begin
- search_query, count, videos, operators = process_search_query(query, page, user, region: region)
+ search_query, count, videos, operators = process_search_query(env.params.query, query, page, user, region: region)
rescue ex
return error_template(500, ex)
end
- operator_hash = {} of String => String
- operators.each do |operator|
- key, value = operator.downcase.split(":")
- operator_hash[key] = value
- end
+ # Legacy stuff | TODO
+ # operator_hash = {} of String => String
+ # operators.each do |operator|
+ # key, value = operator.downcase.split(":")
+ # operator_hash[key] = value
+ # end
+
+ operator_hash = operators
env.set "search", query
templated "search"
diff --git a/src/invidious/search.cr b/src/invidious/search.cr
index 2095721c..a1d81619 100644
--- a/src/invidious/search.cr
+++ b/src/invidious/search.cr
@@ -169,7 +169,7 @@ def produce_channel_search_continuation(ucid, query, page)
return continuation
end
-def process_search_query(query, page, user, region)
+def process_search_query(url_params, query, page, user, region)
if user
user = user.as(User)
view_name = "subscriptions_#{sha256(user.email)}"
@@ -183,13 +183,18 @@ def process_search_query(query, page, user, region)
sort = "relevance"
subscriptions = nil
- operators = query.split(" ").select(&.match(/\w+:[\w,]+/))
- operators.each do |operator|
- key, value = operator.downcase.split(":")
+ # Legacy behavior. TODO add deprecated support.
+ # operators = query.split(" ").select(&.match(/\w+:[\w,]+/))
+ # operators.each do |operator|
+ # key, value = operator.downcase.split(":")
+
+ # operators = url_params.split(" ").select { |a| a.match(/\w+:[\,]+/) }
+ url_params.each do |operator|
+ key, value = operator
case key
when "channel", "user"
- channel = operator.split(":")[-1]
+ channel = value
when "content_type", "type"
content_type = value
when "date"
@@ -203,11 +208,11 @@ def process_search_query(query, page, user, region)
when "subscriptions"
subscriptions = value == "true"
else
- operators.delete(operator)
+ url_params.delete(key)
end
end
- search_query = (query.split(" ") - operators).join(" ")
+ search_query = query
if channel
count, items = channel_search(search_query, page, channel)
@@ -232,20 +237,5 @@ def process_search_query(query, page, user, region)
count, items = search(search_query, search_params, region).as(Tuple)
end
- # Light processing to flatten search results out of Categories.
- # 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}
+ {search_query, count, items, url_params}
end
diff --git a/src/invidious/views/search.ecr b/src/invidious/views/search.ecr
index db374548..6b10eee9 100644
--- a/src/invidious/views/search.ecr
+++ b/src/invidious/views/search.ecr
@@ -23,7 +23,7 @@
<% if operator_hash.fetch("date", "all") == date %>
<%= translate(locale, date) %>
<% else %>
- &page=<%= page %>">
+
<%= translate(locale, date) %>
<% end %>
@@ -38,7 +38,7 @@
<% if operator_hash.fetch("content_type", "all") == content_type %>
<%= translate(locale, content_type) %>
<% else %>
- &page=<%= page %>">
+
<%= translate(locale, content_type) %>
<% end %>
@@ -53,7 +53,7 @@
<% if operator_hash.fetch("duration", "all") == duration %>
<%= translate(locale, duration) %>
<% else %>
- &page=<%= page %>">
+
<%= translate(locale, duration) %>
<% end %>
@@ -68,11 +68,11 @@
<% if operator_hash.fetch("features", "all").includes?(feature) %>
<%= translate(locale, feature) %>
<% elsif operator_hash.has_key?("features") %>
- &page=<%= page %>">
+ ">
<%= translate(locale, feature) %>
<% else %>
- &page=<%= page %>">
+
<%= translate(locale, feature) %>
<% end %>
@@ -87,7 +87,7 @@
<% if operator_hash.fetch("sort", "relevance") == sort %>
<%= translate(locale, sort) %>
<% else %>
- &page=<%= page %>">
+
<%= translate(locale, sort) %>
<% end %>