自顶向下学搜索引擎——北大天网搜索引擎TSE分析及完全注释[6]倒排索引的建立的程序分析(3)

这里介绍正向索引的建立,如果直接建立倒排索引效率上可能会很低,所以可以先产生正向索引为后面的倒排索引打下基础。

 

详细的文件功能和介绍都在这里有了介绍自顶向下学搜索引擎——北大天网搜索引擎TSE分析及完全注释[5]倒排索引的建立及文件介绍

 

CrtForwardIdx.cpp文件

 

  1. int main(int argc, char* argv[])    //./CrtForwardIdx Tianwang.raw.***.seg > moon.fidx
  2. {
  3.     ifstream ifsImgInfo(argv[1]);
  4.     if (!ifsImgInfo) 
  5.     {
  6.         cerr << "Cannot open " << argv[1] << " for input/n";
  7.         return -1;
  8.     }
  9.     string strLine,strDocNum;
  10.     int cnt = 0;
  11.     while (getline(ifsImgInfo, strLine)) 
  12.     {
  13.         string::size_type idx;
  14.         cnt++;
  15.         if (cnt%2 == 1) //奇数行为文档编号
  16.         {
  17.             strDocNum = strLine.substr(0,strLine.size());
  18.             continue;
  19.         }
  20.         if (strLine[0]=='/0' || strLine[0]=='#' || strLine[0]=='/n')
  21.         {
  22.             continue;
  23.         }
  24.         while ( (idx = strLine.find(SEPARATOR)) != string::npos ) //指定查找分界符
  25.         {
  26.             string tmp1 = strLine.substr(0,idx);
  27.             cout << tmp1 << "/t" << strDocNum << endl;
  28.             strLine = strLine.substr(idx + SEPARATOR.size());
  29.         }
  30.         //if (cnt==100) break;
  31.     }
  32.     return 0;
  33. }

 

author:http://hi.baidu.com/jrckkyy

author:http://blog.csdn.net/jrckkyy

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Zda天天爱打卡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值