정말 초간단하게 검색엔진을 구축해 볼 수 있다.
몽고 DB에서 Elastic으로 가서 하는 재구축은 추후에...
from fastapi import FastAPI
from elasticsearch6 import Elasticsearch
# from urllib.parse import unquote
es = Elasticsearch()
app = FastAPI()
@app.get("/search/")
async def search(query: str):
print(query)
# query = unquote(query)
# print(query)
script_query = {
"bool": {
"should": [
{
"match": {
"title.nori": query
}
},
{
"match": {
"synopsis.nori": query
}
}
]
}
}
search_result = es.search(index="movie", body={"query": script_query})
results = search_result["hits"]["hits"]
return {"results": results}
결과
'python' 카테고리의 다른 글
Chatgpt Completion create 메소드 정리 (0) | 2023.11.16 |
---|---|
Python + ChatGPT(gpt-3.5-turbo용으로 변경) (0) | 2023.11.16 |
Chat GPT + Python (1) | 2023.11.09 |
엘라스틱 서치: Nori 토크나이저를 사용한 검색(python 연결) (0) | 2023.07.29 |
Elastic Search Python 연결 (0) | 2023.07.29 |