服务器的搭建,就使用C++中的httplib就可以了
对于httplib搭建得服务器中,这个项目主要使用的是从后端获取数据,也就是get方法
- 得到数据,那么在前端显示的区域,将原本的标签清理一下,然后增加新的标签
- 没有得到数据(搜索的内容不存在),那就是使用
404 Not found的错误了
而在前端页面中,所使用的技术主要就是vue 和jQuery中的ajax.
const string g_input_path = "../data/tmp/raw_input.txt";
const string g_root_path = "./www";
searcher::Searcher search;
void GetWebData(const httplib::Request& req,httplib::Response& resp){
if(!req.has_param("query")){
resp.set_content("请求参数错误","text/plain;charset=utf-8");
return ;
string query = req.get_param_value("query");
string results;
search.Search(query,&results);
resp.set_content(results,"application/json;charset=utf-8");
cout<<results<<endl;
int main(){
using namespace httplib;
bool ret = search.Init(g_input_path);
if(ret == false){
cout<<"searcher init error"<<endl;
return 1;
Server server;
server.set_base_dir(g_root_path.c_str());
server.Get("/searcher",GetWebData);
server.listen("0.0.0.0",19998);
return 0;
初始界面:

找不到搜索内容时

找到指定内容时

还可以点击下一页和上一页

So Easy搜索引擎项目描述开发环境主要技术项目特点项目难点和提升结束语
项目描述
boost官网虽然提供了在线文档,但是没有一个方便的搜索入口,因此我设计开发了这样一款基于boost文档的站内搜索引擎,通过浏览器加快我们精准定位获取到我们所需要查找的内容。
项目特点
项目难点和提升