您的位置:首页 > 其它

利用Bing API开发的搜索工具(MVC+WCF)

2011-11-27 23:16 381 查看
Bing是微软公司的一款搜索引擎,跟一般的搜索引擎一样提供一些常规的搜索功能,至于是否足够强大,那就得看用户的实际需求了。像其他搜索引擎一下,bing也为开发者提供了调用搜索服务的api,鼓励开发人员进行一些第三方的搜索工具的开发,详情可登陆http://www.bing.com/toolbox/bingdeveloper/了解。codeproject最近有一篇文章介绍了如何使用bing 的api去开发简单的搜索客户端,今天自己也鼓捣了一下,做了个简单的搜索工具,是基于wcf和mvc开发的。先看看基本的成果:

基本搜索界面,支持网页、新闻和图片、视频搜索

View Code

SearchRequest request = new SearchRequest();
request.AppId = WebConfigurationManager.AppSettings["BingSearchAppId"];//applicationID
request.Query = q;//查询关键字
request.Version = "2.0";
request.Market = "zh-cn";//语言
request.Sources = new SourceType[] { sourceType.Value };//查询类型
SearchResponse response = null;

using (var client = new BingPortTypeClient())
{
try
{
response = client.Search(request);
}
catch (Exception ex)
{
ViewData["message"] = "搜索失败";
}
}
bing搜索支持的类型列表(从网上拷贝的,基本就是那个意思,搜索PHONEBOOK可理解为搜索黄页,示例中有个这个功能)

SourceTypeDescription
WEB
This sourcetype searches the query string and gets you the list of avalable crawn result based on its inbuilt automation ranking algorithm. This represents the basic search algorithm for Bing Services
IMAGE
Returns the list of images relevant to the query.
VIDEO
Returns List of video result for the searched query
AD
Returns Advertisement links relevant to the query
NEWS
News based entries for the current query based on location passed if any.
RELATEDSEARCH
A unique feature that enables the Bing service to automatically determine the searches that are relevant to the current searches and display the result.
SPELL
Spell Feature enables to automaticaly determine correct spellings of the word passed in the query from its database.
TRANSLATE
It translates three sentences or less passed to the bing service from one language to another based on specified Target Language ID.
INSTANTANSWER
This is another unique feature to enable you to get Instant answers from your current query. It gives authoratitive answers to your questions
PHONEBOOK
Just on your imagination, it searches phone numbers. This is another great feature of Bing Services.
MOBILEWEB
Returns shrink output for mobile browsers.
5、搜索得到的结果集合也很直接明了,按照自己的需求可自由定制结果的显示方式,感觉这种方式用MVC来做最适合不过了。接下来就都是页面展示的组合,没有什么好值得详细描述的了。

具体源代码请下载 BingSearchWebSite

  做的比较简单,主要是体验一下,还可以继续的优化。不过调用API搜索还是有些优势,可能是没有监控那么严的原因,得到结果的尺度比较的宽,一些所谓的敏感内容也能搜索得到,特别是将请求的Market改成"en-us"之后,自由多了,但连接还是打不开的,顶多让你看个缓存页面。

参考:

http://www.codeproject.com/KB/cs/BingSearch.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: