Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…gine-shopee into develop
  • Loading branch information
vectornguyen76 committed Nov 13, 2023
2 parents 20cf3de + 733d24e commit 8a3d1ba
Show file tree
Hide file tree
Showing 6 changed files with 266 additions and 44 deletions.
11 changes: 11 additions & 0 deletions backend/src/text_search/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,14 @@ async def search(query: str, size: int, jwt_data: JWTData = Depends(parse_jwt_de
result = await service.text_search(user_id=jwt_data.user_id, query=query, size=size)

return result


@router.get("/auto-complete", response_model=list[SearchResponse])
async def auto_complete(
query: str, size: int, jwt_data: JWTData = Depends(parse_jwt_demo)
):
result = await service.auto_complete(
user_id=jwt_data.user_id, query=query, size=size
)

return result
19 changes: 19 additions & 0 deletions backend/src/text_search/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,22 @@ async def text_search(user_id: int, query: str, size: int) -> dict[str, Any] | N
)
except Exception as e:
LOGGER.error(f"An error occurred: {str(e)}")


async def auto_complete(user_id: int, query: str, size: int) -> dict[str, Any] | None:
async with httpx.AsyncClient() as client:
try:
response = await client.get(
f"{settings.TEXT_SEARCH_URL}/auto-complete-search?query={query}&size={size}"
)

if response.status_code == 200:
search_results = response.json()

return search_results
else:
LOGGER.error(
f"Failed to call the API. Status code: {response.status_code} - {response.text}"
)
except Exception as e:
LOGGER.error(f"An error occurred: {str(e)}")
119 changes: 118 additions & 1 deletion frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"react-dom": "18.2.0",
"react-icons": "^4.10.1",
"sharp": "^0.32.6",
"typescript": "5.1.6"
"typescript": "5.1.6",
"use-debounce": "^10.0.0"
},
"devDependencies": {
"autoprefixer": "10.4.15",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Inter } from "next/font/google";
const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
title: "Search Engine on Shopee",
title: "Search Engine",
description:
"Search Engine on Shopee apply full text search, semantic search and image search.",
};
Expand Down
Loading

0 comments on commit 8a3d1ba

Please sign in to comment.