refactor search form to use new SearchProcess
This commit is contained in:
parent
dc41e5062d
commit
47c433e7c1
|
@ -39,7 +39,7 @@ class SearchProcess:
|
|||
def _process_result(self, result):
|
||||
"""detect which type of data to process"""
|
||||
index = result["_index"]
|
||||
processed = False
|
||||
processed = {}
|
||||
if index == "ta_video":
|
||||
processed = self._process_video(result["_source"])
|
||||
if index == "ta_channel":
|
||||
|
@ -50,6 +50,10 @@ class SearchProcess:
|
|||
processed = self._process_download(result["_source"])
|
||||
if index == "ta_comment":
|
||||
processed = self._process_comment(result["_source"])
|
||||
if index == "ta_subtitle":
|
||||
processed = self._process_subtitle(result)
|
||||
|
||||
processed.update({"_index": index})
|
||||
|
||||
return processed
|
||||
|
||||
|
@ -139,3 +143,17 @@ class SearchProcess:
|
|||
processed_comments[-1]["comment_replies"].append(comment)
|
||||
|
||||
return processed_comments
|
||||
|
||||
def _process_subtitle(self, result):
|
||||
"""take complete result dict to extract highlight"""
|
||||
subtitle_dict = result["_source"]
|
||||
highlight = result.get("highlight")
|
||||
if highlight:
|
||||
# replace lines with the highlighted markdown
|
||||
subtitle_line = highlight.get("subtitle_line")[0]
|
||||
subtitle_dict.update({"subtitle_line": subtitle_line})
|
||||
|
||||
thumb_path = ThumbManager(subtitle_dict["youtube_id"]).vid_thumb_path()
|
||||
subtitle_dict.update({"vid_thumb_url": f"/cache/{thumb_path}"})
|
||||
|
||||
return subtitle_dict
|
||||
|
|
|
@ -9,6 +9,7 @@ Functionality:
|
|||
import urllib.parse
|
||||
from datetime import datetime
|
||||
|
||||
from api.src.search_processor import SearchProcess
|
||||
from home.src.download.thumbnails import ThumbManager
|
||||
from home.src.es.connect import ElasticWrap
|
||||
from home.src.ta.config import AppConfig
|
||||
|
@ -114,8 +115,8 @@ class SearchForm:
|
|||
def multi_search(self, search_query):
|
||||
"""searching through index"""
|
||||
path, query, query_type = SearchParser(search_query).run()
|
||||
look_up = SearchHandler(path, config=self.CONFIG, data=query)
|
||||
search_results = look_up.get_data()
|
||||
response, _ = ElasticWrap(path).get(data=query)
|
||||
search_results = SearchProcess(response).process()
|
||||
all_results = self.build_results(search_results)
|
||||
|
||||
return {"results": all_results, "queryType": query_type}
|
||||
|
@ -465,7 +466,6 @@ class QueryBuilder:
|
|||
|
||||
query = {
|
||||
"size": 30,
|
||||
"_source": {"excludes": "subtitle_line"},
|
||||
"query": {"bool": {"must": must_list}},
|
||||
"highlight": {
|
||||
"fields": {
|
||||
|
|
|
@ -938,7 +938,7 @@ function populateMultiSearchResults(allResults, queryType) {
|
|||
videoBox.parentElement.style.display = 'block';
|
||||
if (allVideos.length > 0) {
|
||||
for (let index = 0; index < allVideos.length; index++) {
|
||||
const video = allVideos[index].source;
|
||||
const video = allVideos[index];
|
||||
const videoDiv = createVideo(video, defaultVideo);
|
||||
videoBox.appendChild(videoDiv);
|
||||
}
|
||||
|
@ -957,7 +957,7 @@ function populateMultiSearchResults(allResults, queryType) {
|
|||
channelBox.parentElement.style.display = 'block';
|
||||
if (allChannels.length > 0) {
|
||||
for (let index = 0; index < allChannels.length; index++) {
|
||||
const channel = allChannels[index].source;
|
||||
const channel = allChannels[index];
|
||||
const channelDiv = createChannel(channel, defaultChannel);
|
||||
channelBox.appendChild(channelDiv);
|
||||
}
|
||||
|
@ -976,7 +976,7 @@ function populateMultiSearchResults(allResults, queryType) {
|
|||
playlistBox.parentElement.style.display = 'block';
|
||||
if (allPlaylists.length > 0) {
|
||||
for (let index = 0; index < allPlaylists.length; index++) {
|
||||
const playlist = allPlaylists[index].source;
|
||||
const playlist = allPlaylists[index];
|
||||
const playlistDiv = createPlaylist(playlist, defaultPlaylist);
|
||||
playlistBox.appendChild(playlistDiv);
|
||||
}
|
||||
|
@ -995,7 +995,7 @@ function populateMultiSearchResults(allResults, queryType) {
|
|||
if (allFullText.length > 0) {
|
||||
for (let i = 0; i < allFullText.length; i++) {
|
||||
const fullText = allFullText[i];
|
||||
if ('highlight' in fullText) {
|
||||
if ('subtitle_line' in fullText) {
|
||||
const fullTextDiv = createFulltext(fullText);
|
||||
fullTextBox.appendChild(fullTextDiv);
|
||||
}
|
||||
|
@ -1132,19 +1132,14 @@ function createPlaylist(playlist, viewStyle) {
|
|||
}
|
||||
|
||||
function createFulltext(fullText) {
|
||||
const videoId = fullText.source.youtube_id;
|
||||
const videoTitle = fullText.source.title;
|
||||
const thumbUrl = fullText.source.vid_thumb_url;
|
||||
const channelId = fullText.source.subtitle_channel_id;
|
||||
const channelName = fullText.source.subtitle_channel;
|
||||
const subtitleLine = fullText.highlight.subtitle_line[0];
|
||||
const subtitle_start = fullText.source.subtitle_start.split('.')[0];
|
||||
const subtitle_end = fullText.source.subtitle_end.split('.')[0];
|
||||
const videoId = fullText.youtube_id;
|
||||
const subtitle_start = fullText.subtitle_start.split('.')[0];
|
||||
const subtitle_end = fullText.subtitle_end.split('.')[0];
|
||||
const markup = `
|
||||
<a href="#player" data-id="${videoId}" data-position="${subtitle_start}" onclick="createPlayer(this)">
|
||||
<div class="video-thumb-wrap list">
|
||||
<div class="video-thumb">
|
||||
<img src="${thumbUrl}" alt="video-thumb">
|
||||
<img src="${fullText.vid_thumb_url}" alt="video-thumb">
|
||||
</div>
|
||||
<div class="video-play">
|
||||
<img src="/static/img/icon-play.svg" alt="play-icon">
|
||||
|
@ -1153,10 +1148,10 @@ function createFulltext(fullText) {
|
|||
</a>
|
||||
<div class="video-desc list">
|
||||
<p>${subtitle_start} - ${subtitle_end}</p>
|
||||
<p>${subtitleLine}</p>
|
||||
<p>${fullText.subtitle_line}</p>
|
||||
<div>
|
||||
<a href="/channel/${channelId}/"><h3>${channelName}</h3></a>
|
||||
<a class="video-more" href="/video/${videoId}/?t=${subtitle_start}"><h2>${videoTitle}</h2></a>
|
||||
<a href="/channel/${fullText.subtitle_channel_id}/"><h3>${fullText.subtitle_channel}</h3></a>
|
||||
<a class="video-more" href="/video/${videoId}/?t=${subtitle_start}"><h2>${fullText.title}</h2></a>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
|
Loading…
Reference in New Issue