extend SearchForm class with multisearch method for frontend

This commit is contained in:
simon 2021-12-30 15:58:15 +07:00
parent 2a774c3d3e
commit 5fb15b79a4
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 54 additions and 4 deletions

View File

@ -76,6 +76,7 @@ class PostData:
"db-restore": self._db_restore, "db-restore": self._db_restore,
"fs-rescan": self._fs_rescan, "fs-rescan": self._fs_rescan,
"channel-search": self._channel_search, "channel-search": self._channel_search,
"multi_search": self._multi_search,
"delete-video": self._delete_video, "delete-video": self._delete_video,
"delete-channel": self._delete_channel, "delete-channel": self._delete_channel,
"delete-playlist": self._delete_playlist, "delete-playlist": self._delete_playlist,
@ -289,6 +290,13 @@ class PostData:
search_results = SearchForm().search_channels(search_query) search_results = SearchForm().search_channels(search_query)
return search_results 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): def _delete_video(self):
"""delete media file, metadata and thumb""" """delete media file, metadata and thumb"""
youtube_id = self.exec_val youtube_id = self.exec_val

View File

@ -176,11 +176,53 @@ class SearchForm:
search_results = look_up.get_data() search_results = look_up.get_data()
return {"results": search_results} 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 @staticmethod
def search_videos(): def build_results(search_results):
"""searching for videos""" """build the all_results dict"""
# TBD palceholder for now video_results = []
return False 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: class Pagination: