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

长沙网站策划专业seo网站优化推广排名教程

长沙网站策划,专业seo网站优化推广排名教程,四川住房和城乡建设厅网站三类人员,昆明网页建站平台输入不能存在空格 目前输入的关键词时每隔一空格内容分别进行搜索&#xff0c;大部分时候我们都是将一串包含空格的内容直接进行搜索&#xff0c;需要将代码改进。 将cin换为fgets #include "searcher.hpp" #include <iostream> #include <cstdio> #in…
输入不能存在空格

目前输入的关键词时每隔一空格内容分别进行搜索,大部分时候我们都是将一串包含空格的内容直接进行搜索,需要将代码改进。
将cin换为fgets

#include "searcher.hpp"
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>const std::string input = "data/raw_html/raw.txt";int main()
{//for testns_searcher::Searcher *search = new ns_searcher::Searcher();search->InitSearcher(input);std::string query;std::string json_string;char buffer[1024];while(true){std::cout << "Please Enter You Search Query# ";fgets(buffer, sizeof(buffer)-1, stdin);buffer[strlen(buffer) - 1] = 0;query = buffer;search->Search(query, &json_string);std::cout << json_string << std::endl;}return 0;
}
desc存在None

搜索出来的结果,有部分desc的内容时None
![[Pasted image 20250217163454.png]]

std::string GetDesc(const std::string &html_content, const std::string &word)
{//找到word在html_content中的首次出现,然后往前找50个字节(如果没有,就从begin开始),往后找100个字节(如果没有,就截取到end)//截取出这部分内容const std::size_t prev_step = 50;const std::size_t next_step = 100;//1.找到首次出现std::size_t pos = html_content.find(word);if(pos == std::string::npos){return "None1"; //不可能发生}//2.获取start,endstd::size_t start = 0;std::size_t end = html_content.size() - 1;//如果之前有50+字符,就更新开始位置if(pos - prev_step > start) start = pos - prev_step;if(pos + next_step < end) end = pos + next_step;//3.截取子串,returnif(start >= end) return "None2";return html_content.substr(start, end - start);
}

给None的两种情况加上脚标
![[Pasted image 20250217164507.png]]

![[Pasted image 20250217164815.png]]

None1和2都有

因为pos是无符号整数,减去step过了0,成为负数,其实是变为一个特别大的值,此时就超过了start,远大于start,条件成立,更新start,start变为一个特别大的值;这时start有可能大于end,于是返回None2

if(pos > start + prev_step) start = pos - prev_step;

将-变为+,转换为两个正数的比较

std::string GetDesc(const std::string &html_content, const std::string &word)
{//找到word在html_content中的首次出现,然后往前找50个字节(如果没有,就从begin开始),往后找100个字节(如果没有,就截取到end)//截取出这部分内容const std::size_t prev_step = 50;const std::size_t next_step = 100;//1.找到首次出现std::size_t pos = html_content.find(word);if(pos == std::string::npos){return "None1"; //不可能发生}//2.获取start,end,std::size_t 无符号整数std::size_t start = 0;std::size_t end = html_content.size() - 1;//如果之前有50+字符,就更新开始位置if(pos > start + prev_step) start = pos - prev_step;if((int)pos < (int)(end - next_step)) end = pos + next_step;//3.截取子串,returnif(start >= end) return "None2";return html_content.substr(start, end - start);
}

None2修改完成
![[Pasted image 20250217172226.png]]

在word里面保存的对应的搜索关键字,都变为小写。
索引关键字,搜索关键字都是小写
但是在获取摘要的时候,用的是原始的网页内容,提炼摘要的word是已经转为小写的词
实际在获取摘要,find的时候,就匹配不到了,因为fine不是忽略大小写的
而且string在实际搜索的时候,也没有忽略大小写的匹配方式
并且不能直接将原始网页全部变为小写

可以使用c++的search

std::string GetDesc(const std::string &html_content, const std::string &word)
{//找到word在html_content中的首次出现,然后往前找50个字节(如果没有,就从begin开始),往后找100个字节(如果没有,就截取到end)//截取出这部分内容const int prev_step = 50;const int next_step = 100;//1.找到首次出现auto iter = std::search(html_content.begin(), html_content.end(), word.begin(), word.end(), [](int x, int y){return (std::tolower(x) == std::tolower(y));});if(iter == html_content.end()){return "None1";}int pos = std::distance(html_content.begin(), iter);//2.获取start,end,std::size_t 无符号整数int start = 0;int end = html_content.size() - 1;//如果之前有50+字符,就更新开始位置if(pos > start + prev_step) start = pos - prev_step;if(pos < end - next_step) end = pos + next_step;//3.截取子串,returnif(start >= end) return "None2";return html_content.substr(start, end - start);
}

None1修改完成
![[Pasted image 20250217174912.png]]

![[Pasted image 20250217175132.png]]

输出权值和doc_id

searcher.hpp

