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