views:

36

answers:

2

Does Bing has an option similar to Google Custom Search or Yahoo where I can use Bing to power the search results on my site?

Couple requirements:

  • Works with an ASP.NET site (is a .NET project)
  • Host the search box and results on my own website
  • Ability to customize the look and feel of the results to match my site (Full control is ideal but I understand it's not possible with free solutions)

I did a search for Bing custom search and found this: http://www.bing.com/siteowner/ but it's not exactly what I am looking for.

+1  A: 

You can sign up for site search and query Bing via jsonp and display results via javascript (exact code untested)

 function searchDone(results) {
    if(results.SearchResponse.Web.Results && results.SearchResponse.Web.Results.length > 0) {
       for (var i = 0; i < results.SearchResponse.Web.Results.length; i++) {
            result = results.SearchResponse.Web.Results[i];
            item = document.createElement('li');
            item.innerHTML = '<a href="' + result.Url + '">' + AntiXssLibrary.HtmlEncode(result.Title.replace(/\uE000/g, "").replace(/\uE001/g, "")) + '</a>' + '<blockquote>' + AntiXssLibrary.HtmlEncode(result.Description.replace(/\uE000/g, "").replace(/\uE001/g, "")) + '</blockquote>';
            // append child to document somewhere
        }
    }
 }



 var serviceURI = "http://api.search.live.net/json.aspx?JsonType=callback&amp;JsonCallback=searchDone&amp;sources=web&amp;Options=EnableHighlighting";
 var appid = "&Appid=YOUR_BING_APP_ID";      
 var query = "&query=site:http://YOURDOMAIN.com/ <%=Request.Querystring["query"] %>";

 var fullUri = serviceURI + appid + query;
 var head = document.getElementsByTagName('head');
 var script = document.createElement('script');
 script.type = "text/javascript";
 script.src = fullUri;
 head[0].appendChild(script);
BC
+1  A: 

The query string Bing uses is:

http://www.bing.com/search?q=&amp;src=IE-SearchBox&amp;FORM=IE8SRC

(this is the template URL from the Bing search provider in IE). All you have to do is insert your search terms after the q parameter. A good way to test this is to actually execute a search and see the url in the address box of the browser:

http://www.bing.com/search?q=how+to+query+bing&amp;src=IE-SearchBox&amp;FORM=IE8SRC

you can drop the src and FORM parameters, Bing will just be using those for statistical purposes.

To get the results to appear in your own page, use an iframe, give it an id, and sets its src url (using javascript) to the search url you have constructed.

var frame = document.getElementById('mySearchFrame');
if (frame != null)
    frame.src = 'http://www.bing.com/search?q=' + mySearchTerms;

Note that if you want to style the page then you will have to query Bing from code behind and "scrape" the results and place them into your own page. (Or you could just send the page back but modify the contents of it before doing so, but to do this will be violating Bing's terms of use - MS supply Bing for you to use for free, but it is on their terms, which means you will not be able to delete any advertising or change the look and feel of the page - there are no free rides in this world :).

slugster