分类: C/C++ 搜索引擎研究 2008-10-16 16:40 429人阅读 收藏 举报
以下是根据正向索引建立倒排索引的注释
- int main(int argc, char* argv[])
- {
- ifstream ifsImgInfo(argv[1]);
- if (!ifsImgInfo)
- {
- cerr << "Cannot open " << argv[1] << " for input/n";
- return -1;
- }
- string strLine,strDocNum,tmp1="";
- int cnt = 0;
- while (getline(ifsImgInfo, strLine))
- {
- string::size_type idx;
- string tmp;
- idx = strLine.find("/t");
- tmp = strLine.substr(0,idx);
- if (tmp.size()<2 || tmp.size() > 8) continue;
- if (tmp1.empty()) tmp1=tmp;
- if (tmp == tmp1)
- {
- strDocNum = strDocNum + " " + strLine.substr(idx+1);
- }
- else
- {
- if ( strDocNum.empty() )
- strDocNum = strDocNum + " " + strLine.substr(idx+1);
- cout << tmp1 << "/t" << strDocNum << endl;
- tmp1 = tmp;
- strDocNum.clear();
- strDocNum = strDocNum + " " + strLine.substr(idx+1);
- }
- cnt++;
-
- }
- cout << tmp1 << "/t" << strDocNum << endl;
- return 0;
- }
|