diff --git a/tubearchivist/home/src/frontend.py b/tubearchivist/home/src/frontend.py index fc6c5ae..12d95e9 100644 --- a/tubearchivist/home/src/frontend.py +++ b/tubearchivist/home/src/frontend.py @@ -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 diff --git a/tubearchivist/home/src/searching.py b/tubearchivist/home/src/searching.py index 62fa65f..535dbb2 100644 --- a/tubearchivist/home/src/searching.py +++ b/tubearchivist/home/src/searching.py @@ -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: