这已经不是什么新话题,但是对于我是刚刚接触,所以拿出与人分享,如果你和我一样以前没有涉及过这方面的知识,希望它能起到抛砖引玉的作用。
可以说google绝对是我的良师益友,所以我比较关注他的技术,在建设个人网站过程中,需要为站点添加搜索引擎,我觉得没有搜索功能的网站就象缺少了双腿。
我对于搜索知识还很贫乏
一般可以使用fso对站点内物理文件进行处理,来找到复合条件的内容。对于保存于数据库内的文章,可以使用数据库引擎搜索数据库,找到满足条件的数据。
但是其实还有一个更简单方便的办法,就是使用google的强大搜索引擎,你可以用它实现本站内搜索,互联网搜索,大部分的做法是在本站添加一个入口,然后转到google网站。
我现在说的是使用google 的WEB API,完成在本站内搜索,因为Google WEB API符合SOAP和WSDL标准,它使用XML的方式返回结果,因此你可以自定义返回的结果显示方式,也可以方便的存储这些数据。
因为我的网站是asp的,所以我分别用asp和VB实现web service和Desktop application的演示。
Google WEB API主要提供三种服务:
Search,Cache,Spelling。
这里只谈使用SOAP标准调用搜索功能。提示使用doGoogleSearch API非常容易,只要提交一个包含特定内容的XML文件即可,在google WEB API SDK中都有相应的模板.
doGoogleSearch.xml内容
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns
OAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1
oGoogleSearch xmlns:ns1="urn:GoogleSearch"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<key xsi:type="xsd
tring">00000000000000000000000000000000</key>
<q xsi:type="xsd
tring">shrdlu winograd maclisp teletype</q>
<start xsi:type="xsd:int">0</start>
<maxResults xsi:type="xsd:int">10</maxResults>
<filter xsi:type="xsd:boolean">true</filter>
<restrict xsi:type="xsd
tring"></restrict>
<safeSearch xsi:type="xsd:boolean">false</safeSearch>
<lr xsi:type="xsd
tring"></lr>
<ie xsi:type="xsd
tring">latin1</ie>
<oe xsi:type="xsd
tring">latin1</oe>
</ns1
oGoogleSearch>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
下面简要解释每个节点的含义:
key 使用者的license key,google可以通过它了解使用情况,每个key每天最多查询1000次
q 要查找的字符串
start 结果记录中的起始位置,因为多页显示,用它来确定当前页显示的记录范围
maxResults 每页显示的记录数,现在最大值是10
filter 布尔值,过录结果中重复记录的开关。 特定国家和标题开关
restrict 约束搜索的范围
safeSearch 布尔值,是否过滤到成人信息
lr 搜索特定语言范围,比如“搜索所有简体中文网页”:lang_zh-CN
ie和oe是输入输出的语言编码,这个被忽略,默认是UTF-8格式
以上这些就是一次提交所需要的参数。
设定好参数就可以发送到Google的SOAP RPC Router。
之后google会将搜索结果以xml文件的形式返回给调用者。调用者主要相应操作这个xml文件,就得到自己想要的数据。
摘录一段:
下面看一个实际的返回结果例子:
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns
OAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1
oGoogleSearchResponse xmlns:ns1="urn:GoogleSearch" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<return xsi:type="ns1:GoogleSearchResult">
<directoryCategories xmlns:ns2="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:Array" ns2:arrayType="ns1
irectoryCategory[0]">
</directoryCategories>
<documentFiltering xsi:type="xsd:boolean">true</documentFiltering>
<endIndex xsi:type="xsd:int">10</endIndex>
<estimateIsExact xsi:type="xsd:boolean">false</estimateIsExact>
<estimatedTotalResultsCount xsi:type="xsd:int">31</estimatedTotalResultsCount>
<resultElements xmlns:ns3="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns3:Array" ns3:arrayType="ns1:ResultElement[10]">
<item xsi:type="ns1:ResultElement">
<URL xsi:type="xsd
tring">http://msdn.microsoft.com/library/en-us/dncenet/html/choose_api.asp</URL>
<cachedSize xsi:type="xsd
tring">54k</cachedSize>
<directoryCategory xsi:type="ns1
irectoryCategory">
<fullViewableName xsi:type="xsd
tring"></fullViewableName>
<specialEncoding xsi:type="xsd
tring"></specialEncoding>
</directoryCategory>
<directoryTitle xsi:type="xsd
tring"></directoryTitle>
<hostName xsi:type="xsd
tring"></hostName>
<relatedInformationPresent xsi:type="xsd:boolean">true</relatedInformationPresent>
<snippet xsi:type="xsd
tring">Choosing a Windows Embedded <b>API</b>: Win32 vs. the .NET Compact Framework. Written by: Paul Yao, Windows<br> Embedded MVP The Paul Yao Company. <b>...</b> This article focuses on two of these APIs—Win32 and the .NET Compact<br> Framework —to provide details on selecting an <b>API</b> for specific programming tasks. <b>...</b> </snippet>
<summary xsi:type="xsd
tring"></summary>
<title xsi:type="xsd
tring">Choosing a Windows Embedded <b>API</b>: Win32 vs. the .NET Compact <b>...</b></title>
</item>
</resultElements>
<searchComments xsi:type="xsd
tring"></searchComments>
<searchQuery xsi:type="xsd
tring">google site:www.blanksoft.com</searchQuery>
<searchTime xsi:type="xsd
ouble">0.177621</searchTime>
<searchTips xsi:type="xsd
tring"></searchTips>
<startIndex xsi:type="xsd:int">1</startIndex>
</return>
</ns1
oGoogleSearchResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
完整可以看:http://www.blanksoft.com/gosearch/rettext.txt
我只保留了一个item信息(应该是maxResults个或者少于maxResults个)。
下面结束主要的节点含义:
return节:
estimatedTotalResultsCount:收到的总记录数。
searchComments:显示一些注释信息,比如“Google 会搜索所有的查询字词,您不必添加 "AND" 运算符”
searchQuery:查询内容,一般等于你传入的查询字符串,但是并不总是一样。
SearchTime:返回服务器搜索花费的时间
SearchTips:显示一些小技巧
StartIndex:当前返回第一条记录的索引号
EndIndex:当前返回最后一条记录的索引号
Item::返回的结果集合
Item节:
URL:页面地址
CachedSize:在Google的cache的页面大小
Snippet:内容摘录
Title:页面标题
大致常用的差不多就是这么多,ODP内容暂时省略。
查看asp的效果,可以访问:
http://www.blanksoft.com/gosearch/googlesearch.asp
我是仿造google的样子设计,当然可以随便定义成自己喜欢的样子
打印 | 张贴于 2004-05-14 16:38:00 | Tag:暂无标签
留言反馈
CSDN 上都可以申请的!只要是它的注册用户都可以拥有自己的强大功能的BLOG啊!看看我的就知道了1
楼主,你的google代码怎么无法下载了!
你有点让我为难了!一是我对你不熟悉,最主要我说话似乎没什么分量!
真的是十分抱歉!如果我能帮上忙,我一定不会拒绝,但是这件事,我可能帮不上啊!
yangdong1981@tom.com
QQ:32874089
再次感谢。
—— 一个想申请blog的人。