??歡迎來到C++項(xiàng)目專欄
?????♀?作者介紹:前PLA隊(duì)員 目前是一名普通本科大三的軟件工程專業(yè)學(xué)生
??IP坐標(biāo):湖北武漢
?? 目前技術(shù)棧:C/C++、Linux系統(tǒng)編程、計(jì)算機(jī)網(wǎng)絡(luò)、數(shù)據(jù)結(jié)構(gòu)、Mysql、Python
?? 博客介紹:通過分享學(xué)習(xí)過程,加深知識點(diǎn)的掌握,也希望通過平臺能認(rèn)識更多同僚,如果覺得文章有幫助,請您動動發(fā)財(cái)手點(diǎn)點(diǎn)贊,本人水平有限,有不足之處歡迎大家扶正~
?? 最后送大家一句話共勉:知不足而奮進(jìn),望遠(yuǎn)山而前行。
————————————————
1.項(xiàng)目介紹
對比常用搜索引擎,實(shí)現(xiàn)一個(gè)簡易版的站內(nèi)搜索引擎。
基于boost庫實(shí)現(xiàn),boost庫官網(wǎng)上是沒有站內(nèi)搜索引擎的,我們自己實(shí)現(xiàn)一個(gè),部署在自己的云服務(wù),客戶端可以通過瀏覽器訪問服務(wù)器地址,實(shí)現(xiàn)搜索引擎功能的使用。
2.搜索引擎宏觀介紹
常用搜索引擎,如百度 搜狗等,搜索引擎框架可簡易理解如上圖,我們實(shí)現(xiàn)的站內(nèi)搜索引擎對比就是把相關(guān)資料提前下載到云服務(wù)器本地,當(dāng)用戶使用搜索功能時(shí),在服務(wù)器本地進(jìn)行檢索反饋。文章來源:http://www.zghlxwxcb.cn/news/detail-842783.html
3.相關(guān)技術(shù)棧和項(xiàng)目環(huán)境
- 技術(shù)棧: C/C++ C++11, STL, 準(zhǔn)標(biāo)準(zhǔn)庫Boost,Jsoncpp,cppjieba,cpp-httplib , 選學(xué): html5,css,js、Query、Ajax
- 項(xiàng)目環(huán)境: Centos 7云服務(wù)器,vim/gcc(g++)/Makefile , vs2019 or vs code
4.正排索引VS倒排索引-搜索引擎具體原理
5.編寫數(shù)據(jù)去標(biāo)簽與數(shù)據(jù)清洗的模塊
先去boost官網(wǎng)將文件下載下來,使用rz命令將文件拖拽到Linux服務(wù)器
解壓命令:
創(chuàng)建好數(shù)據(jù)文件夾用來區(qū)分處理好的數(shù)據(jù),方便后期讀取使用文章來源地址http://www.zghlxwxcb.cn/news/detail-842783.html
- 編寫parser.cc模塊
//代碼的基本結(jié)構(gòu):
#include <iostream>
#include <string>
#include <vector>
//是一個(gè)目錄,下面放的是所有的html網(wǎng)頁
const std::string src_path = "data/input/";
const std::string output = "data/raw_html/raw.txt";
typedef struct DocInfo{
std::string title; //文檔的標(biāo)題
std::string content; //文檔內(nèi)容
std::string url; //該文檔在官網(wǎng)中的url
}DocInfo_t;
//const &: 輸入
//*: 輸出
//&:輸入輸出
bool EnumFile(const std::string &src_path, std::vector<std::string> *files_list);
bool ParseHtml(const std::vector<std::string> &files_list, std::vector<DocInfo_t>
*results);
bool SaveHtml(const std::vector<DocInfo_t> &results, const std::string &output);
int main()
{
std::vector<std::string> files_list;
//第一步: 遞歸式的把每個(gè)html文件名帶路徑,保存到files_list中,方便后期進(jìn)行一個(gè)一個(gè)的文件進(jìn)行讀取
if(!EnumFile(src_path, &files_list)){
std::cerr << "enum file name error!" << std::endl;
return 1;
}
//第二步: 按照files_list讀取每個(gè)文件的內(nèi)容,并進(jìn)行解析
std::vector<DocInfo_t> results;
if(!ParseHtml(files_list, &results)){
std::cerr << "parse html error" << std::endl;
return 2;
}
//第三步: 把解析完畢的各個(gè)文件內(nèi)容,寫入到output,按照\3作為每個(gè)文檔的分割符
if(!SaveHtml(results, output)){
std::cerr << "sava html error" << std::endl;
return 3;
}
return 0;
}
bool EnumFile(const std::string &src_path, std::vector<std::string> *files_list)
{
return true;
}
bool ParseHtml(const std::vector<std::string> &files_list, std::vector<DocInfo_t> *results)
{
return true;
}
bool SaveHtml(const std::vector<DocInfo_t> &results, const std::string &output)
{
return true;
}
- 安裝boost開發(fā)庫
$ sudo yum install -y boost-devel //是boost 開發(fā)庫
到了這里,關(guān)于【Boost搜索引擎項(xiàng)目】Day1 項(xiàng)目介紹+去標(biāo)簽和數(shù)據(jù)清洗框架搭建的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!