mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-12-23 02:10:15 +00:00
extend SearchForm class with multisearch method for frontend
This commit is contained in:
parent
2a774c3d3e
commit
5fb15b79a4
@ -76,6 +76,7 @@ class PostData:
|
||||
"db-restore": self._db_restore,
|
||||
"fs-rescan": self._fs_rescan,
|
||||
"channel-search": self._channel_search,
|
||||
"multi_search": self._multi_search,
|
||||
"delete-video": self._delete_video,
|
||||
"delete-channel": self._delete_channel,
|
||||
"delete-playlist": self._delete_playlist,
|
||||
@ -289,6 +290,13 @@ class PostData:
|
||||
search_results = SearchForm().search_channels(search_query)
|
||||
return search_results
|
||||
|
||||
def _multi_search(self):
|
||||
"""search through all indexes"""
|
||||
search_query = self.exec_val
|
||||
print("searching for: " + search_query)
|
||||
search_results = SearchForm().multi_search(search_query)
|
||||
return search_results
|
||||
|
||||
def _delete_video(self):
|
||||
"""delete media file, metadata and thumb"""
|
||||
youtube_id = self.exec_val
|
||||
|
@ -176,11 +176,53 @@ class SearchForm:
|
||||
search_results = look_up.get_data()
|
||||
return {"results": search_results}
|
||||
|
||||
def multi_search(self, search_query):
|
||||
"""searching through index"""
|
||||
url = self.ES_URL + "/ta_video,ta_channel,ta_playlist/_search"
|
||||
data = {
|
||||
"size": 30,
|
||||
"query": {
|
||||
"multi_match": {
|
||||
"query": search_query,
|
||||
"fields": [
|
||||
"title",
|
||||
"tags",
|
||||
"category",
|
||||
"channel_name",
|
||||
"channel_description",
|
||||
"playlist_name",
|
||||
"playlist_description",
|
||||
],
|
||||
}
|
||||
},
|
||||
}
|
||||
look_up = SearchHandler(url, data)
|
||||
search_results = look_up.get_data()
|
||||
all_results = self.build_results(search_results)
|
||||
|
||||
return {"results": all_results}
|
||||
|
||||
@staticmethod
|
||||
def search_videos():
|
||||
"""searching for videos"""
|
||||
# TBD palceholder for now
|
||||
return False
|
||||
def build_results(search_results):
|
||||
"""build the all_results dict"""
|
||||
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)
|
||||
|
||||
all_results = {
|
||||
"video_results": video_results,
|
||||
"channel_results": channel_results,
|
||||
"playlist_results": playlist_results,
|
||||
}
|
||||
|
||||
return all_results
|
||||
|
||||
|
||||
class Pagination:
|
||||
|
Loading…
Reference in New Issue
Block a user