added order and security
Browse files
App/Embedding/utils/Elastic.py
CHANGED
@@ -1,15 +1,13 @@
|
|
1 |
from elasticsearch import Elasticsearch
|
|
|
2 |
|
|
|
3 |
|
4 |
# initialize elasticSearch
|
5 |
-
es = Elasticsearch(
|
6 |
-
[
|
7 |
-
"https://u46hxt12c:3qcatejimc@movies-search-5264494072.us-west-2.bonsaisearch.net:443"
|
8 |
-
]
|
9 |
-
)
|
10 |
|
11 |
|
12 |
-
def FetchDocuments(ids):
|
13 |
es_index_name = "telegram_media"
|
14 |
res = es.search(
|
15 |
index=es_index_name,
|
@@ -20,17 +18,17 @@ def FetchDocuments(ids):
|
|
20 |
"inner_hits": {
|
21 |
"name": "simple",
|
22 |
"collapse": {"field": "caption"},
|
23 |
-
"sort": [{"season_number": {"order":
|
24 |
"size": 1,
|
25 |
},
|
26 |
},
|
27 |
},
|
28 |
)
|
29 |
|
30 |
-
response=[]
|
31 |
for data in res["hits"]["hits"]:
|
32 |
-
temp=data["inner_hits"]["simple"]["hits"]["hits"][0][
|
33 |
-
temp[
|
34 |
|
35 |
response.append(temp)
|
36 |
return response
|
|
|
1 |
from elasticsearch import Elasticsearch
|
2 |
+
import os
|
3 |
|
4 |
+
ELASTIC_HOST = os.environ.get("ELASTIC_HOST")
|
5 |
|
6 |
# initialize elasticSearch
|
7 |
+
es = Elasticsearch([ELASTIC_HOST])
|
|
|
|
|
|
|
|
|
8 |
|
9 |
|
10 |
+
def FetchDocuments(ids, order="asc"):
|
11 |
es_index_name = "telegram_media"
|
12 |
res = es.search(
|
13 |
index=es_index_name,
|
|
|
18 |
"inner_hits": {
|
19 |
"name": "simple",
|
20 |
"collapse": {"field": "caption"},
|
21 |
+
"sort": [{"season_number": {"order": order}}],
|
22 |
"size": 1,
|
23 |
},
|
24 |
},
|
25 |
},
|
26 |
)
|
27 |
|
28 |
+
response = []
|
29 |
for data in res["hits"]["hits"]:
|
30 |
+
temp = data["inner_hits"]["simple"]["hits"]["hits"][0]["_source"]
|
31 |
+
temp["_id"] = data["inner_hits"]["simple"]["hits"]["hits"][0]["_id"]
|
32 |
|
33 |
response.append(temp)
|
34 |
return response
|
App/Embedding/utils/Initialize.py
CHANGED
@@ -72,7 +72,7 @@ def IdSearch(query: str, background_task: BackgroundTasks):
|
|
72 |
|
73 |
|
74 |
def LookUpIds(imdb_ids: list[str]):
|
75 |
-
return FetchDocuments(imdb_ids)
|
76 |
|
77 |
|
78 |
def TextSearch(query: str, filter=None):
|
|
|
72 |
|
73 |
|
74 |
def LookUpIds(imdb_ids: list[str]):
|
75 |
+
return FetchDocuments(imdb_ids, order="desc")
|
76 |
|
77 |
|
78 |
def TextSearch(query: str, filter=None):
|