mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-22 11:50:14 +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,
|
"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
|
||||||
|
@ -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:
|
||||||
|
Loading…
Reference in New Issue
Block a user