Skip to content

Commit

Permalink
Bing search
Browse files Browse the repository at this point in the history
  • Loading branch information
bleroy committed Nov 8, 2011
1 parent 7d5fd4b commit 6113586
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
36 changes: 36 additions & 0 deletions Search.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@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 results = XElement.Load(response);
}
<ul id="SearchResultsDiv">
@foreach(var result in results.Element(web + "Web").Element(web + "Results").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>
8 changes: 8 additions & 0 deletions Styles/Site.css
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,14 @@ img.thumb {
min-height: 80px;
}

#SearchResultsDiv header {
font-size: 0.8em;
}

#SearchResultsDiv li {
list-style: none;
}

/* Search page end */

#siteInfo {
Expand Down
4 changes: 4 additions & 0 deletions Web.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="bingAppId" value="Please put your Bing app id here"/>
</appSettings>
<system.web>
<compilation targetFramework="4.0"/>
<customErrors mode="RemoteOnly"/>
</system.web>
<system.webServer>
<defaultDocument>
Expand Down
4 changes: 3 additions & 1 deletion _SiteLayout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
<div id="SidebarHeaderDiv">
</div>
<div id="SidebarContentDiv">
<input class="txtsearchbox" type="text" name="q"/><big><a href="#" id="search">&raquo;</a></big><br/>
<form action="Search.cshtml" method="GET">
<input class="txtsearchbox" type="text" name="q"/><big><a href="#" id="search">&raquo;</a></big><br/>
</form>
</div>
<nav class="TocContainer"><ol></ol></nav>
<div id="SidebarFooterDiv">
Expand Down

0 comments on commit 6113586

Please sign in to comment.