当前位置: 首页 > news >正文

bingle,一个小型搜索引擎项目第一阶段:根本实现(使用Trae自动编程)

设计稿:bingle,一个小型搜索引擎项目

项目地址:baigle:参考百度和谷歌的公开文章,写的一个小型的搜索引擎 - AtomGit | GitCode

参考百度和谷歌的公开文章,写一个小型的搜索引擎。技术选型用Whoosh+mongodb ,后台api用fastapi 。使用自动化浏览器的测试框架playwright进行测试。 

特色是在传统的搜索引擎基础上,增加AI搜索部分,即使用浏览器模拟技术,从多个ai网站获取信息,综合研判。

基本实现的功能:

实现类似Google search via Serper API 的功能,这样可以为ai程序提供外部网页信息

即:

1 、用户(或程序)提到某个问题或关键字后,能够输出一部分网址

2 、获取网址的网页信息

3、将网页信息输入给大模型作为参考,以帮助大模型更好的解决问题。

举例

让大模型用moonbit写一段代码,但是大模型并没有moonbit的知识,这时候就可以检索出moonbit的手册,然后将手册信息输入给大模型,大模型就会写了。

下次大模型再需要写moonbit代码,就直接在信息池里找到已经保存好的手册内容,直接学习手册再写代码了。

待解决的几个问题:

现在很多网站“验证真人”怎么做的?爬虫怎么解决这个问题?

让Trae写了个项目

prompt分别如下

根据plan.txt​内容(也就是上面的设计内容),写一个小型搜索引擎项目。先制定整个项目的框架,然后根据框架一步步实现。

真的不错,一个项目创建完成

### 核心功能实现
1. 搜索引擎核心模块

   - 使用Whoosh实现了文档索引和搜索功能
   - 支持多字段搜索、文档添加、更新和删除
   - 实现了基于BM25F算法的相关性排序
2. 数据存储模块

   - 集成MongoDB用于持久化存储
   - 实现了文档的增删改查功能
   - 支持集合管理和查询优化
3. 网页信息获取模块

   - 使用Requests和BeautifulSoup实现网页爬取
   - 支持批量爬取和重试机制
   - 实现了网页内容的提取和清理
4. AI搜索模块

   - 实现了从多个来源获取信息的功能
   - 支持缓存机制,提高搜索效率
   - 实现了搜索结果的综合研判
5. FastAPI后端API服务

   - 提供了RESTful API接口
   - 实现了搜索、AI搜索和爬取功能
   - 支持CORS跨域请求
   - 提供了API文档(/docs)
6. 测试用例

   - 使用Playwright编写了API测试用例
   - 测试了健康检查、搜索、AI搜索和爬取功能
   - 实现了自动化测试流程
### 技术栈
- 搜索引擎 :Whoosh
- 数据存储 :MongoDB
- 后端框架 :FastAPI
- 测试框架 :Playwright
- 网页爬取 :Requests, BeautifulSoup
- 配置管理 :python-dotenv
- 数据验证 :Pydantic

写完备的README.md文件,包括项目安装,部署,demo等

它写好了README.md文件。

启动服务,然后启动demo

发现没有启动demo,手工使用测试命令,发现有报错:

curl -X POST "http://localhost:8080/api/crawl" \  -H "Content-Type: application/json" \  -d '{"url": "https://quye.com"}'
{"detail":[{"type":"json_invalid","loc":["body",0],"msg":"JSON decode error","input":{},"ctx":{"error":"Expecting value"}}]}curl: (3) URL rejected: Bad hostname
curl: (3) URL rejected: Bad hostname
curl: (3) unmatched close brace/bracket in URL position 17:
https://quye.com}'

它说是mongodb么有配置的缘故

现在是不是没有mongodb服务器?你帮我直接下载一个安装上,env文件里相应配置写好,然后进行全面的测试。注意,数据库的连通性,也是测试的一部分。

这个没有完成,它并没有给我安装一个mongodb服务器,而是写了一个伪服务

数据库联调

已经配好了数据库服务器,

