转自:http://blog.csdn.net/jrckkyy/article/category/402818
由于百度博客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="http://search.yahoo.com/search">

<table cellpadding=0 cellspacing=0 border=0><tr><td>

<input type=text size=30 name=p title="enter search terms here">

<input type=submit value=Search> </td><td><font face=arial size=-2>·

<a href="http://search.yahoo.com/search/options?p=">advanced search</a><br>·

<a href="http://buzz.yahoo.com/">most 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);"> </td>

<td nowrap><a href="http://utility.baidu.com/quality/quality_form.php?word=jrckkyy">与百度对话</a></td>

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

<select onChange=reRange(this.selectedIndex) name=range>

<script language=javascript>

<!--

; i < rescode.length; i++) {

) {

document.write(] + '</option>');

} else {

document.write(] + '</option>');

}

}

document.f.range.selectedIndex ;

-->

</script>

</select>

</font>-<font color=#ffffff>

<select name=cd>

<script language=javascript>

<!--

var ind = document.f.range.selectedIndex;

;

;

; i < len; i++) {

document.write(] + '</option>');

)

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

;

iDisplayRst.ShowMiddle(iQuery.m_sQuery,used_msec,

setRelevantRst.size(), iQuery.m_iStart);

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

;

}

http://jrckkyy.cublog.cn (http://blog.chinaunix.net/u2/83460/)
http://blog.csdn.net/jrckkyy
http://hi.baidu.com/jrckkyy
- 鸿蒙内核源码分析(源码注释篇) | 鸿蒙必定成功,也必然成功 | 百篇博客分析OpenHarmony源码 | v13.02
百篇博客系列篇.本篇为: v13.xx 鸿蒙内核源码分析(源码注释篇) | 鸿蒙必定成功,也必然成功 | 51.c.h .o 几点说明 kernel_liteos_a_note | 中文注解鸿蒙内核 ...
- ceph-csi源码分析(3)-rbd driver-服务入口分析
更多ceph-csi其他源码分析,请查看下面这篇博文:kubernetes ceph-csi分析目录导航 ceph-csi源码分析(3)-rbd driver-服务入口分析 当ceph-csi组件启动 ...
- 从零学脚手架(八)---webpack-dev-server源码分析
上一篇中介绍了webpack-dev-server属性配置 这一篇就简单的梳理下webpack-dev-server内部实现. 由于涉及到源码解析,所以会涉及到一些比较难啃的知识,我会尽量进行简单化描 ...
- windows本地script脚本恶意代码分析(带注释)
//经过样本分析和抓取,该恶意程序是款下载者木马. //不懂的可以百度百科. http://baike.baidu.com/link?url=0dNqFM8QIjEQhD71ofElH0wHGktIQ ...
- C#分析搜索引擎URL得到搜索关键字,并判断页面停留时间以及来源页面
前台代码: var start; var end; var state; var lasturl = document.referrer; start = new Date($.ajax({ asyn ...
- [python爬虫] Selenium定向爬取海量精美图片及搜索引擎杂谈
我自认为这是自己写过博客中一篇比较优秀的文章,同时也是在深夜凌晨2点满怀着激情和愉悦之心完成的.首先通过这篇文章,你能学到以下几点: 1.可以了解Python简单爬取图片的一些思路和方法 ...
- google搜索引擎使用方法
搜索引擎命令大全!这是一个我最喜欢的Google搜索技巧的清单: link:URL = 列出到链接到目标URL的网页清单. related:URL = 列出于目标URL地址有关的网页. site:ht ...
- 9个基于Java的搜索引擎框架
在这个信息相当繁杂的互联网时代,我们已经学会了如何利用搜索引擎这个强大的利器来找寻目标信息,比如你会在Google上搜索情人节如何讨女朋友欢心,你也会在百度上寻找正规的整容医疗机构(尽管有很大一部分广 ...
- [Search Engine] 搜索引擎分类和基础架构概述
大家一定不会多搜索引擎感到陌生,搜索引擎是互联网发展的最直接的产物,它可以帮助我们从海量的互联网资料中找到我们查询的内容,也是我们日常学习.工作和娱乐不可或缺的查询工具.之前本人也是经常使用Googl ...
随机推荐
- 2016.5.21——atoi()函数的测试
对函数atoi()函数的测试: atoi()函数将字符串型转换为整型 代码: #include "stdafx.h" #include "iostream" # ...
- 【NOIP题解】NOIP2017 TG D2T3 列队
列队,NOIP2017 TG D2T3. 树状数组经典题. 题目链接:洛谷. 题意: Sylvia 是一个热爱学习的女孩子. 前段时间,Sylvia 参加了学校的军训.众所周知,军训的时候需要站方阵. ...
- 十五、springboot集成定时任务(Scheduling Tasks)(二)之(线程配置)
配置类: /** * 定时任务线程配置 * */ @Configuration public class SchedulerConfig implements SchedulingConfigurer ...
- Java与redis交互、Jedis连接池JedisPool
Java与redis交互比较常用的是Jedis. 先导入jar包: commons-pool2-2.3.jar jedis-2.7.0.jar 基本使用: public class RedisTest ...
- C实现线程池
简介:这里使用linux下的互斥锁和条件变量实现了一个线程池.代码由一个未知作者完成,第二任作者补充优化. 本人仅仅是做了一些注释工作. 代码如下: /*! .h */ #include <st ...
- SQL Server存储过程的删除方法
SQL Server存储过程的删除方法使我们经常会用到的,下面就为您介绍扩展存储过程的删除方法,如果您对SQL Server存储过程方面感兴趣的话,不妨一看. --清除SQL Server所有的危险扩 ...
- 关于django过滤器的使用
最近项目中要做分类筛选,其实已经做了这个功能,但是有一个字段是MultiSelectField类型,包含多个值,用户提交的数据是单个值,无法查询出结果, 所以用到了自定义过滤 原代码 class In ...
- MySQL学习笔记:从一个表update到另外一个表
# ---- 测试数据 ---- # 表1 CREATE TABLE temp_x AS AS c_id, 1.11 AS c_amount FROM DUAL UNION ALL AS c_id, ...
- 10月15日 | 云栖大会“淘宝移动技术实践&开放论坛”来了!
参会报名链接:http://baichuan.taobao.com/marketing/yunqi#?baichuan_channel=cnblogs 顺应移动互联网消费升级趋势, 淘宝作为移动领域的 ...
- Knockout.Js官网学习Demo(使用VS2012或者VS2013均可打开)
https://pan.baidu.com/s/1gf9JZ8n#list/path=%2F