• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            學著站在巨人的肩膀上

            金融數(shù)學,InformationSearch,Compiler,OS,

              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              12 隨筆 :: 0 文章 :: 8 評論 :: 0 Trackbacks

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

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

            上一篇主要介紹了倒排索引建立相關的文件及中間文件。
            TSE建立索引在運行程序上的大致步驟可以簡化分為以下幾步:

            1、運行命令#./DocIndex
            會用到一個文件 tianwang.raw.520    //爬取回來的原始文件,包含多個網(wǎng)頁的所有信息,所以很大,這也是一個有待解決的問題,到底存成大文件(如果過大會超過2G或4G的限制,而且文件過大索引效率過低)還是小文件(文件數(shù)過多用于打開關閉文件句柄的消耗過大)還有待思考,還就是存儲方案的解決最終肯定是要存為分布式的,最終總文件量肯定是會上TB的,TSE只支持小型的搜索引擎需求。          
            會產生一下三個文件 Doc.idx, Url.idx, DocId2Url.idx    //Data文件夾中的Doc.idx DocId2Url.idx和Doc.idx

            2、運行命令#sort Url.idx|uniq > Url.idx.sort_uniq    //Data文件夾中的Url.idx.sort_uniq
            會用到一個文件 Url.idx文件 //md5 hash 之后的url完整地址和document id值對
            會產生一個文件 Url.idx.sort_uniq //URL消重,md5 hash排序,提高檢索效率

            3、運行命令#./DocSegment Tianwang.raw.2559638448 
            會用到一個文件 Tianwang.raw.2559638448  //Tianwang.raw.2559638448為爬回來的文件 ,每個頁面包含http頭,分詞為后面建立到排索引做準備
            會產生一個文件 Tianwang.raw.2559638448.seg //分詞文件,由一行document id號和一行文檔分詞組(只對每個文檔<html></html>中<head></head><body></body>等文字標記中的文本進行分組)構成

            4、運行命令#./CrtForwardIdx Tianwang.raw.2559638448.seg > moon.fidx //建立獨立的正向索引

            5、運行命令
            #set | grep "LANG"
            #LANG=en; export LANG;
            #sort moon.fidx > moon.fidx.sort

            6、運行命令#./CrtInvertedIdx moon.fidx.sort > sun.iidx //建立倒排索引

            我們先從建立索引的第一個程序DocIndex.cpp開始分析。(注釋約定:Tianwang.raw.2559638448是抓回來合并成的大文件,后面就叫大文件,里面包含了很多篇html文檔,里面的文檔有規(guī)律的分隔就叫做一篇一篇的文檔)


            //DocIndex.h start-------------------------------------------------------------

             


            #ifndef _COMM_H_040708_
            #define _COMM_H_040708_

            #include

            #include
            #include
            #include
            #include
            #include
            #include
            #include


            using namespace std;

            const unsigned HEADER_BUF_SIZE = 1024;
            const unsigned RstPerPage = 20; //前臺搜索結果數(shù)據(jù)集返回條數(shù)

            //iceway
            //const unsigned MAX_DOC_IDX_ID = 21312;  //DocSegment.cpp中要用到
            const unsigned MAX_DOC_IDX_ID = 22104;


            //const string IMG_INFO_NAME("./Data/s1.1");
            const string INF_INFO_NAME("./Data/sun.iidx"); //倒排索引文件
            //朱德  14383 16151 16151 16151 1683 207 6302 7889 8218 8218 8637
            //朱古力  1085 1222

            //9萬多條 字元文件 包括特殊符號,標點,漢字
            const string DOC_IDX_NAME("./Data/Doc.idx"); //倒排索引文件
            const string RAWPAGE_FILE_NAME("./Data/Tianwang.swu.iceway.1.0");

            //iceway
            const string DOC_FILE_NAME = "Tianwang.swu.iceway.1.0";  //Docindex.cpp中要用到
            const string Data_DOC_FILE_NAME = "./Data/Tianwang.swu.iceway.1.0";  //Snapshot.cpp中要用到


            //const string RM_THUMBNAIL_FILES("rm -f ~/public_html/ImgSE/timg/*");

            //const string THUMBNAIL_DIR("/ImgSE/timg/");


            #endif _COMM_H_040708_
            //DocIndex.h end--------------------------------------------------------------//DocIndex.cpp start-----------------------------------------------------------

            #include
            #include
            #include "Md5.h"
            #include "Url.h"
            #include "Document.h"

            //iceway(mnsc)
            #include "Comm.h"
            #include

            using namespace std;

            int main(int argc, char* argv[])
            {
                //ifstream ifs("Tianwang.raw.2559638448");
             //ifstream ifs("Tianwang.raw.3023555472");
             //iceway(mnsc)
             ifstream ifs(DOC_FILE_NAME.c_str()); //打開Tianwang.raw.3023555472文件,最原始的文件
             if (!ifs)
             {
                 cerr << "Cannot open " << "tianwang.img.info" << " for input\n";
                 return -1;
                }
             ofstream ofsUrl("Url.idx", ios::in|ios::out|ios::trunc|ios::binary); //建立并打開Url.idx文件
             if( !ofsUrl )
             {
              cout << "error open file " << endl;
             }

             ofstream ofsDoc("Doc.idx", ios::in|ios::out|ios::trunc|ios::binary); //建立并打開Doc.idx文件
             if( !ofsDoc )
             {
              cout << "error open file " << endl;
             }

             ofstream ofsDocId2Url("DocId2Url.idx", ios::in|ios::out|ios::trunc|ios::binary); //建立并打開DocId2Url.idx文件
             if( !ofsDocId2Url )
             {
              cout << "error open file " << endl;
             }

             int cnt=0; //文檔編號從0開始計算
             string strLine,strPage;
             CUrl iUrl;
             CDocument iDocument;
             CMD5 iMD5;
             
             int nOffset = ifs.tellg();
             while (getline(ifs, strLine))
             {
              if (strLine[0]=='\0' || strLine[0]=='#' || strLine[0]=='\n')
              {
               nOffset = ifs.tellg();
               continue;
              }

              if (!strncmp(strLine.c_str(), "version: 1.0", 12)) //判斷第一行是否是version: 1.0如果是就解析下去
              { 
               if(!getline(ifs, strLine)) break;
               if (!strncmp(strLine.c_str(), "url: ", 4)) //判斷第二行是否是url: 如果是則解析下去
               {
                iUrl.m_sUrl = strLine.substr(5); //截取url: 五個字符之后的url內容
                iMD5.GenerateMD5( (unsigned char*)iUrl.m_sUrl.c_str(), iUrl.m_sUrl.size() ); //對url用md5 hash處理
                iUrl.m_sChecksum = iMD5.ToString(); //將字符數(shù)組組合成字符串這個函數(shù)在Md5.h中實現(xiàn)

               } else
               {
                continue;
               }

               while (getline(ifs, strLine))
               {
                if (!strncmp(strLine.c_str(), "length: ", 8)) //一直讀下去直到判斷澹澹(相對第五行)惺欠袷莑ength: 是則接下下去
                {
                 sscanf(strLine.substr(8).c_str(), "%d", &(iDocument.m_nLength)); //將該塊所代表網(wǎng)頁的實際網(wǎng)頁內容長度放入iDocument數(shù)據(jù)結構中
                 break;
                }
               }

               getline(ifs, strLine); //跳過相對第六行故意留的一個空行

               iDocument.m_nDocId = cnt; //將文檔編號賦值到iDocument數(shù)據(jù)結構中
               iDocument.m_nPos = nOffset; //文檔結尾在大文件中的結束行號
               char *pContent = new char[iDocument.m_nLength+1]; //新建該文檔長度的字符串指針

               memset(pContent, 0, iDocument.m_nLength+1); //每一位初始化為0
               ifs.read(pContent, iDocument.m_nLength); //根據(jù)獲得的文檔長度讀取澹(其中包含協(xié)議頭)讀取文檔內容
               iMD5.GenerateMD5( (unsigned char*)pContent, iDocument.m_nLength );
               iDocument.m_sChecksum = iMD5.ToString(); //將字符數(shù)組組合成字符串這個函數(shù)在Md5.h中實現(xiàn)
               
               delete[] pContent;
               
               ofsUrl << iUrl.m_sChecksum ; //將md5hash后的url寫入Url.idx文件
               ofsUrl << "\t" << iDocument.m_nDocId << endl; //在一行中一個tab距離分隔,將文件編號寫入Url.idx文件

               ofsDoc << iDocument.m_nDocId ; //將文件編號寫入Doc.idx文件
               ofsDoc << "\t" << iDocument.m_nPos ; //在一行中一個tab距離分隔,將該文檔結束行號澹(同樣也是下一文檔開始行號)寫入Doc.idx文件
               //ofsDoc << "\t" << iDocument.m_nLength ;
               ofsDoc << "\t" << iDocument.m_sChecksum << endl; //在一行中一個tab距離分隔,將md5hash后的url寫入Doc.idx文件

               ofsDocId2Url << iDocument.m_nDocId ; //將文件編號寫入DocId2Url.idx文件
               ofsDocId2Url << "\t" << iUrl.m_sUrl << endl; //將該文檔的完整url寫入DocId2Url.idx文件

               cnt++; //文檔編號加一說明該以文檔分析完畢,生成下一文檔的編號
              }

              nOffset = ifs.tellg();

             }

             //最后一行只有文檔號和上一篇文檔結束號
             ofsDoc << cnt ;
             ofsDoc << "\t" << nOffset << endl;


             return(0);
            }

            //DocIndex.cpp end-----------------------------------------------------------author:http://hi.baidu.com/jrckkyy

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

             

             

            posted on 2009-12-10 23:00 學者站在巨人的肩膀上 閱讀(1326) 評論(1)  編輯 收藏 引用 所屬分類: 中文文本信息處理

            評論

            # re: 自頂向下學搜索引擎——北大天網(wǎng)搜索引擎TSE分析及完全注釋[6]倒排索引的建立的程序分析(1) 2009-12-12 13:18 夢芭莎內衣
            阿喀琉斯貸記卡是看見的  回復  更多評論
              

            丁香狠狠色婷婷久久综合| 色成年激情久久综合| 2021国内久久精品| 青青青青久久精品国产| 国产L精品国产亚洲区久久| 99久久国产宗和精品1上映| 精品无码久久久久久久久久| 国产精品久久久久久吹潮| 精品熟女少妇AV免费久久| 色综合久久综精品| 久久精品国产亚洲77777| 99精品国产在热久久无毒不卡 | 久久美女网站免费| 欧美性猛交xxxx免费看久久久| 99久久免费国产精精品| 久久九色综合九色99伊人| 久久婷婷国产麻豆91天堂| 日本精品一区二区久久久| 精品久久久久久无码专区不卡| 久久综合伊人77777| 亚洲国产成人精品无码久久久久久综合| 亚洲色婷婷综合久久| 久久久人妻精品无码一区| 久久99精品国产麻豆宅宅| 久久精品国产福利国产秒| 亚洲午夜久久久久久久久电影网| 久久一区二区免费播放| 久久99国产精品久久久| 久久99国产精一区二区三区| 久久久久亚洲AV成人片| 国产成人无码久久久精品一| 久久91这里精品国产2020| 奇米影视7777久久精品| 亚洲国产精品久久久久婷婷软件| 久久综合综合久久97色| 777午夜精品久久av蜜臀 | 久久精品无码一区二区三区免费 | 99久久国产主播综合精品| 国产精品久久久亚洲| 丁香狠狠色婷婷久久综合| 国产精品一区二区久久|