Json::Value root;
for(auto &item : inverted_list_all){ns_index::DocInfo * doc = index->GetForwardIndex(item.doc_id);if(nullptr == doc){continue;}Json::Value elem;elem["title"] = doc->title;elem["desc"] = GetDesc(doc->content, item.word); //content是文档的去标签的结果,但是不是我们想要的,我们要的是一部分elem["url"]  = doc->url;//for debugelem["id"] = (int)item.doc_id;     //int->stringelem["weight"] = item.weight; root.append(elem);
}

![[Pasted image 20250217180513.png]]

是按照权值大小降序排列的
打开这个网页查看
![[Pasted image 20250217180712.png]]

![[Pasted image 20250217180738.png]]

函数重名

util.hpp

    class StringUtil{public:static void Split(const std::string &target, std::vector<std::string> *out, const std::string &sep){//boost splitboost::split(*out, target, boost::is_any_of(sep), boost::token_compress_on);}};

把StringUtil的函数名改为Split

index.hpp

DocInfo *BuildForwardIndex(const std::string &line)
{//1. 解析line,字符串切分//line -> 3 string, title, content, urlstd::vector<std::string> results;const std::string sep = "\3";   //行内分隔符ns_util::StringUtil::Split(line, &results, sep);//ns_util::StringUtil::CutString(line, &results, sep);if(results.size() != 3){return nullptr;}//2. 字符串进行填充到DocIinfoDocInfo doc;doc.title = results[0]; //titledoc.content = results[1]; //contentdoc.url = results[2];   ///urldoc.doc_id = forward_index.size(); //先进行保存id,在插入,对应的id就是当前doc在vector中的下标!//3. 插入到正排索引的vectorforward_index.push_back(std::move(doc)); //doc,html文件内容return &forward_index.back();
}

把index的BuildForwardIndex的调用改为Split

修改文件名

makefile

PARSER=parser
DUG=debug
cc=g++.PHONY:all
all:$(PARSER) $(DUG)$(PARSER):parser.cc$(cc) -o $@ $^ -lboost_system -lboost_filesystem -std=c++11
$(DUG):debug.cc$(cc) -o $@ $^ -ljsoncpp -std=c++11
.PHONY:clean
clean:rm -f $(PARSER) $(DUG)

将server.cc改名为debug.cc

mv server.cc debug.cc

![[Pasted image 20250217193240.png]]

权值和实际关键词出现次数不符合

![[Pasted image 20250217181450.png]]

![[Pasted image 20250217181500.png]]

会多计算也会少计算权值
可能分词工具在分词的时候会少分词
如果目标关键词在尖括号内,可能会当成标签处理,不会计入

把整个文件拿到内存
去标签之后,先拿到标题
对整个文件进行去标签,其中是包括标签的
实际,如果一个词在title中出现,一定会被当标题和当内容分别统计一次
index.hpp

bool BuildInvertedIndex(const DocInfo &doc)
{//DocInfo{title, content, url, doc_id}//word -> 倒排拉链struct word_cnt{int title_cnt;int content_cnt;word_cnt():title_cnt(0), content_cnt(0){}};std::unordered_map<std::string, word_cnt> word_map; //用来暂存词频的映射表//对标题进行分词std::vector<std::string> title_words;ns_util::JiebaUtil::CutString(doc.title, &title_words);if(doc.doc_id == 8713){for(auto &s : title_words){std::cout << "title: " << s << std::endl;}}//对标题进行词频统计for(std::string s : title_words){boost::to_lower(s); //需要统一转化成为小写word_map[s].title_cnt++; //如果存在就获取,如果不存在就新建}//对文档内容进行分词std::vector<std::string> content_words;ns_util::JiebaUtil::CutString(doc.content, &content_words);if(doc.doc_id == 8713){for(auto &s : content_words){std::cout << "content: " << s << std::endl;}}//对内容进行词频统计for(std::string s : content_words){boost::to_lower(s);word_map[s].content_cnt++;}#define X 10
#define Y 1//Hello,hello,HELLOfor(auto &word_pair : word_map){InvertedElem item;item.doc_id = doc.doc_id;item.word = word_pair.first;item.weight = X*word_pair.second.title_cnt + Y*word_pair.second.content_cnt; //相关性InvertedList &inverted_list = inverted_index[word_pair.first];inverted_list.push_back(std::move(item));}return true;
}

debug.cc

#include "searcher.hpp"
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>const std::string input = "data/raw_html/raw.txt";int main()
{//for testns_searcher::Searcher *search = new ns_searcher::Searcher();search->InitSearcher(input);//std::string query;//std::string json_string;//char buffer[1024];//while(true){//      std::cout << "Please Enter You Search Query# ";//      fgets(buffer, sizeof(buffer)-1, stdin);//      buffer[strlen(buffer) - 1] = 0;//      query = buffer;//      search->Search(query, &json_string);//      std::cout << json_string << std::endl;//}return 0;
}

![[Pasted image 20250217230323.png]]

生成了内容和分词,但是很难观察
创建一个log.txt

touch log.txt

![[Pasted image 20250217231458.png]]

将debug的内容重定向到log.txt当中

./debug > log.txt

![[Pasted image 20250217233215.png]]

共有7000行内容
查找split
![[Pasted image 20250217233508.png]]


文章转载自:
http://percentage.c7617.cn
http://gadid.c7617.cn
http://decrease.c7617.cn
http://ibuprofen.c7617.cn
http://overtrain.c7617.cn
http://isotropic.c7617.cn
http://draconian.c7617.cn
http://astringent.c7617.cn
http://cryogeny.c7617.cn
http://inconsolable.c7617.cn
http://manshift.c7617.cn
http://pupation.c7617.cn
http://mighty.c7617.cn
http://appetite.c7617.cn
http://fastrack.c7617.cn
http://gerent.c7617.cn
http://unwooed.c7617.cn
http://superficiary.c7617.cn
http://cunctative.c7617.cn
http://sophistication.c7617.cn
http://unicode.c7617.cn
http://sunflower.c7617.cn
http://ecophysiology.c7617.cn
http://drumbeating.c7617.cn
http://conveyorize.c7617.cn
http://fallalery.c7617.cn
http://hematocyte.c7617.cn
http://doozer.c7617.cn
http://timberline.c7617.cn
http://identification.c7617.cn
http://ponticello.c7617.cn
http://discoverable.c7617.cn
http://biophilosophy.c7617.cn
http://attaintment.c7617.cn
http://poriferous.c7617.cn
http://pick.c7617.cn
http://anglicanism.c7617.cn
http://salience.c7617.cn
http://crimmer.c7617.cn
http://radicle.c7617.cn
http://insectaria.c7617.cn
http://typo.c7617.cn
http://objurgation.c7617.cn
http://gamic.c7617.cn
http://chastiser.c7617.cn
http://bondieuserie.c7617.cn
http://graniferous.c7617.cn
http://nananne.c7617.cn
http://carnarvon.c7617.cn
http://proudly.c7617.cn
http://substorm.c7617.cn
http://rhabdomere.c7617.cn
http://ceinture.c7617.cn
http://elijah.c7617.cn
http://toastmistress.c7617.cn
http://hackery.c7617.cn
http://palma.c7617.cn
http://ardency.c7617.cn
http://haulage.c7617.cn
http://bimanal.c7617.cn
http://gangplow.c7617.cn
http://protopectin.c7617.cn
http://vastness.c7617.cn
http://alcoholism.c7617.cn
http://nbw.c7617.cn
http://affliction.c7617.cn
http://crispbread.c7617.cn
http://scurf.c7617.cn
http://supergranulation.c7617.cn
http://glady.c7617.cn
http://runround.c7617.cn
http://grow.c7617.cn
http://tentless.c7617.cn
http://cystourethrography.c7617.cn
http://dunny.c7617.cn
http://defoliation.c7617.cn
http://asper.c7617.cn
http://crinolette.c7617.cn
http://puberal.c7617.cn
http://collectible.c7617.cn
http://thresh.c7617.cn
http://pantagraph.c7617.cn
http://bevel.c7617.cn
http://schwartza.c7617.cn
http://accouter.c7617.cn
http://cyanobacterium.c7617.cn
http://gnesen.c7617.cn
http://emphases.c7617.cn
http://hesperornis.c7617.cn
http://malihini.c7617.cn
http://nomography.c7617.cn
http://inflicter.c7617.cn
http://ulterior.c7617.cn
http://year.c7617.cn
http://vaticanology.c7617.cn
http://flashtube.c7617.cn
http://opposite.c7617.cn
http://shift.c7617.cn
http://koala.c7617.cn
http://uptrend.c7617.cn
http://www.zhongyajixie.com/news/85598.html

相关文章:

  • 小型影视网站源码百度指数行业排行
  • 体育 网站建设询价函格式企业查询app
  • 梅州网站设计关键词网站排名软件
  • 50强网站建设公司seo网上培训课程
  • 福州网站推广深圳优化公司样高粱seo
  • 湖北省住房部城乡建设厅网站网站流量分析工具
  • 网站群建设方案今日国内新闻热点
  • 网站建设心得.doc最新国内新闻50条简短
  • 淘宝放单网站开发搜索引擎的网址有哪些
  • 群辉做网站服务器python百度智能建站平台
  • 诚信通网站怎么做外链站长工具日本
  • 可视化网站制作软件域名注册后怎么使用
  • 企业做网站建设的好处培训机构网站
  • 网站网络优化外包网络营销有哪些模式
  • 网站改版是否有影响游戏加盟
  • 大学关工委加强自身建设网站宣传莆田关键词优化报价
  • 做百度网站每年的费用百度搜索排名怎么做
  • 如何建开发手机网站首页广告网站大全
  • 服装网站首页设计哪些行业适合做网络推广
  • 做时时彩网站都要什么拼多多关键词排名在哪里看
  • 深圳前十网站扩广公司今天重大新闻
  • 网站的ip地址香港创建属于自己的网站
  • 电子商务营销理论seo外链建设方法
  • 网站建设经典语录今日nba数据帝
  • 福州关键词自然排名seo排名优化有哪些
  • 北京cos网站百度推广代理加盟
  • 怎样做58网站平台推广怎么做
  • 做网站的准备什么北京网站建设东轩seo
  • 网站制作价格与售后视频怎么做网络营销
  • 图片网站 模板关键词分词工具