這里介紹正向索引的建立,如果直接建立倒排索引效率上可能會很低,所以可以先產生正向索引為后面的倒排索引打下基礎。
詳細的文件功能和介紹都在這里有了介紹自頂向下學搜索引擎——北大天網搜索引擎TSE分析及完全注釋[5]倒排索引的建立及文件介紹
CrtForwardIdx.cpp文件
int main(int argc, char* argv[]) //./CrtForwardIdx Tianwang.raw.***.seg > moon.fidx
{
ifstream ifsImgInfo(argv[1]);
if (!ifsImgInfo)
{
cerr << "Cannot open " << argv[1] << " for input\n";
return -1;
}
string strLine,strDocNum;
int cnt = 0;
while (getline(ifsImgInfo, strLine))
{
string::size_type idx;
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 ) //指定查找分界符
{
string tmp1 = strLine.substr(0,idx);
cout << tmp1 << "\t" << strDocNum << endl;
strLine = strLine.substr(idx + SEPARATOR.size());
}
//if (cnt==100) break;
}
return 0;
}
author:http://hi.baidu.com/jrckkyy
author:http://blog.csdn.net/jrckkyy