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

            學(xué)著站在巨人的肩膀上

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

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

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

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

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

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

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

            3、運(yùn)行命令#./DocSegment Tianwang.raw.2559638448 
            會(huì)用到一個(gè)文件 Tianwang.raw.2559638448  //Tianwang.raw.2559638448為爬回來的文件 ,每個(gè)頁面包含http頭,分詞為后面建立到排索引做準(zhǔn)備
            會(huì)產(chǎn)生一個(gè)文件 Tianwang.raw.2559638448.seg //分詞文件,由一行document id號(hào)和一行文檔分詞組(只對(duì)每個(gè)文檔<html></html>中<head></head><body></body>等文字標(biāo)記中的文本進(jìn)行分組)構(gòu)成

            4、運(yùn)行命令#./CrtForwardIdx Tianwang.raw.2559638448.seg > moon.fidx //建立獨(dú)立的正向索引

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

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

            我們先從建立索引的第一個(gè)程序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; //前臺(tái)搜索結(jié)果數(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萬多條 字元文件 包括特殊符號(hào),標(biāo)點(diǎn),漢字
            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; //文檔編號(hào)從0開始計(jì)算
             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: 五個(gè)字符之后的url內(nèi)容
                iMD5.GenerateMD5( (unsigned char*)iUrl.m_sUrl.c_str(), iUrl.m_sUrl.size() ); //對(duì)url用md5 hash處理
                iUrl.m_sChecksum = iMD5.ToString(); //將字符數(shù)組組合成字符串這個(gè)函數(shù)在Md5.h中實(shí)現(xiàn)

               } else
               {
                continue;
               }

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

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

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

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

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

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

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

              nOffset = ifs.tellg();

             }

             //最后一行只有文檔號(hào)和上一篇文檔結(jié)束號(hào)
             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 學(xué)者站在巨人的肩膀上 閱讀(1326) 評(píng)論(1)  編輯 收藏 引用 所屬分類: 中文文本信息處理

            評(píng)論

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

            久久婷婷是五月综合色狠狠| 久久99亚洲网美利坚合众国| 久久亚洲2019中文字幕| 欧美午夜A∨大片久久| 久久无码AV一区二区三区| 久久天天躁夜夜躁狠狠躁2022| 久久精品国产亚洲av水果派| 国产香蕉97碰碰久久人人| 噜噜噜色噜噜噜久久| 亚洲精品高清久久| 亚洲综合精品香蕉久久网| 久久99国产精一区二区三区| 狠狠色丁香久久婷婷综合_中| 国产亚洲综合久久系列| 久久亚洲中文字幕精品一区| 亚洲国产天堂久久综合网站| 亚洲精品国精品久久99热一| 亚洲国产精品综合久久一线| 国产欧美久久一区二区| 久久亚洲AV成人无码国产| 亚洲国产精品一区二区三区久久 | 久久综合久久鬼色| 国产精品久久久久久影院| 国内精品久久久久影院薰衣草 | 久久精品卫校国产小美女| 日本加勒比久久精品| 国产精品久久久天天影视香蕉| 久久精品成人国产午夜| 久久精品欧美日韩精品| 久久青青草原亚洲av无码app| 国产成人精品综合久久久| 无码人妻久久一区二区三区蜜桃| 久久国产精品国语对白| 精品水蜜桃久久久久久久| 中文精品久久久久国产网址| 亚洲国产二区三区久久| 国产69精品久久久久9999| 久久综合综合久久97色| 国产成人综合久久久久久 | 久久久一本精品99久久精品88| 亚洲性久久久影院|