600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > 北大天网搜索引擎TSE分析及完全注释[1]寻找搜索引擎入口

北大天网搜索引擎TSE分析及完全注释[1]寻找搜索引擎入口

时间:2023-06-14 16:29:09

相关推荐

北大天网搜索引擎TSE分析及完全注释[1]寻找搜索引擎入口

本着黑客精神我将陆续把最近分析注释TSE搜索引擎的心得发布出来,老鸟,大虾,大牛,高手飘过就是了,若愿意浪费指点下小弟的在下不甚感激,有问题的朋友直接留言讨论。由于本人水平有限,分析和翻译难免有错大家见笑了。

上学期拜读了James F.Kurose著的《计算机网络-自顶向下方法与internet特色(第三版阴影)》,觉得写得确实不错(希望没看的朋友一定要买来看看),自己也来搞个高自顶向下的学习方法,先从用户看得到的东西出发分析研究搜索引擎,下面我们就来看看各大搜索引擎搜索界面的代码,你所需要特别注意的是form表单中的action

雅虎/:

<formname=s1style="margin-bottom:0"action="/search">

<tablecellpadding=0cellspacing=0border=0><tr><td>

<inputtype=textsize=30name=ptitle="entersearchtermshere">&nbsp;

<inputtype=submitvalue=Search>&nbsp;&nbsp;</td><td><fontface=arialsize=-2>&#183;&nbsp;

<ahref="/search/options?p=">advancedsearch</a><br>&#183;&nbsp;

<ahref="/">mostpopular</a></font></td></tr></table></form>

谷歌:

<formmethod=GETaction=/search><tr><tdnowrap>

<fontsize=-1><inputtype=textname=qsize=41maxlength=2048value="jrckkyy"title="Google搜索"><inputtype=submitname=btnGvalue="Google搜索"><inputtype=hiddenname=completevalue=1><inputtype=hiddenname=hlvalue="zh-CN"><inputtype=hiddenname=newwindowvalue=1><inputtype=hiddenname=savalue="2"></font></td></tr></form>

百度:

<formname=f2action="/s">

<trvalign="middle">

<tdnowrap>

<inputtype=hiddenname=ctvalue="0">

<inputtype=hiddenname=ievalue="gb2312">

<inputtype=hiddenname=bsvalue="jrckkyy">

<inputtype=hiddenname=sr>

<inputtype=hiddenname=zvalue="">

<inputtype=hiddenname=clvalue=3>

<inputtype=hiddenname=fvalue=8>

<inputname=wdsize="35"class=ivalue="jrckkyy"maxlength=100>

<inputtype=submitvalue=百度一下><inputtype=buttonvalue=结果中找onclick="returnbq(f2,1,0);">&nbsp;&nbsp;&nbsp;</td>

<tdnowrap><ahref="/quality/quality_form.php?word=jrckkyy">与百度对话</a></td>

</tr>

</form>

天网/:

<formname=faction="/cgi-bin/tw"method=get>

<tdvalign=centerwidth=634background=images/index_image_02.gif>

<tableheight=46cellspacing=0cellpadding=0width=600align=rightborder=0>

<tbody>

<tr>

<tdheight=50>

<tablecellspacing=0cellpadding=0width=600border=0>

<tbody>

<tr>

<tdwidth="524"height="30"valign="bottom">

<divalign="center"><inputname="word"type="text"size="40"maxlength="255"onClick="this.focus();checkWord(this,1)"onblutesr='checkWord(this,0)'value='请输入资源名称'>

<fontcolor=#ffffff>&nbsp;

<selectonChange=reRange(this.selectedIndex)name=range>

<scriptlanguage=javascript>

<!--

for(vari=0;i<rescode.length;i++){

if(i==0){

document.write('<optionvalue="0"selected>'+rescode[i][0]+'</option>');

}else{

document.write('<optionvalue="'+i+'">'+rescode[i][0]+'</option>');

}

}

document.f.range.selectedIndex=0;

-->

</script>

</select>

</font>-<fontcolor=#ffffff>

<selectname=cd>

<scriptlanguage=javascript>

<!--

varind=document.f.range.selectedIndex;

varlen=(rescode[ind].length-1)/2;

varsel=0;

for(vari=0;i<len;i++){

document.write('<optionvalue="'+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>

<tdwidth="71"valign="bottom"><inputid=submit2type=imageheight=22width=40src="images/so2.gif"align=absMiddlename=submit></td>

</tr>

<tr>

<tdcolspan=3height=25class=style16>

<divalign=center></div>

</td>

</tr>

</tbody>

</table>

</td>

</tr>

</tbody>

</table>

</td>

</form>

测试服务器TSE:

<formmethod="get"action="/cgi-bin/index/TSESearch"name="tw">

<tdwidth="100%"height="25"align="center">

<inputtype="text"name="word"size="55">

<inputtype="submit"value="搜索"name="www">

</td>

<inputtype="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),研发部

*Allrightsreserved.

*

*@filesourceTSESearch.cpp

*@authorjrckkyy<jrckkyy@>

*

*Let'sstart

*

*/

#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"//返回查询结果页面头文件,返回结果分为头部,中部,底部

usingnamespacestd;

/*

*Ainvertedfile(INF)includesaterm-indexfile&ainverted-listsfile.

*Ainverted-listsconsistsofmanybucks(postinglists).

*Theterm-indexfileisstoredatvecTerm,and

*theinverted-listsissoredatmapBuckets.

*/

/**

*程序翻译说明

*搜索程序入口前台关键字提交到该cgi程序例如:./cgi-bin/index/TSESearch?word=123&start=1

*倒排文件包括一个记录检索词文件和一个倒排列表文件。

*倒排列表包含很多标志(提交名单)。

*记录检索词文件使用vecTerm来排序,和倒排列表是用mapBuckets来排序。

*

*@accesspublic

*@paramintchar参数的汉字说明用于接收前台get传递的参数

*@returnstring0

*/

intmain(intargc,char*argv[])

{

structtimevalbegin_tv,end_tv;

structtimezonetz;

CDictiDict;

map<string,string>dictMap,mapBuckets;

vector<DocIdx>vecDocIdx;//Document。h

CQueryiQuery;

iQuery.GetInputs();//具体程序开始执行

//currentquery&resultpagenumber

iQuery.SetQuery();

iQuery.SetStart();

//begintosearch

//开始具体搜索程序

gettimeofday(&begin_tv,&tz);//开始计时获取程序运行时间差

iQuery.GetInvLists(mapBuckets);//将所有字符集存入映射变量中瓶颈所在

iQuery.GetDocIdx(vecDocIdx);//将倒排索引存入向量中瓶颈所在

CHzSegiHzSeg;//includeChSeg/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);

//searchend

//搜索完毕

//下面开始显示

CDisplayRstiDisplayRst;

iDisplayRst.ShowTop();

floatused_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);

return0;

} 复制搜索 复制搜索

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。