From e8eb7077edcd098e352fe9590b52609b023553ee Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 30 Dec 2021 20:42:42 +0700 Subject: [PATCH] add initial search endpoint and improve results$ --- tubearchivist/home/forms.py | 15 +++++++++ tubearchivist/home/src/searching.py | 32 ++++++++++++------- tubearchivist/home/templates/home/search.html | 29 +++++++++++++++++ tubearchivist/home/urls.py | 2 ++ tubearchivist/home/views.py | 17 ++++++++++ tubearchivist/static/css/style.css | 5 +++ 6 files changed, 89 insertions(+), 11 deletions(-) create mode 100644 tubearchivist/home/templates/home/search.html diff --git a/tubearchivist/home/forms.py b/tubearchivist/home/forms.py index f85392d..e19e3c6 100644 --- a/tubearchivist/home/forms.py +++ b/tubearchivist/home/forms.py @@ -116,6 +116,21 @@ class PlaylistSearchForm(forms.Form): ) +class MultiSearchForm(forms.Form): + """multi search form for /search/""" + + searchInput = forms.CharField( + label="", + widget=forms.TextInput( + attrs={ + "autocomplete": "off", + "oninput": "searchMulti(this.value)", + "autofocus": True, + } + ), + ) + + class AddToQueueForm(forms.Form): """text area form to add to downloads""" diff --git a/tubearchivist/home/src/searching.py b/tubearchivist/home/src/searching.py index 535dbb2..b94d056 100644 --- a/tubearchivist/home/src/searching.py +++ b/tubearchivist/home/src/searching.py @@ -184,14 +184,23 @@ class SearchForm: "query": { "multi_match": { "query": search_query, + "type": "bool_prefix", + "operator": "and", + "fuzziness": "auto", "fields": [ - "title", - "tags", "category", - "channel_name", "channel_description", - "playlist_name", + "channel_name._2gram", + "channel_name._3gram", + "channel_name.search_as_you_type", "playlist_description", + "playlist_name._2gram", + "playlist_name._3gram", + "playlist_name.search_as_you_type", + "tags", + "title._2gram", + "title._3gram", + "title.search_as_you_type", ], } }, @@ -208,13 +217,14 @@ class SearchForm: video_results = [] channel_results = [] playlist_results = [] - for result in search_results: - if result["_index"] == "ta_video": - video_results.append(result) - elif result["_index"] == "ta_channel": - channel_results.append(result) - elif result["_index"] == "ta_playlist": - playlist_results.append(result) + if search_results: + for result in search_results: + if result["_index"] == "ta_video": + video_results.append(result) + elif result["_index"] == "ta_channel": + channel_results.append(result) + elif result["_index"] == "ta_playlist": + playlist_results.append(result) all_results = { "video_results": video_results, diff --git a/tubearchivist/home/templates/home/search.html b/tubearchivist/home/templates/home/search.html new file mode 100644 index 0000000..d109263 --- /dev/null +++ b/tubearchivist/home/templates/home/search.html @@ -0,0 +1,29 @@ +{% extends "home/base.html" %} +{% block content %} +
+
+

Search

+
+ +
+

Video Results

+
+

No videos found.

+
+
+
+

Channel Results

+
+

No channels found.

+
+
+
+

Playlist Results

+
+

No playlists found.

+
+
+
+{% endblock content %} diff --git a/tubearchivist/home/urls.py b/tubearchivist/home/urls.py index 8d4ca60..f7acf3e 100644 --- a/tubearchivist/home/urls.py +++ b/tubearchivist/home/urls.py @@ -13,6 +13,7 @@ from home.views import ( LoginView, PlaylistIdView, PlaylistView, + SearchView, SettingsView, VideoView, process, @@ -52,4 +53,5 @@ urlpatterns = [ login_required(PlaylistIdView.as_view()), name="playlist_id", ), + path("search/", SearchView.as_view(), name="search"), ] diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index 6d3cc34..cb274ab 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -20,6 +20,7 @@ from home.forms import ( ApplicationSettingsForm, ChannelSearchForm, CustomAuthForm, + MultiSearchForm, PlaylistSearchForm, SchedulerSettingsForm, SubscribeToChannelForm, @@ -669,6 +670,22 @@ class VideoView(View): return stars +class SearchView(ArchivistResultsView): + """resolves to /search/ + handle cross index search interface + """ + + view_origin = "home" + es_search = False + + def get(self, request): + """handle get request""" + self.initiate_vars(request) + self.context.update({"search_form": MultiSearchForm()}) + + return render(request, "home/search.html", self.context) + + class SettingsView(View): """resolves to /settings/ handle the settings page, display current settings, diff --git a/tubearchivist/static/css/style.css b/tubearchivist/static/css/style.css index e284a67..b62e594 100644 --- a/tubearchivist/static/css/style.css +++ b/tubearchivist/static/css/style.css @@ -657,6 +657,11 @@ button:hover { width: 100%; } +/* multi search page */ +.multi-search-box input { + width: 100%; +} + /* channel overview page */ .channel-list.list { display: block;