From 2a76641e492929c1c69a6eeeeafe3abceec2257e Mon Sep 17 00:00:00 2001 From: tangwang Date: Sat, 8 Nov 2025 08:47:33 +0800 Subject: [PATCH] config --- .env | 2 +- .env.example | 2 +- DEPLOYMENT.md | 24 ++++++++++++------------ HighLevelDesign.md | 2 ++ IMPLEMENTATION_SUMMARY.md | 10 +++++----- QUICKSTART.md | 30 +++++++++++++++--------------- USER_GUIDE.md | 26 +++++++++++++------------- api/app.py | 4 ++-- config/env_config.py | 2 +- frontend/index.html | 2 +- frontend/static/js/app.js | 4 ++-- main.py | 2 +- scripts/frontend_server.py | 2 +- scripts/start_frontend.sh | 4 ++-- setup.sh | 2 ++ start_all.sh | 10 ++++++---- 16 files changed, 67 insertions(+), 61 deletions(-) diff --git a/.env b/.env index 03ed1a8..76c730b 100644 --- a/.env +++ b/.env @@ -19,7 +19,7 @@ CUSTOMER_ID=customer1 # API Service Configuration API_HOST=0.0.0.0 -API_PORT=8000 +API_PORT=6002 # Embedding Models TEXT_MODEL_DIR=/data/tw/models/bge-m3 diff --git a/.env.example b/.env.example index eedfb30..6f45d6a 100644 --- a/.env.example +++ b/.env.example @@ -19,7 +19,7 @@ CUSTOMER_ID=customer1 # API Service Configuration API_HOST=0.0.0.0 -API_PORT=8000 +API_PORT=6002 # Embedding Models TEXT_MODEL_DIR=/data/tw/models/bge-m3 diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index 2e2ad64..a612d14 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -36,7 +36,7 @@ cd /data/tw/SearchEngine ./start_all.sh ``` -然后访问: http://localhost:8080 +然后访问: http://localhost:6003 ### 方式2: 分步启动 @@ -88,7 +88,7 @@ DEEPL_AUTH_KEY=c9293ab4-ad25-479b-919f-ab4e63b429ed CUSTOMER_ID=customer1 API_HOST=0.0.0.0 -API_PORT=8000 +API_PORT=6002 ``` ## 服务端口 @@ -96,9 +96,9 @@ API_PORT=8000 | 服务 | 端口 | URL | |------|------|-----| | Elasticsearch | 9200 | http://localhost:9200 | -| Backend API | 8000 | http://localhost:8000 | -| Frontend Web | 8080 | http://localhost:8080 | -| API Docs | 8000 | http://localhost:8000/docs | +| Backend API | 6002 | http://localhost:6002 | +| Frontend Web | 6003 | http://localhost:6003 | +| API Docs | 6002 | http://localhost:6002/docs | ## 测试流程 @@ -162,10 +162,10 @@ nohup ./scripts/start_backend.sh > logs/backend.log 2>&1 & sleep 5 # 测试健康检查 -curl http://localhost:8000/admin/health +curl http://localhost:6002/admin/health # 测试搜索 -curl -X POST http://localhost:8000/search/ \ +curl -X POST http://localhost:6002/search/ \ -H "Content-Type: application/json" \ -d '{"query": "消防", "size": 5}' ``` @@ -176,7 +176,7 @@ curl -X POST http://localhost:8000/search/ \ # 启动前端 ./scripts/start_frontend.sh -# 然后在浏览器访问: http://localhost:8080 +# 然后在浏览器访问: http://localhost:6003 ``` ## 故障排除 @@ -234,8 +234,8 @@ cat .env | grep ES_ **解决**: ```bash # 查看占用端口的进程 -lsof -i :8000 # 后端 -lsof -i :8080 # 前端 +lsof -i :6002 # 后端 +lsof -i :6003 # 前端 # 杀掉进程 kill -9 @@ -246,12 +246,12 @@ kill -9 ## 下一步 1. **测试搜索功能** - - 打开 http://localhost:8080 + - 打开 http://localhost:6003 - 尝试不同的搜索查询 - 测试布尔操作符 2. **查看API文档** - - 访问 http://localhost:8000/docs + - 访问 http://localhost:6002/docs - 了解所有可用的API端点 3. **自定义配置** diff --git a/HighLevelDesign.md b/HighLevelDesign.md index 94b85ff..397a9f7 100644 --- a/HighLevelDesign.md +++ b/HighLevelDesign.md @@ -112,6 +112,8 @@ if response.status_code == 200: 支持多种匹配方式,如AND、OR、RANK、NOTAND以及(),优先级从高到低为(),ANDNOT,AND,OR,RANK。 default域的相关性,是代码里面单独计算,是特定的深度定制优化的,暂时不做配置化。 +多语言搜索: +对外提供的服务 用default域搜索就行,但是内部需要通过配置翻译为多种语言(配置几种目标语言 默认中文、英文,并且设置对应的检索域),然后分别到对应的字段搜索,中文字段到配置的中文title搜索,英文到对应的英文title搜索。 暂时具体实现为 bm25()+0.2*text_embedding_relevence(也就是knn检索表达式的打分) bm25打分(base_query): diff --git a/IMPLEMENTATION_SUMMARY.md b/IMPLEMENTATION_SUMMARY.md index ac6d145..195906b 100644 --- a/IMPLEMENTATION_SUMMARY.md +++ b/IMPLEMENTATION_SUMMARY.md @@ -251,7 +251,7 @@ python data/customer1/ingest_customer1.py \ ```bash python -m api.app \ --host 0.0.0.0 \ - --port 8000 \ + --port 6002 \ --customer customer1 \ --es-host http://localhost:9200 ``` @@ -260,17 +260,17 @@ python -m api.app \ ```bash # Simple Chinese query (auto-translates to English/Russian) -curl -X POST http://localhost:8000/search/ \ +curl -X POST http://localhost:6002/search/ \ -H "Content-Type: application/json" \ -d '{"query": "芭比娃娃", "size": 10}' # Boolean query -curl -X POST http://localhost:8000/search/ \ +curl -X POST http://localhost:6002/search/ \ -H "Content-Type: application/json" \ -d '{"query": "toy AND (barbie OR doll) ANDNOT cheap", "size": 10}' # Query with filters -curl -X POST http://localhost:8000/search/ \ +curl -X POST http://localhost:6002/search/ \ -H "Content-Type: application/json" \ -d '{ "query": "消防", @@ -279,7 +279,7 @@ curl -X POST http://localhost:8000/search/ \ }' # Image search -curl -X POST http://localhost:8000/search/image \ +curl -X POST http://localhost:6002/search/image \ -H "Content-Type: application/json" \ -d '{ "image_url": "https://oss.essa.cn/example.jpg", diff --git a/QUICKSTART.md b/QUICKSTART.md index 18ee4d1..2c10055 100644 --- a/QUICKSTART.md +++ b/QUICKSTART.md @@ -46,10 +46,10 @@ python ingest_customer1.py \ # 3. Start API service cd ../.. -python -m api.app --host 0.0.0.0 --port 8000 +python -m api.app --host 0.0.0.0 --port 6002 # 4. Test search -curl -X POST http://localhost:8000/search/ \ +curl -X POST http://localhost:6002/search/ \ -H "Content-Type: application/json" \ -d '{"query": "消防", "size": 5}' ``` @@ -72,23 +72,23 @@ python ingest_customer1.py \ cd ../.. python -m api.app \ --host 0.0.0.0 \ - --port 8000 \ + --port 6002 \ --customer customer1 \ --es-host http://localhost:9200 # 4. Test various searches # Simple search -curl -X POST http://localhost:8000/search/ \ +curl -X POST http://localhost:6002/search/ \ -H "Content-Type: application/json" \ -d '{"query": "芭比娃娃", "size": 10}' # Boolean search -curl -X POST http://localhost:8000/search/ \ +curl -X POST http://localhost:6002/search/ \ -H "Content-Type: application/json" \ -d '{"query": "toy AND (barbie OR doll)", "size": 10}' # With filters -curl -X POST http://localhost:8000/search/ \ +curl -X POST http://localhost:6002/search/ \ -H "Content-Type: application/json" \ -d '{"query": "娃娃", "size": 10, "filters": {"categoryName_keyword": "芭比"}}' ``` @@ -96,8 +96,8 @@ curl -X POST http://localhost:8000/search/ \ ## API Documentation Once the service is running, visit: -- **Swagger UI**: http://localhost:8000/docs -- **ReDoc**: http://localhost:8000/redoc +- **Swagger UI**: http://localhost:6002/docs +- **ReDoc**: http://localhost:6002/redoc ## Common Issues @@ -131,33 +131,33 @@ export DEEPL_API_KEY="your-key" ### Test Health ```bash -curl http://localhost:8000/admin/health +curl http://localhost:6002/admin/health ``` ### Test Configuration ```bash -curl http://localhost:8000/admin/config +curl http://localhost:6002/admin/config ``` ### Test Index Stats ```bash -curl http://localhost:8000/admin/stats +curl http://localhost:6002/admin/stats ``` ### Test Search ```bash # Chinese query (auto-translates to English/Russian) -curl -X POST http://localhost:8000/search/ \ +curl -X POST http://localhost:6002/search/ \ -H "Content-Type: application/json" \ -d '{"query": "消防套", "size": 5}' # English query -curl -X POST http://localhost:8000/search/ \ +curl -X POST http://localhost:6002/search/ \ -H "Content-Type: application/json" \ -d '{"query": "fire control set", "size": 5}' # Russian query -curl -X POST http://localhost:8000/search/ \ +curl -X POST http://localhost:6002/search/ \ -H "Content-Type: application/json" \ -d '{"query": "Наборы для пожаротушения", "size": 5}' ``` @@ -193,4 +193,4 @@ For issues or questions, refer to: - **README.md**: Comprehensive documentation - **IMPLEMENTATION_SUMMARY.md**: Technical details - **CLAUDE.md**: Development guidelines -- **API Docs**: http://localhost:8000/docs +- **API Docs**: http://localhost:6002/docs diff --git a/USER_GUIDE.md b/USER_GUIDE.md index cdadcdf..aac2e10 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -16,9 +16,9 @@ cd /data/tw/SearchEngine 4. 启动前端Web界面 启动完成后,访问: -- **前端界面**: http://localhost:8080 -- **后端API**: http://localhost:8000 -- **API文档**: http://localhost:8000/docs +- **前端界面**: http://localhost:6003 +- **后端API**: http://localhost:6002 +- **API文档**: http://localhost:6002/docs ### 停止服务 @@ -65,7 +65,7 @@ cd /data/tw/SearchEngine ./scripts/start_backend.sh ``` -后端API会在 http://localhost:8000 启动 +后端API会在 http://localhost:6002 启动 ### 4. 启动前端 @@ -73,7 +73,7 @@ cd /data/tw/SearchEngine ./scripts/start_frontend.sh ``` -前端界面会在 http://localhost:8080 启动 +前端界面会在 http://localhost:6003 启动 --- @@ -100,7 +100,7 @@ CUSTOMER_ID=customer1 # API服务配置 API_HOST=0.0.0.0 -API_PORT=8000 +API_PORT=6002 ``` ### 修改配置 @@ -143,7 +143,7 @@ API_PORT=8000 ### 搜索接口 ```bash -curl -X POST http://localhost:8000/search/ \ +curl -X POST http://localhost:6002/search/ \ -H "Content-Type: application/json" \ -d '{ "query": "芭比娃娃", @@ -156,7 +156,7 @@ curl -X POST http://localhost:8000/search/ \ ### 图片搜索 ```bash -curl -X POST http://localhost:8000/search/image \ +curl -X POST http://localhost:6002/search/image \ -H "Content-Type: application/json" \ -d '{ "image_url": "https://oss.essa.cn/example.jpg", @@ -167,19 +167,19 @@ curl -X POST http://localhost:8000/search/image \ ### 健康检查 ```bash -curl http://localhost:8000/admin/health +curl http://localhost:6002/admin/health ``` ### 查看配置 ```bash -curl http://localhost:8000/admin/config +curl http://localhost:6002/admin/config ``` ### 索引统计 ```bash -curl http://localhost:8000/admin/stats +curl http://localhost:6002/admin/stats ``` --- @@ -231,7 +231,7 @@ cat .env | grep ES_ **问题**: CORS错误 **解决**: -- 确保后端在 http://localhost:8000 运行 +- 确保后端在 http://localhost:6002 运行 - 检查浏览器控制台错误信息 --- @@ -339,5 +339,5 @@ SearchEngine/ 遇到问题请查看: - **日志**: `logs/backend.log` -- **API文档**: http://localhost:8000/docs +- **API文档**: http://localhost:6002/docs - **配置**: `config/schema/customer1_config.yaml` diff --git a/api/app.py b/api/app.py index fbc5535..62ba7da 100644 --- a/api/app.py +++ b/api/app.py @@ -2,7 +2,7 @@ Main FastAPI application for the search service. Usage: - uvicorn api.app:app --host 0.0.0.0 --port 8000 --reload + uvicorn api.app:app --host 0.0.0.0 --port 6002 --reload """ import os @@ -161,7 +161,7 @@ if __name__ == "__main__": parser = argparse.ArgumentParser(description='Start search API service') parser.add_argument('--host', default='0.0.0.0', help='Host to bind to') - parser.add_argument('--port', type=int, default=8000, help='Port to bind to') + parser.add_argument('--port', type=int, default=6002, help='Port to bind to') parser.add_argument('--customer', default='customer1', help='Customer ID') parser.add_argument('--es-host', default='http://localhost:9200', help='Elasticsearch host') parser.add_argument('--reload', action='store_true', help='Enable auto-reload') diff --git a/config/env_config.py b/config/env_config.py index 71ec98c..316a3e9 100644 --- a/config/env_config.py +++ b/config/env_config.py @@ -36,7 +36,7 @@ CUSTOMER_ID = os.getenv('CUSTOMER_ID', 'customer1') # API Service Configuration API_HOST = os.getenv('API_HOST', '0.0.0.0') -API_PORT = int(os.getenv('API_PORT', 8000)) +API_PORT = int(os.getenv('API_PORT', 6002)) # Model Directories TEXT_MODEL_DIR = os.getenv('TEXT_MODEL_DIR', '/data/tw/models/bge-m3') diff --git a/frontend/index.html b/frontend/index.html index 9bc8ca8..f190956 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -51,7 +51,7 @@
-

