利用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可理解为搜索黄页,示例中有个这个功能)
5、搜索得到的结果集合也很直接明了,按照自己的需求可自由定制结果的显示方式,感觉这种方式用MVC来做最适合不过了。接下来就都是页面展示的组合,没有什么好值得详细描述的了。
具体源代码请下载 BingSearchWebSite
做的比较简单,主要是体验一下,还可以继续的优化。不过调用API搜索还是有些优势,可能是没有监控那么严的原因,得到结果的尺度比较的宽,一些所谓的敏感内容也能搜索得到,特别是将请求的Market改成"en-us"之后,自由多了,但连接还是打不开的,顶多让你看个缓存页面。
参考:
http://www.codeproject.com/KB/cs/BingSearch.aspx
基本搜索界面,支持网页、新闻和图片、视频搜索
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可理解为搜索黄页,示例中有个这个功能)
SourceType | Description |
---|---|
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. |
具体源代码请下载 BingSearchWebSite
做的比较简单,主要是体验一下,还可以继续的优化。不过调用API搜索还是有些优势,可能是没有监控那么严的原因,得到结果的尺度比较的宽,一些所谓的敏感内容也能搜索得到,特别是将请求的Market改成"en-us"之后,自由多了,但连接还是打不开的,顶多让你看个缓存页面。
参考:
http://www.codeproject.com/KB/cs/BingSearch.aspx
相关文章推荐
- 利用Bing Search API进行搜索
- 安卓开发笔记①:利用高德地图API进行定位、开发电子围栏、天气预报、轨迹记录、搜索周边(位置)
- 利用bing图片搜索接口开发图片搜索应用程序
- 安卓开发笔记①:利用高德地图API进行定位、开发电子围栏、天气预报、轨迹记录、搜索周边(位置)
- Android 利用高德地图API进行定位、开发电子围栏、天气预报、轨迹记录、搜索周边(位置)
- 安卓开发笔记①:利用高德地图API进行定位、开发电子围栏、天气预报、轨迹记录、搜索周边(位置)
- 利用Yahoo! Search API开发自已的搜索引擎-php版
- java连接oracle数据库(利用MyEclipse开发工具反向生成 bean与配置文件)
- 开发者如何利用工具快速开发出完美APP
- 利用ASP.NET MVC+EasyUI+SqlServer搭建企业开发框架
- 利用c#开发一个telnet unix服务器或者防火墙的小工具(转)
- ANDROID 开发常用的框架、工具、API最全集合
- JavaSE学习总结第11天_开发工具 & API常用对象1
- 移动端开发-各类免费收费api及网站工具收藏
- 如何利用 Visual Studio 自带工具提高开发效率
- WordPress开发中常用的工具或api文档
- 【前端开发】利用Fiddler抓包工具进行本地调试
- 利用微软翻译API做自己的翻译的工具(java)
- 利用winpcap/libnet开发EAPOL-START/LOGOFF攻击测试工具
- 微信“跳一跳”辅助工具——利用Python开发