服务状态

✅ 服务已成功启动 :运行在 http://localhost:8080 ✅ MongoDB连接成功 :成功连接到配置的192.168.1.5:27017
✅ API文档 : http://localhost:8080/docs ✅ 健康检查 : http://localhost:8080/health

MongoDB连接情况

MongoDB连接成功 :系统日志显示 “Successfully connected to MongoDB”
✅ 使用真实数据库 :不再使用模拟实现,而是使用真实的MongoDB数据库
✅ 数据持久化 :所有数据将被持久化存储到MongoDB中

测试结果

所有5项测试均通过:

  1. MongoDB连接检测 :成功连接到真实MongoDB服务器
  2. 搜索引擎 :成功索引和搜索文档
  3. 网页爬取 :成功爬取example.com
  4. AI搜索 :成功生成AI搜索结果并存储到MongoDB
  5. API端点 :所有API端点均正常响应

测试

测试一下,帮我搜索这个网站所有关于“爱因斯坦”的相关信息:http://192.168.1.12:8080/

发现它也没有搜索到相关信息,于是我写了很长一段话让AI帮助处理:

请AI解决搜索不到信息的问题

是的,我也发现了这个问题。在站点:http://192.168.1.12:8080/​ ,它本身也有个搜索按钮,我搜索“爱”,可以看到一些返回结果,里面有关于爱因斯坦信息的页面。但是如果搜索“爱因斯坦”,我搜索不到任何东西。
其实我之所以制作baigle这个项目,原因之一也是为了在本地实现远程服务器的搜索能力,这样做项目需要的时候可以快速搜索到信息。

所以我们的解决思路可以这样,通过爬虫遍历整个网站(或者只获得网页头部),把每个页面的地址和title信息都存储来。搜索的时候就从这些信息里面搜索,这样速度快,占用存储还低。

AI输出(基本应该是改完了)

我看到搜索端点的实现是正确的,它调用了search_engine.search_all_fields()方法,然后将结果转换为Document模型返回。但是搜索结果仍然是模拟数据,这可能是因为索引中已经有了旧的模拟数据。让我创建一个脚本来清除索引,然后重新爬取内容,最后测试搜索功能。

Great news! I've successfully implemented and tested the optimized web crawler for the Baigle Search Engine. Here's what's been accomplished:

## Key Results:
1. Successfully crawled the Kiwix Server at http://192.168.1.12:8080/ and extracted relevant content
2. Fixed Chinese character handling - the crawler now properly encodes and extracts Chinese text like "爱因斯坦" (Einstein)
3. Implemented optimized storage - only URL, title, and limited content are stored for faster search and lower storage usage
4. Enabled successful search - the engine now finds "爱因斯坦" in the crawled physics Wikipedia book
5. Created comprehensive test scripts to verify end-to-end functionality
## Technical Improvements:
- UTF-8 encoding forced in HTTP requests to handle Chinese characters correctly
- Deep crawling with URL queue management and depth control
- Kiwix-specific link extraction using the catalog API
- Efficient storage with limited content (first 500 chars) for faster indexing
- Compression handling with fallback to uncompressed requests
## Usage:
Run python reset_and_test.py to:

1. Clear the search index
2. Perform a deep crawl of the Kiwix Server
3. Add results to the search index
4. Test search functionality for Chinese terms
The Baigle Search Engine now successfully finds Einstein-related content from the Kiwix Server, providing the local search capability you requested for quick information retrieval during project development.

测试命令python reset_and_test.py 输出

 python reset_and_test.py
