add initial search endpoint and improve results$

This commit is contained in:
simon 2021-12-30 20:42:42 +07:00
parent 5fb15b79a4
commit e8eb7077ed
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
6 changed files with 89 additions and 11 deletions

View File

@ -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): class AddToQueueForm(forms.Form):
"""text area form to add to downloads""" """text area form to add to downloads"""

View File

@ -184,14 +184,23 @@ class SearchForm:
"query": { "query": {
"multi_match": { "multi_match": {
"query": search_query, "query": search_query,
"type": "bool_prefix",
"operator": "and",
"fuzziness": "auto",
"fields": [ "fields": [
"title",
"tags",
"category", "category",
"channel_name",
"channel_description", "channel_description",
"playlist_name", "channel_name._2gram",
"channel_name._3gram",
"channel_name.search_as_you_type",
"playlist_description", "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,6 +217,7 @@ class SearchForm:
video_results = [] video_results = []
channel_results = [] channel_results = []
playlist_results = [] playlist_results = []
if search_results:
for result in search_results: for result in search_results:
if result["_index"] == "ta_video": if result["_index"] == "ta_video":
video_results.append(result) video_results.append(result)

View File

@ -0,0 +1,29 @@
{% extends "home/base.html" %}
{% block content %}
<div class="boxed-content">
<div class="title-bar">
<h1>Search</h1>
</div>
<div class="multi-search-box">
{{ search_form }}
</div>
<div>
<h2>Video Results</h2>
<div id="video-results" class="video-list grid">
<p>No videos found.</p>
</div>
</div>
<div>
<h2>Channel Results</h2>
<div id="channel-results">
<p>No channels found.</p>
</div>
</div>
<div>
<h2>Playlist Results</h2>
<div id="playlist-results">
<p>No playlists found.</p>
</div>
</div>
</div>
{% endblock content %}

View File

@ -13,6 +13,7 @@ from home.views import (
LoginView, LoginView,
PlaylistIdView, PlaylistIdView,
PlaylistView, PlaylistView,
SearchView,
SettingsView, SettingsView,
VideoView, VideoView,
process, process,
@ -52,4 +53,5 @@ urlpatterns = [
login_required(PlaylistIdView.as_view()), login_required(PlaylistIdView.as_view()),
name="playlist_id", name="playlist_id",
), ),
path("search/", SearchView.as_view(), name="search"),
] ]

View File

@ -20,6 +20,7 @@ from home.forms import (
ApplicationSettingsForm, ApplicationSettingsForm,
ChannelSearchForm, ChannelSearchForm,
CustomAuthForm, CustomAuthForm,
MultiSearchForm,
PlaylistSearchForm, PlaylistSearchForm,
SchedulerSettingsForm, SchedulerSettingsForm,
SubscribeToChannelForm, SubscribeToChannelForm,
@ -669,6 +670,22 @@ class VideoView(View):
return stars 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): class SettingsView(View):
"""resolves to /settings/ """resolves to /settings/
handle the settings page, display current settings, handle the settings page, display current settings,

View File

@ -657,6 +657,11 @@ button:hover {
width: 100%; width: 100%;
} }
/* multi search page */
.multi-search-box input {
width: 100%;
}
/* channel overview page */ /* channel overview page */
.channel-list.list { .channel-list.list {
display: block; display: block;