forked from OrchardCMS/OrchardDoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BingSearch.cshtml
42 lines (41 loc) · 1.79 KB
/
BingSearch.cshtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@using System.Configuration
@using System.Xml.Linq
@{
const int pageSize = 10;
XNamespace web = "http://schemas.microsoft.com/LiveSearch/2008/04/XML/web";
var appid = ConfigurationManager.AppSettings["bingAppId"];
var pageNumber = int.Parse(Request.QueryString["p"] ?? "0");
var q = Request.QueryString["q"] ?? "";
Page.Title = "Orchard Documentation - Search - " + q;
var requestString = "http://api.bing.net/xml.aspx?"
+ "AppId=" + appid
+ "&Query=" + Html.Encode(q) + "%20site:docs.orchardproject.net"
+ "&Sources=Web"
+ "&Version=2.0"
+ "&Market=en-us"
+ "&Adult=Moderate"
+ "&Options=EnableHighlighting"
+ "&Web.Count=" + pageSize
+ "&Web.Offset=" + (pageNumber*pageSize)
+ "&Web.Options=DisableHostCollapsing+DisableQueryAlterations";
var request = (HttpWebRequest) WebRequest.Create(requestString);
var response = request.GetResponse().GetResponseStream();
var webElement = XElement.Load(response).Element(web + "Web");
if (webElement != null) {
var resultSet = webElement.Element(web + "Results");
if (resultSet != null) {
<ul id="SearchResultsDiv">
@foreach (var result in resultSet.Elements(web + "WebResult")) {
<li>
<article>
<header>
<h2><a href="@result.Element(web + "Url").Value">@result.Element(web + "Title").Value</a></h2>
</header>
<p>@result.Element(web + "Description").Value</p>
</article>
</li>
}
</ul>
}
}
}