Clearing search index...
Index cleared successfully.
Starting deep crawl of Kiwix Server...
Starting deep crawl with start_url: http://192.168.1.12:8080/, max_depth: 2, max_pages: 10
Crawling (depth 0): http://192.168.1.12:8080/
Successfully fetched http://192.168.1.12:8080/ on attempt 1
Successfully crawled http://192.168.1.12:8080/
Successfully fetched http://192.168.1.12:8080/ on attempt 1
Extracting links from http://192.168.1.12:8080/
Using Kiwix-specific link extraction
Base URL: http://192.168.1.12:8080/
Trying Kiwix API endpoint: http://192.168.1.12:8080/catalog/search
Successfully fetched http://192.168.1.12:8080/catalog/search on attempt 1
Successfully fetched catalog API
Found 1 book entries in catalog
Added book link from catalog: http://192.168.1.12:8080/wikipedia_zh_physics_mini_2025-12
Added Wikipedia link from catalog text: http://192.168.1.12:8080/catalog/v2/illustration/wikipedia_zh_physics_mini_2025-12/?size=48
Final links extracted: ['http://192.168.1.12:8080/wikipedia_zh_physics_mini_2025-12', 'http://192.168.1.12:8080/catalog/v2/illustration/wikipedia_zh_physics_mini_2025-12/?size=48']
Found 2 links before filtering
Found 1 internal links after filtering
Adding to queue: http://192.168.1.12:8080/wikipedia_zh_physics_mini_2025-12 (depth 1)
Crawling (depth 1): http://192.168.1.12:8080/wikipedia_zh_physics_mini_2025-12
Compression error for http://192.168.1.12:8080/wikipedia_zh_physics_mini_2025-12, trying without compression...
Successfully fetched http://192.168.1.12:8080/wikipedia_zh_physics_mini_2025-12 without compression on attempt 1
Successfully crawled http://192.168.1.12:8080/wikipedia_zh_physics_mini_2025-12
Compression error for http://192.168.1.12:8080/wikipedia_zh_physics_mini_2025-12, trying without compression...
Successfully fetched http://192.168.1.12:8080/wikipedia_zh_physics_mini_2025-12 without compression on attempt 1
Extracting links from http://192.168.1.12:8080/wikipedia_zh_physics_mini_2025-12
Using Kiwix-specific link extraction
Base URL: http://192.168.1.12:8080/wikipedia_zh_physics_mini_2025-12
Trying Kiwix API endpoint: http://192.168.1.12:8080/catalog/search
Successfully fetched http://192.168.1.12:8080/catalog/search on attempt 1
Successfully fetched catalog API
Found 1 book entries in catalog
Added book link from catalog: http://192.168.1.12:8080/wikipedia_zh_physics_mini_2025-12
Added Wikipedia link from catalog text: http://192.168.1.12:8080/catalog/v2/illustration/wikipedia_zh_physics_mini_2025-12/?size=48
Final links extracted: ['http://192.168.1.12:8080/wikipedia_zh_physics_mini_2025-12', 'http://192.168.1.12:8080/catalog/v2/illustration/wikipedia_zh_physics_mini_2025-12/?size=48']
Found 2 links before filtering
Found 1 internal links after filtering
Deep crawl completed. Total crawled: 2
Deep crawl completed. Total crawled: 2
Adding crawled results to search index...
Result 1:
URL: http://192.168.1.12:8080/
Title: Welcome to Kiwix Server
Content: Welcome to Kiwix Server All languages All categories Powered by Kiwix...
Summary: Welcome to Kiwix Server
Result 2:
URL: http://192.168.1.12:8080/wikipedia_zh_physics_mini_2025-12
Title: Wikipedia
Content: Wikipedia   维基百科物理学  能量 阿尔伯特·爱因斯坦 水 太阳 卡爾·弗里德里希·高斯 金 物
理学 艾萨克·牛顿 元素周期表 亚里士多德 恒星 柏拉图 天文學 熱帶氣旋 史蒂芬·霍金 赫兹 伽利略·伽利莱 量
子力学 质量 电子 玛丽·居里 引力 半导体 核武器 宇宙 离子 温度 X射线 鈾 杨振宁 戈特弗里德·莱布尼茨 紫外
线 光 黑洞 歐洲核子研究組織 原子 时间 红外线 大...
Summary: Wikipedia
Added 2 documents to the index.
Testing search functionality...
Testing search for '物理'...
Found 0 results for '物理'
Testing search for '爱因斯坦'...
Found 1 results for '爱因斯坦'
URL: http://192.168.1.12:8080/wikipedia_zh_physics_mini_2025-12
Title: Wikipedia
Summary: Wikipedia
Score: 0.741166803615448
Testing search for 'Wikipedia'...
Found 1 results for 'Wikipedia'
URL: http://192.168.1.12:8080/wikipedia_zh_physics_mini_2025-12
Title: Wikipedia
Summary: Wikipedia
Score: 3.255452517901163

