如何使用 Bing 作为我网站上的搜索引擎?

发布于 2024-09-09 07:57:14 字数 368 浏览 8 评论 0原文

Bing 是否有类似于 Google 自定义搜索或 Yahoo 的选项,我可以使用 Bing 为我的网站上的搜索结果提供支持?

几个要求:

  • 与 ASP.NET 站点一起使用(是一个 .NET 项目)
  • 在我自己的网站上托管搜索框和结果
  • 能够自定义结果的外观和风格以匹配我的站点(完全控制是理想的选择,但我理解它是免费解决方案不可能)

我搜索了 Bing 自定义搜索,发现了这个: http://www.bing .com/siteowner/ 但这并不完全是我正在寻找的。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千里故人稀 2024-09-16 07:57:14

Bing 使用的查询字符串是:(

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

这是 IE 中 Bing 搜索提供程序的模板 URL)。您所要做的就是在 q 参数后面插入搜索词。测试这一点的一个好方法是实际执行搜索并在浏览器地址框中查看 url:

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

您可以删除 srcFORM 参数,Bing 只会将它们用于统计目的。

要使结果显示在您自己的页面中,请使用 iframe,为其指定 id,并将其 src url(使用 javascript)设置为您构建的搜索 url。

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

请注意,如果您想设置页面样式,则必须从代码隐藏中查询 Bing 并“抓取”结果并将其放入您自己的页面中。 (或者您可以将页面发回,但在此之前修改其内容,但这样做将违反 Bing 的使用条款 - MS 提供 Bing 供您免费使用,但这是按照他们的条款进行的,这意味着您将无法删除任何广告或更改页面的外观和感觉 - 这个世界上没有免费的乘车:)。

The query string Bing uses is:

http://www.bing.com/search?q=&src=IE-SearchBox&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&src=IE-SearchBox&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 :).

牛↙奶布丁 2024-09-16 07:57:14

您可以注册网站搜索并通过 jsonp 查询 Bing 并通过 javascript 显示结果(确切代码未经测试)

 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&JsonCallback=searchDone&sources=web&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);

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&JsonCallback=searchDone&sources=web&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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文