Search Tools developed using Bing API (MVC + WCF)

Source: Internet
Author: User

Bing is a search engine provided by Microsoft. It provides some common search functions like general search engines. As to whether it is powerful enough, it depends on the actual needs of users. Like other search engines, Bing also provides developers with APIs to call the search service and encourages developers to develop third-party search tools. For details, visit http://www.bing.com/toolbox/bing#/to learn more. CodeprojectArticleThis article describes how to use Bing APIs to develop a simple search client. Today, I have made some effort and developed a simple search tool based on WCF and MVC. Let's take a look at the basic results:

Basic Search interface, supporting searching for webpages, news, images, and videos

Search the results page of a web page and use Bing's powerful API to basically achieve common search engine functions

The following describes the basic development steps:

1. First, you need to register an account at Bing's Development Center.

2. Save or record the created applicationid, and then use this ID to call Bing's search service. Bing's search service currently supports the following three methods to call XML, JSON, and soap. I am relatively lazy. The JSON and XML methods are based on clients,CodeIs very inefficient. I chose the soap method. With the powerful client functions of WCF, it is very easy to call the soap service. The following is the soap call procedure (for other methods, refer to bing API ).

3. Use the svcutil tool to generate a service client. The Public Address of the service is http://Api.search.live.net/search.wsdl? Appid = your_appidThe appid is the applicationid generated in the first step. It should be a fully functional proxy class, including the model class and contract class used. Similar to other client types automatically generated by WCF, including a client class, bingporttypeclient is generated here, which contains a method for making search public. As for the configuration file, it is basically OK to generate it using a tool.

4. The next call is very simple. Bing provides easy-to-understand APIs. applictionid, query keyword, and data type to be searched must be provided in request parameters.

View code

Searchrequest request = New Searchrequest ();
Request. appid = webconfigurationmanager. appsettings [ " Bingsearchappid " ]; // Applicationid
Request. query = Q; // query keywords
Request. Version = " 2.0 " ;
Request. Market = " Zh-CN " ; // Language
Request. Sources = New Sourcetype [] {sourcetype. Value}; // query type
Searchresponse response = Null ;

Using ( VaR Client = New Bingporttypeclient ())
{
Try
{
Response = client. Search (request );
}
Catch (Exception ex)
{
Viewdata [ " Message " ] = " Search failed " ;
}
}

List of types supported by Bing search (which is basically the meaning of copying from the Internet. Searching phonebook can be understood as searching Yellow Pages. This function is available in the example)

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.

 

5. The set of search results is also very straightforward. You can customize the display method of the results according to your needs. I feel that this method is best suited to MVC. The next step is the combination of page display. There is nothing worth describing in detail.

DetailsSource codeDownload bingsearchwebsite

 

It is relatively simple to do, mainly to experience and continue optimization. However, Calling API Search still has some advantages. It may be because it is not as strict as monitoring, and the resulting scale is relatively wide. Some so-called sensitive content can also be searched, in particular, after changing the requested market to "En-us", there is more freedom, but the connection still cannot be opened. At most, you can see a cache page.

 

Refer:

Http://www.codeproject.com/KB/cs/BingSearch.aspx

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.