SearchEngine © 2025 | API服务地址: http://localhost:8000

+

SearchEngine © 2025 | API服务地址: http://localhost:6002

diff --git a/frontend/static/js/app.js b/frontend/static/js/app.js index 3af062d..4eedf9e 100644 --- a/frontend/static/js/app.js +++ b/frontend/static/js/app.js @@ -1,7 +1,7 @@ // SearchEngine Frontend JavaScript // API endpoint -const API_BASE_URL = 'http://localhost:8000'; +const API_BASE_URL = 'http://localhost:6002'; // Update API URL display document.getElementById('apiUrl').textContent = API_BASE_URL; @@ -68,7 +68,7 @@ async function performSearch() {
搜索出错: ${error.message}

- 请确保后端服务正在运行 (http://localhost:8000) + 请确保后端服务正在运行 (http://localhost:6002)
`; } finally { diff --git a/main.py b/main.py index ce9ff6f..56bf88f 100755 --- a/main.py +++ b/main.py @@ -151,7 +151,7 @@ def main(): serve_parser = subparsers.add_parser('serve', help='Start API service') serve_parser.add_argument('--customer', default='customer1', help='Customer ID') serve_parser.add_argument('--host', default='0.0.0.0', help='Host to bind to') - serve_parser.add_argument('--port', type=int, default=8000, help='Port to bind to') + serve_parser.add_argument('--port', type=int, default=6002, help='Port to bind to') serve_parser.add_argument('--es-host', default='http://localhost:9200', help='Elasticsearch host') serve_parser.add_argument('--reload', action='store_true', help='Enable auto-reload') diff --git a/scripts/frontend_server.py b/scripts/frontend_server.py index fc8bafa..8d74481 100755 --- a/scripts/frontend_server.py +++ b/scripts/frontend_server.py @@ -12,7 +12,7 @@ import sys frontend_dir = os.path.join(os.path.dirname(__file__), '../frontend') os.chdir(frontend_dir) -PORT = 8080 +PORT = 6003 class MyHTTPRequestHandler(http.server.SimpleHTTPRequestHandler): """Custom request handler with CORS support.""" diff --git a/scripts/start_frontend.sh b/scripts/start_frontend.sh index c596b86..e8fce2e 100755 --- a/scripts/start_frontend.sh +++ b/scripts/start_frontend.sh @@ -16,13 +16,13 @@ echo -e "${GREEN}========================================${NC}" echo -e "${GREEN}Starting Frontend Server${NC}" echo -e "${GREEN}========================================${NC}" -PORT=8080 +PORT=6003 echo -e "\n${YELLOW}Frontend will be available at:${NC}" echo -e " ${GREEN}http://localhost:$PORT${NC}" echo "" echo -e "${YELLOW}Make sure the backend API is running at:${NC}" -echo -e " ${GREEN}http://localhost:8000${NC}" +echo -e " ${GREEN}http://localhost:6002${NC}" echo "" python scripts/frontend_server.py diff --git a/setup.sh b/setup.sh index d310273..fa035e1 100755 --- a/setup.sh +++ b/setup.sh @@ -1,5 +1,7 @@ #!/bin/bash +source /home/tw/miniconda3/etc/profile.d/conda.sh + # SearchEngine Setup and Startup Script # This script sets up the environment and starts all services diff --git a/start_all.sh b/start_all.sh index d6a7166..572469c 100755 --- a/start_all.sh +++ b/start_all.sh @@ -3,6 +3,8 @@ # One-click startup script for SearchEngine # This script starts everything you need +source /home/tw/miniconda3/etc/profile.d/conda.sh + set -e cd "$(dirname "$0")" @@ -67,7 +69,7 @@ echo -e "${YELLOW}等待后端服务启动...${NC}" sleep 5 # Check if backend is running -if curl -s http://localhost:8000/admin/health > /dev/null 2>&1; then +if curl -s http://localhost:6002/admin/health > /dev/null 2>&1; then echo -e "${GREEN}✓ 后端服务运行正常${NC}" else echo -e "${RED}✗ 后端服务启动失败,请检查日志: logs/backend.log${NC}" @@ -81,9 +83,9 @@ echo -e "${GREEN}所有服务启动完成!${NC}" echo -e "${GREEN}========================================${NC}" echo "" echo -e "访问地址:" -echo -e " ${GREEN}前端界面: http://localhost:8080${NC}" -echo -e " ${GREEN}后端API: http://localhost:8000${NC}" -echo -e " ${GREEN}API文档: http://localhost:8000/docs${NC}" +echo -e " ${GREEN}前端界面: http://localhost:6003${NC}" +echo -e " ${GREEN}后端API: http://localhost:6002${NC}" +echo -e " ${GREEN}API文档: http://localhost:6002/docs${NC}" echo "" echo -e "日志文件:" echo -e " 后端: logs/backend.log" -- libgit2 0.21.2