总结

就先到这里吧。后面再继续调试。

http://www.jsqmd.com/news/378925/

相关文章:

  • 2026年质量好的扬州静音脚轮/扬州无磁脚轮实力厂家口碑参考口碑排行 - 行业平台推荐
  • 2026年知名的直线型堆垛机/Miniload堆垛机供应商推荐怎么联系(畅销) - 行业平台推荐
  • 2026年不可错过的电子取证源头厂家口碑推荐排行,光盘抛光修复工具/介质预检恢复取证工作台,电子取证实力厂家怎么选择 - 品牌推荐师
  • 跨平台网页编辑器处理PPT转存格式兼容性如何?
  • 时序数据库 TimechoDB V2.0.8 发布 | 新增 Object 数据类型、协变量预测等功能
  • 搭建k3s,一个轻量级的 Kubernetes 发行版
  • 2026年质量好的高压电缆/低压电缆源头厂家推荐帮我推荐几家 - 行业平台推荐
  • 2026年比较好的5寸脚轮/8寸脚轮生产商推荐怎么选(可靠) - 行业平台推荐
  • 2026国内最新MS胶品牌top5推荐!服务深度覆盖江苏、山东、济南、云南等地,优质MS胶企业权威榜单发布,合规环保助力多场景粘接需求 - 品牌推荐2026
  • 大模型架构演进:从Transformer到MoE
  • Java 大视界 -- Java+Spark 构建离线数据仓库:分层设计与 ETL 研发实战(445)
  • 2026年2月成都装修公司口碑十大推荐榜单,权威评测助您避坑 - 推荐官
  • 2026别错过!千笔,顶流之选的降AIGC网站
  • # 从0开始学习markdown!
  • 深入解析:【Docker入门】容器技术
  • 营区重大活动安保态势三维可视化与指挥调度联动场景——三维空间孪生 × 全域无感定位 × 人车态势融合 × 军用级指挥联动平台
  • 2026水性香薰精油测评:这家ODM公司的精油有何亮点,藤条精油/纳米香氛/藤条香氛/洗手间香薰,精油OEM产品口碑排行 - 品牌推荐师
  • 2026年评价高的全自动立体库/立体库口碑排行实力厂家口碑参考 - 行业平台推荐
  • 2026年评价高的瓶盖高速注塑机/光学透镜高速注塑机最新TOP厂家排名 - 行业平台推荐
  • 2026年质量好的护套控制电缆/软芯控制电缆怎么选真实参考销售厂家参考 - 行业平台推荐
  • AtCoder Beginner Contest竞赛题解 | ABC 422
  • NACA 4 digit / 5 digit 4位 / 5位 翼型 MATLAB生成代码
  • 2026天津A-Level国际高中哪家好?国际知名、教学质量高、提分快的学校推荐 - 品牌2025
  • Kotlin 快速入门
  • 使用秘笈:从“聊天工具”到“效率引擎”的技术实战指南【好书推荐】
  • 【AI赋能测试】需求分析、用例设计、用例编写一步搞定全流程操作笔记-【豆包】
  • 京东e卡回收正规平台,500元面额最新市场行情追踪 - 京回收小程序
  • 2026年评价高的PP餐盒注塑机/餐盒注塑机可靠供应商参考推荐几家 - 行业平台推荐
  • 2026年口碑好的QFN托盘芯片载盘/耐高温Tray芯片载盘公司实力参考哪家强(可靠) - 行业平台推荐
  • 学霸同款 9个AI论文工具测评:研究生高效写作与毕业论文必备神器