Skip to content

Commit

Permalink
Add subscriptions search filter
Browse files Browse the repository at this point in the history
  • Loading branch information
omarroth committed Sep 17, 2018
1 parent f38aac8 commit f39ed3d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/invidious.cr
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ get "/search" do |env|
duration = ""
features = [] of String
sort = "relevance"
subscriptions = nil

operators = query.split(" ").select { |a| a.match(/\w+:[\w,]+/) }
operators.each do |operator|
Expand All @@ -451,13 +452,24 @@ get "/search" do |env|
features = value.split(",")
when "sort"
sort = value
when "subscriptions"
subscriptions = value == "true"
end
end

search_query = (query.split(" ") - operators).join(" ")

if channel
count, videos = channel_search(search_query, page, channel)
elsif subscriptions
videos = PG_DB.query_all("SELECT id,title,published,updated,ucid,author FROM (
SELECT *,
to_tsvector(channel_videos.title) ||
to_tsvector(channel_videos.author)
as document
FROM channel_videos
) v_search WHERE v_search.document @@ plainto_tsquery($1) LIMIT 20 OFFSET $2;", search_query, (page - 1) * 20, as: ChannelVideo)
count = videos.size
else
search_params = build_search_params(sort: sort, date: date, content_type: "video",
duration: duration, features: features)
Expand Down

0 comments on commit f39ed3d

Please sign in to comment.