# SearchEngine **Repository Path**: hatomugi/search-engine ## Basic Information - **Project Name**: SearchEngine - **Description**: 搜索引擎+QT客户端 - **Primary Language**: C++ - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2024-07-19 - **Last Updated**: 2025-12-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SearchEngine(必读) #### 介绍 1. 搜索引擎+QT 客户端 2. json 通信,客户端请求数据量小,直接发送 json,服务端回复数据量大,先发送数据长度,再发送数据 3. log4cpp 日志,记录连接 IP 来源,请求 IP,请求类型 #### 注意 1. 使用本仓库 QT 客户端需要关注的是,sendInLoop 底层调用的 writen 函数增加了一个 write()长度的过程,长度是 size_t 类型 ``` int SocketIO::writen(const char *buf, size_t len) { send(_fd, &len, sizeof(size_t), MSG_NOSIGNAL); size_t total_sent = 0; while (total_sent < len) { int once_sent = send(_fd, buf + total_sent, len - total_sent, MSG_NOSIGNAL); if (once_sent == -1 && errno == EINTR) { continue; } else if (once_sent == -1) { return -1; } else if (once_sent == 0) { break; } total_sent += once_sent; } return total_sent; } ``` #### 第三方库安装 ``` sudo apt install libmysqlcppconn-dev sudo apt install libboost-regex-dev sudo apt install nlohmann-json3-dev ``` #### json通信格式 ``` #wordQuery request { "query_id": 2, #客户端请求ID 1是recommend, 2是wordQuery "msg": "人性化CNNIC", "pageNum": 10, #要跳转的页码,点击search时页码为1,通过jump跳页 "itemsPerPage": 5 #每页结果的最大数,请求以页为单位 } #wordQuery response { "msgID" : 2, "maxPage": 3, #客户端查询页码上限 "queryWords" : [ "人性化", "CNNIC" ], #vector 客户端背景色标注 "files": [ { "title": "404, not found", "summary": "未找到你搜索的内容", "url": "" } ] } #keywordRecommand request { "query_id": 1, "msg": "keyWord" } #keywordRecommand response { "msgID" : 1, "msg": [ "keyWord1", "keyWord2", "keyWord3" ] #vector 关键词推荐数组 } ``` #### 使用说明 1. 克隆仓库(git 不太会用啊,之前的提交都给我整毁了。。。) 2. 修改配置文件 3. CMake 4. ./bin/xxx 运行 5. ctrl+c 通过信号优雅停止 #### QTclient 展示 ![输入图片说明](QTcpClient/QTconnect.png) ![输入图片说明](QTcpClient/QTrecommend.png) ![输入图片说明](QTcpClient/QTresult.png)