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

            由于百度博客http://hi.baidu.com/jrckkyy發表文章字數有限,以后原創文章全部都先發表到csdn和cu上,再發表到百度博客上,百度博客除了放原創的文章還主要放網上尋找到的優秀文章。

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

            上學期拜讀了James F.Kurose著的《計算機網絡-自頂向下方法與internet特色(第三版陰影)》,覺得寫得確實不錯(希望沒看的朋友一定要買來看看),自己也來搞個高自頂向下的學習方法,先從用戶看得到的東西出發分析研究搜索引擎,下面我們就來看看各大搜索引擎搜索界面的代碼,你所需要特別注意的是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=結果中找 onclick="return bq(f2,1,0);">&nbsp;&nbsp;&nbsp;</td>
            <td nowrap><a href="</tr>
            </form>
            天網
            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>
            測試服務器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>   
            由以上幾個form的屬性可以看出全部采用的是get方法,CGI做為處理程序,也就是C/C++,CGI全稱是“公共網關界面”(Common Gateway Interface),HTTP服務器與你的或其它機器上的程序進行“交談”的一種工具,其程序須運行在網絡服務器上。CGI逐漸被近幾年來的PHP,JAVA,ASP,PERL,Python,Ruby等動態語言所取代。但是其在速度和運行效率上的優勢是無法取代的。

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

             

            /**//**
             * 程序翻譯說明
             * @Copyright (c) 2008, 研發部
             * 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個索引和1個數據文件
            #include "Query.h"    //包含數據查詢處理頭文件
            #include "Document.h"    //html文檔處理頭文件
            #include "StrFun.h"        //字符串處理頭文件
            #include "ChSeg/Dict.h"    //字元字典處理頭文件
            #include "ChSeg/HzSeg.h"   
            #include "DisplayRst.h"    //返回查詢結果頁面頭文件,返回結果分為頭部,中部,底部

            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.
             */

            /**//**
             * 程序翻譯說明
             * 搜索程序入口前臺關鍵字提交到該cgi程序 例如:./cgi-bin/index/TSESearch?word=123&start=1
             * 倒排文件包括一個記錄檢索詞文件和一個倒排列表文件。
             * 倒排列表包含很多標志(提交名單)。
             * 記錄檢索詞文件使用vecTerm來排序,和倒排列表是用mapBuckets來排序。
             *
             * @access  public
             * @param   int char 參數的漢字說明 用于接收前臺get傳遞的參數
             * @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();        //具體程序開始執行
                // current query & result page number
                iQuery.SetQuery();
                iQuery.SetStart();

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

                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);        //將以"/"劃分開的關鍵字一一順序放入一個向量容器中
               
                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 學者站在巨人的肩膀上 閱讀(2361) 評論(1)  編輯 收藏 引用 所屬分類: 中文文本信息處理

            評論

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

            久久国产一片免费观看| 97久久国产亚洲精品超碰热| 人妻少妇精品久久| 综合久久久久久中文字幕亚洲国产国产综合一区首| 激情五月综合综合久久69| 亚洲人成网站999久久久综合| 狠狠色婷婷久久一区二区 | 亚洲人成精品久久久久| av无码久久久久不卡免费网站 | 久久无码AV中文出轨人妻| 久久精品中文字幕无码绿巨人| 激情久久久久久久久久| 久久久久久国产精品无码超碰| 精品国产热久久久福利| 色偷偷偷久久伊人大杳蕉| 久久亚洲精品无码播放| 91精品国产91久久久久久青草| 亚洲午夜久久久影院| 久久综合成人网| 色成年激情久久综合| 久久综合综合久久综合| 久久国产亚洲精品| 99久久国产综合精品成人影院| 久久精品夜夜夜夜夜久久| 久久人人爽人人爽人人片AV东京热| 久久高清一级毛片| 国产精品gz久久久| 99热都是精品久久久久久| 97久久精品无码一区二区天美| 免费久久人人爽人人爽av| 亚洲七七久久精品中文国产| 久久青青国产| 亚洲国产成人久久笫一页| 久久亚洲国产精品五月天婷| 久久精品国产一区二区| 欧美性猛交xxxx免费看久久久| 久久99精品免费一区二区| 久久人人超碰精品CAOPOREN| 污污内射久久一区二区欧美日韩 | 少妇熟女久久综合网色欲| 中文精品99久久国产|