• <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>

            學著站在巨人的肩膀上

            金融數學,InformationSearch,Compiler,OS,

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

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

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

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

            1、運行命令#./DocIndex
            會用到一個文件 tianwang.raw.520    //爬取回來的原始文件,包含多個網頁的所有信息,所以很大,這也是一個有待解決的問題,到底存成大文件(如果過大會超過2G或4G的限制,而且文件過大索引效率過低)還是小文件(文件數過多用于打開關閉文件句柄的消耗過大)還有待思考,還就是存儲方案的解決最終肯定是要存為分布式的,最終總文件量肯定是會上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文檔,里面的文檔有規律的分隔就叫做一篇一篇的文檔)


            //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; //前臺搜索結果數據集返回條數

            //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(); //將字符數組組合成字符串這個函數在Md5.h中實現

               } else
               {
                continue;
               }

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

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

               iDocument.m_nDocId = cnt; //將文檔編號賦值到iDocument數據結構中
               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); //根據獲得的文檔長度讀取澹(其中包含協議頭)讀取文檔內容
               iMD5.GenerateMD5( (unsigned char*)pContent, iDocument.m_nLength );
               iDocument.m_sChecksum = iMD5.ToString(); //將字符數組組合成字符串這個函數在Md5.h中實現
               
               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: 自頂向下學搜索引擎——北大天網搜索引擎TSE分析及完全注釋[6]倒排索引的建立的程序分析(1) 2009-12-12 13:18 夢芭莎內衣
            阿喀琉斯貸記卡是看見的  回復  更多評論
              

            久久久久久久久久免免费精品| 久久午夜夜伦鲁鲁片免费无码影视| 久久久久亚洲av无码专区| 一本色道久久88综合日韩精品 | 久久人做人爽一区二区三区| 亚洲精品成人网久久久久久| 国产成人精品综合久久久久 | 综合久久一区二区三区| 久久精品国产免费观看| 久久青青草原综合伊人| 亚洲国产成人精品91久久久 | 久久久国产打桩机| 国内精品久久久久伊人av| 中文精品久久久久国产网址 | 国产国产成人久久精品| 国产69精品久久久久观看软件 | 亚洲综合精品香蕉久久网| 久久国产亚洲精品麻豆| 怡红院日本一道日本久久 | 日产精品99久久久久久| 91精品国产色综久久| 伊人久久大香线蕉综合影院首页| 亚洲国产精品久久久久婷婷软件| 久久精品国产久精国产一老狼| 亚洲一区二区三区日本久久九| 色狠狠久久AV五月综合| 综合久久给合久久狠狠狠97色| 青青草原1769久久免费播放| 亚洲AV日韩AV永久无码久久| 欧美亚洲另类久久综合婷婷| 久久久久久久99精品免费观看| 伊人久久综合成人网| 久久强奷乱码老熟女网站| 狠狠久久亚洲欧美专区| 欧美噜噜久久久XXX| 亚洲中文字幕无码久久精品1| 亚洲午夜福利精品久久| 无夜精品久久久久久| 少妇久久久久久被弄到高潮| 久久久久人妻一区精品| 久久无码国产|