• <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 評論 :: 0 Trackbacks

            由于百度博客http://hi.baidu.com/jrckkyy發(fā)表文章字?jǐn)?shù)有限,以后原創(chuàng)文章全部都先發(fā)表到csdn和cu上,再發(fā)表到百度博客上,百度博客除了放原創(chuàng)的文章還主要放網(wǎng)上尋找到的優(yōu)秀文章。

            本著黑客精神我將陸續(xù)把最近分析注釋TSE搜索引擎的心得發(fā)布出來,老鳥,大蝦,大牛,高手飄過就是了,若愿意浪費(fèi)指點(diǎn)下小弟的在下不甚感激,有問題的朋友直接留言討論。由于本人水平有限,分析和翻譯難免有錯(cuò)大家見笑了。

            上學(xué)期拜讀了James F.Kurose著的《計(jì)算機(jī)網(wǎng)絡(luò)-自頂向下方法與internet特色(第三版陰影)》,覺得寫得確實(shí)不錯(cuò)(希望沒看的朋友一定要買來看看),自己也來搞個(gè)高自頂向下的學(xué)習(xí)方法,先從用戶看得到的東西出發(fā)分析研究搜索引擎,下面我們就來看看各大搜索引擎搜索界面的代碼,你所需要特別注意的是form表單中的action

            雅虎http://www.yohoo.com/

            <form name=s1 style="margin-bottom:0" action="<table cellpadding=0 cellspacing=0 border=0><tr><td>
            <input type=text size=30 name=p title="enter search terms here">&nbsp;
            <input type=submit value=Search>&nbsp;&nbsp;</td><td><font face=arial size=-2>·&nbsp;
            <a href="
            search</a><br>·&nbsp;
            <a href="
            popular</a></font></td></tr></table></form>
            谷歌
            http://www.g.cn

            <form method=GET action=/search><tr><td nowrap>
            <font size=-1><input type=text name=q size=41 maxlength=2048 value="jrckkyy" title="Google 搜索"> <input type=submit name=btnG value="Google 搜索"><input type=hidden name=complete value=1><input type=hidden name=hl value="zh-CN"><input type=hidden name=newwindow value=1><input type=hidden name=sa value="2"></font></td></tr></form>
            百度http://www.baidu.com

            <form name=f2 action="/s">
            <tr valign="middle">
            <td nowrap>
            <input type=hidden name=ct value="0">
            <input type=hidden name=ie value="gb2312">
            <input type=hidden name=bs value="jrckkyy">
            <input type=hidden name=sr>
            <input type=hidden name=z value="">
            <input type=hidden name=cl value=3>
            <input type=hidden name=f value=8>
            <input name=wd size="35" class=i value="jrckkyy" maxlength=100>
            <input type=submit value=百度一下> <input type=button value=結(jié)果中找 onclick="return bq(f2,1,0);">&nbsp;&nbsp;&nbsp;</td>
            <td nowrap><a href="</tr>
            </form>
            天網(wǎng)
            http://www.tianwang.com/

            <form name=f action="/cgi-bin/tw" method=get>
                            <td valign=center width=634 background=images/index_image_02.gif>
                                <table height=46 cellspacing=0 cellpadding=0 width=600 align=right  border=0>
                                    <tbody>
                                        <tr>
                                            <td height=50>
                                                <table cellspacing=0 cellpadding=0 width=600 border=0>
                                                    <tbody>
                                                        <tr>
                                              <td width="524" height="30" valign="bottom">
                                                    <div align="center">                                  <input name="word" type="text" size="40" maxlength="255" onClick="this.focus();checkWord(this,1)" onblutesr='checkWord(this,0)' value='請輸入資源名稱'>
                                                        <font color=#ffffff> &nbsp;
                                                        <select onChange=reRange(this.selectedIndex) name=range>
                                                            <script language=javascript>...
                                       <!--
                                       for(var i = 0; i < rescode.length; i++) ...{
                                           if(i == 0) ...{
                                               document.write('<option value="0" selected>' + rescode[i][0] + '</option>');
                                           } else ...{
                                               document.write('<option value="' + i + '">' + rescode[i][0] + '</option>');
                                           }
                                       }
                                       document.f.range.selectedIndex = 0;
                                       -->
                                     </script>
                                                        </select>
                                                        </font>-<font color=#ffffff>
                                                        <select name=cd>
                                                            <script language=javascript>...
                                       <!--
                                       var ind = document.f.range.selectedIndex;
                                       var len = (rescode[ind].length - 1) / 2;
                                       var sel = 0;
                                       for(var i = 0; i < len; i++) ...{
                                           document.write('<option value="' + rescode[ind][2*i+1] + '">' + rescode[ind][2*i+2] + '</option>');
                                           if(rescode[ind][2*i+1] == 0)
                                               sel = i;
                                       }
                                       document.f.cd.selectedIndex = sel;
                                       -->
                             </script>
                                                        </select>
                                                        </font></div>
                                                </td>
                            <td width="71" valign="bottom"><input id=submit2 type=image height=22 width=40 src="images/so2.gif" align=absMiddle name=submit></td>
                          </tr>
                                                        <tr>
                                                            <td colspan=3 height=25 class=style16>
                                                                <div align=center></div>
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </td>
                        </form>
            測試服務(wù)器TSE:

            <form method="get" action="/cgi-bin/index/TSESearch" name="tw">
                    <td width="100%" height="25" align="center">                          
                    <input type="text" name="word" size="55">
                    <input type="submit" value=" 搜索" name="www">
                    </td>                          
                    <input type="hidden" name="cdtype" value="GB">                        
                    </form>   
            由以上幾個(gè)form的屬性可以看出全部采用的是get方法,CGI做為處理程序,也就是C/C++,CGI全稱是“公共網(wǎng)關(guān)界面”(Common Gateway Interface),HTTP服務(wù)器與你的或其它機(jī)器上的程序進(jìn)行“交談”的一種工具,其程序須運(yùn)行在網(wǎng)絡(luò)服務(wù)器上。CGI逐漸被近幾年來的PHP,JAVA,ASP,PERL,Python,Ruby等動態(tài)語言所取代。但是其在速度和運(yùn)行效率上的優(yōu)勢是無法取代的。

            以下是TSE CGI入口程序注釋,其他搜索引擎的入口也應(yīng)該類似

             

            /**//**
             * 程序翻譯說明
             * @Copyright (c) 2008, 研發(fā)部
             * All rights reserved.
             *
             * @filesource  TSESearch.cpp
             * @author  jrckkyy <jrckkyy@163.com>
             *
             * Let's start
             *
             */
            #include <stdio.h>
            #include <stdlib.h>
            #include <string.h>
            #include <sys/types.h>
            #include <sys/stat.h>
            #include <fcntl.h>
            #include <sys/time.h>
            #include <unistd.h>

            #include <iostream>
            #include <fstream>
            #include <list>

            #include "Comm.h"    //包含2個(gè)索引和1個(gè)數(shù)據(jù)文件
            #include "Query.h"    //包含數(shù)據(jù)查詢處理頭文件
            #include "Document.h"    //html文檔處理頭文件
            #include "StrFun.h"        //字符串處理頭文件
            #include "ChSeg/Dict.h"    //字元字典處理頭文件
            #include "ChSeg/HzSeg.h"   
            #include "DisplayRst.h"    //返回查詢結(jié)果頁面頭文件,返回結(jié)果分為頭部,中部,底部

            using namespace std;

            /**//*
             * A inverted file(INF) includes a term-index file & a inverted-lists file.
             * A inverted-lists consists of many bucks(posting lists).
             * The term-index file is stored at vecTerm, and
             * the inverted-lists is sored at mapBuckets.
             */

            /**//**
             * 程序翻譯說明
             * 搜索程序入口前臺關(guān)鍵字提交到該cgi程序 例如:./cgi-bin/index/TSESearch?word=123&start=1
             * 倒排文件包括一個(gè)記錄檢索詞文件和一個(gè)倒排列表文件。
             * 倒排列表包含很多標(biāo)志(提交名單)。
             * 記錄檢索詞文件使用vecTerm來排序,和倒排列表是用mapBuckets來排序。
             *
             * @access  public
             * @param   int char 參數(shù)的漢字說明 用于接收前臺get傳遞的參數(shù)
             * @return  string 0
             */
            int main(int argc, char* argv[])
            ...{
                struct timeval begin_tv, end_tv;
                struct timezone tz;

                CDict iDict;
                map<string, string> dictMap, mapBuckets;
                vector<DocIdx> vecDocIdx;    //Document。h

                CQuery iQuery;
                iQuery.GetInputs();        //具體程序開始執(zhí)行
                // current query & result page number
                iQuery.SetQuery();
                iQuery.SetStart();

                // begin to search
                //開始具體搜索程序
                gettimeofday(&begin_tv,&tz);    //開始計(jì)時(shí)獲取程序運(yùn)行時(shí)間差

                iQuery.GetInvLists(mapBuckets);        //將所有字符集存入映射變量中    瓶頸所在
                iQuery.GetDocIdx(vecDocIdx);        //將倒排索引存入向量中        瓶頸所在
               
                CHzSeg iHzSeg;        //include ChSeg/HzSeg.h
                iQuery.m_sSegQuery = iHzSeg.SegmentSentenceMM(iDict, iQuery.m_sQuery);    //將get到的查詢變量分詞分成 "我/        愛/        你們/    的/        格式"
               
                vector<string> vecTerm;
                iQuery.ParseQuery(vecTerm);        //將以"/"劃分開的關(guān)鍵字一一順序放入一個(gè)向量容器中
               
                set<string> setRelevantRst;
                iQuery.GetRelevantRst(vecTerm, mapBuckets, setRelevantRst);
               
                gettimeofday(&end_tv,&tz);
                // search end
                //搜索完畢

                //下面開始顯示
                CDisplayRst iDisplayRst;
                iDisplayRst.ShowTop();

                float used_msec = (end_tv.tv_sec-begin_tv.tv_sec)*1000
                    +((float)(end_tv.tv_usec-begin_tv.tv_usec))/(float)1000;

                iDisplayRst.ShowMiddle(iQuery.m_sQuery,used_msec,
                        setRelevantRst.size(), iQuery.m_iStart);

                iDisplayRst.ShowBelow(vecTerm,setRelevantRst,vecDocIdx,iQuery.m_iStart);

                return 0;

            }

             

             

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

            評論

            # re: 自頂向下學(xué)搜索引擎——北大天網(wǎng)搜索引擎TSE分析及完全注釋[1]尋找搜索引擎入口 2009-12-12 09:44 coconut
            cgi是接口,和語言無關(guān),可以是C也可以是其他語言。  回復(fù)  更多評論
              

            99久久免费只有精品国产| 婷婷久久香蕉五月综合加勒比| 亚洲精品午夜国产VA久久成人| 国产香蕉97碰碰久久人人| 国产成人综合久久综合| 国产精品无码久久综合 | 精品久久久久一区二区三区| 久久AV高清无码| 国产午夜福利精品久久2021| 狠狠色婷婷综合天天久久丁香 | 日韩中文久久| 亚洲伊人久久综合影院| 久久久这里有精品| 亚洲国产另类久久久精品小说 | 午夜人妻久久久久久久久| 久久久久久免费视频| 久久精品国产免费观看| 无码人妻久久一区二区三区免费| 久久亚洲国产精品成人AV秋霞| 亚洲中文久久精品无码| 国产一级做a爰片久久毛片| 999久久久国产精品| 久久这里都是精品| 国产麻豆精品久久一二三| 18岁日韩内射颜射午夜久久成人| 精品久久久无码中文字幕天天| 亚洲人成无码久久电影网站| 成人久久免费网站| 国内精品伊人久久久久影院对白| 思思久久99热免费精品6| 99久久婷婷国产综合亚洲| 国产福利电影一区二区三区久久久久成人精品综合 | 91精品国产综合久久婷婷| 亚洲国产精品久久久久| 精品久久久一二三区| 青青草原综合久久| 久久人人爽人人爽人人av东京热 | 亚洲第一永久AV网站久久精品男人的天堂AV | 久久综合亚洲色HEZYO国产| 久久99精品国产麻豆| 三级三级久久三级久久 |