转自: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 ...
随机推荐
- shell脚本实现监控shell脚本的执行流程及变量的值
这篇文章主要介绍了shell脚本实现监控shell脚本的执行流程及变量的值本文使用shell完成对执行过程中条件语句中的变量的变化的监控和整个程序的执行流程的观察功能,需要的朋友可以参考下 很多时候, ...
- linux下补丁制作及打补丁实例【转】
转自:http://www.latelee.org/using-gnu-linux/diff-and-patch-on-linux.html 搞ARM有一段时日了,期间看了不少开发板的手册,手册的内容 ...
- python 根据输入的内容输出类型
类型判断 from functools import singledispatch import numbers from collections import abc from collection ...
- React-Native 之 常用组件Image使用
前言 学习本系列内容需要具备一定 HTML 开发基础,没有基础的朋友可以先转至 HTML快速入门(一) 学习 本人接触 React Native 时间并不是特别长,所以对其中的内容和性质了解可能会有所 ...
- DevExpress GridControl 的数据绑定
本人不才啊,折腾2个多小时才把数据绑定好.现在把折腾过程记录一下来以帮助更多的朋友,自己也温习一下. 直接上代码了哈.... WPF哈 xaml文件 <dxg:GridControl Name= ...
- Flask: Quickstart解读
Windows 10家庭中文版,Python 3.6.4,Flask 1.0.2 从示例代码说起: from flask import Flask app = Flask(__name__) @app ...
- Nginx - upstream 模块及参数测试
目录 - 1. 前言- 2. 配置示例及指令说明 - 2.1 配置示例 - 2.2 指令 - 2.3 upstream相关变量- 3. 参数配置及测试 - 3.1 max_fa ...
- Luogu P2069 【松鼠吃果子】
推荐一波数组模拟链表的讲解 这道题呢,数组写的话不好删除(因为后面要接过来),自然想到链表 对于一个果子,我们可以维护其前驱和后继,我们不妨记与一个点相邻的上面的点为其前驱,下面的点为其后继 观察到题 ...
- Django配置https协议
本博客来自https://blog.csdn.net/huplion/article/details/52892901 1.首先我们需要得到一张证书文件 参考:WINDOWS系统下创建自签名SSL证书 ...
- 20165333实验一 JAVA开发环境的熟悉
JAVA开发环境的熟悉-1 1建立"自己学号exp1"的目录 2 在"自己学号exp1"目录下建立src,bin等目录 3 javac,java的执行在&quo ...