这里介绍正向索引的建立,如果直接建立倒排索引效率上可能会很低,所以可以先产生正向索引为后面的倒排索引打下基础。
详细的文件功能和介绍都在这里有了介绍自顶向下学搜索引擎——北大天网搜索引擎TSE分析及完全注释[5]倒排索引的建立及文件介绍
CrtForwardIdx.cpp文件
intmain(intargc,char*argv[])//./CrtForwardIdxTianwang.raw.***.seg>moon.fidx {ifstreamifsImgInfo(argv[1]); if(!ifsImgInfo) {cerr<<"Cannotopen"<<argv[1]<<"forinput/n"; return-1; } stringstrLine,strDocNum; intcnt=0; while(getline(ifsImgInfo,strLine)) {string::size_typeidx; cnt++; if(cnt%2==1)//奇数行为文档编号 {strDocNum=strLine.substr(0,strLine.size()); continue; } if(strLine[0]=='/0'||strLine[0]=='#'||strLine[0]=='/n') {continue; } while((idx=strLine.find(SEPARATOR))!=string::npos)//指定查找分界符 {stringtmp1=strLine.substr(0,idx); cout<<tmp1<<"/t"<<strDocNum<<endl; strLine=strLine.substr(idx+SEPARATOR.size()); } //if(cnt==100)break; } return0; }