<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>阅微堂 &#187; PHP</title>
	<atom:link href="http://zhiqiang.org/blog/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://zhiqiang.org/blog</link>
	<description>数学、金融、计算机</description>
	<lastBuildDate>Wed, 23 May 2012 08:37:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Google Web API打造站内搜索</title>
		<link>http://zhiqiang.org/blog/it/google-web-search-api-build-station.html</link>
		<comments>http://zhiqiang.org/blog/it/google-web-search-api-build-station.html#comments</comments>
		<pubDate>Tue, 05 Sep 2006 02:07:10 +0000</pubDate>
		<dc:creator>zhiqiang</dc:creator>
				<category><![CDATA[IT技术]]></category>
		<category><![CDATA[Google Web API]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[搜索]]></category>

		<guid isPermaLink="false">http://zhiqiang.org/blog/436.html</guid>
		<description><![CDATA[博客 » IT技术 » Google Web API，PHP，搜索 » WordPress自带了站内搜索，可是搜索结果很不令人满意。它的搜索是通过MYSQL查询得来的，所以首先它无法分词和切词，对于中文搜索效果尤其差。其次它无法在搜索结果中高亮度和重点显示搜索关键词相关内容，而是显示一堆乱七八糟的东西。但用上Google Web API构建的站内搜索后，一切都迎刃而解。 利用Google Web API，可以将搜索内容发...]]></description>
			<content:encoded><![CDATA[<p id="breadcrumb" class="breadcrumb"><a href="http://zhiqiang.org/blog/">博客</a> » <a href="http://zhiqiang.org/blog/category/it">IT技术</a> » <a href="http://zhiqiang.org/blog/tag/google-web-api" rel="tag">Google Web API</a>，<a href="http://zhiqiang.org/blog/tag/php" rel="tag">PHP</a>，<a href="http://zhiqiang.org/blog/tag/%e6%90%9c%e7%b4%a2" rel="tag">搜索</a> » </p><p>WordPress自带了站内搜索，可是搜索结果很不令人满意。它的搜索是通过<a href="http://www.mysql.com">MYSQL</a>查询得来的，所以首先它无法分词和切词，对于中文搜索效果尤其差。其次它无法在搜索结果中高亮度和重点显示搜索关键词相关内容，而是显示一堆乱七八糟的东西。但用上Google Web API构建的站内搜索后，一切都迎刃而解。</p>
<p><center><br />
<form action="http://zhiqiang.org/blog/search.php" method="get">
<input id="q" size="30" name="q" type="text" />
<input type="submit" value="Search" /> </form>
<p></center>利用<a href="http://code.google.com/" target="_blank">Google Web API</a>，可以将搜索内容发送到<a href="http://www.google.com.hk/">Google</a>，再处理Google返回的搜索结果，最后显示在自己的页面上，如下图所示：</p>
<p align="center"><a title="Photo Sharing" href="http://www.flickr.com/photos/mathzqy/234477793/"><img height="394" alt="google" src="http://farm1.static.flickr.com/97/234477793_d04c9828af.jpg" width="497" /></a></p>
<p>Google Web API的功能不限于搜索，它还可以读Google Cache，单词纠错等。不过我目前只用了它的搜索功能。主要参考了<a href="http://goood.org" target="_blank">通过php调用Google API</a>和Google Web API: PHP implementation这两篇文章。PHP的SOAP类下载于<a href="http://pear.php.net/" target="_blank">PEAR</a>。另外鄙视一下PEAR上的文档结构，包里面的文件都不全，每下载一个文件，运行就告诉我还缺少另一个补充文件。最后我只好去搜索关键词，一个文件一个文件把它们补齐。这种工作对我这种业余人士太耗费时间了。</p>
<p>网络的乐趣在于共享，所以提供<a href="http://sites.google.com/site/mathzqy/GoogleAPI.zip">下载</a>。下载后放在blog的根目录下。search.php的前几行可能需要重新配置:</p>
<blockquote>
<pre>$num = 10; <span style="color: #008000">// 每次查询显示的结果数量</span>
$<span style="color: #ffa500">key</span> = '<span style="color: #8b0000">Enter your google license key</span>';  <span style="color: #008000">// Google API key，去<a href="http://code.google.com/">http://www.google.com/apis/</a>申请</span>
$navi_num = 7; <span style="color: #008000">// 导航页面的页面数量</span></pre>
</blockquote>
<div><h4>相关文章</h4><ul><li class='currentpost'><a href="http://zhiqiang.org/blog/it/google-web-search-api-build-station.html">Google Web API打造站内搜索</a></li><li ><a href="http://zhiqiang.org/blog/science/computer-science/how-google-search-similar-images.html">图片搜索的原理</a></li></ul></div>    <p></p>
    <hr noshade style="margin:0;height:1px" />
    <p>&copy; zhiqiang for <a href="http://zhiqiang.org/blog">阅微堂</a>, 2006. | <a href="http://zhiqiang.org/blog/it/google-web-search-api-build-station.html">&#38142;&#25509;</a> | <a href="http://zhiqiang.org/blog/it/google-web-search-api-build-station.html#comments">23 &#26465;&#35780;&#35770;</a></p>]]></content:encoded>
			<wfw:commentRss>http://zhiqiang.org/blog/it/google-web-search-api-build-station.html/feed</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
	</channel>
</rss>

