From d882f5ba061ba598d12abc5ee19d58cd07fe477e Mon Sep 17 00:00:00 2001 From: Bertrand Le Roy Date: Tue, 29 Nov 2011 21:26:55 -0800 Subject: [PATCH] More repairs --- Search.cshtml | 51 ++++++++++++++++--------------------- Styles/Site.css | 25 ++++++++++++++++++ _AppStart.cshtml | 63 +++++++--------------------------------------- _SiteLayout.cshtml | 15 +++++++---- 4 files changed, 66 insertions(+), 88 deletions(-) diff --git a/Search.cshtml b/Search.cshtml index 71286e8f..c250e362 100644 --- a/Search.cshtml +++ b/Search.cshtml @@ -1,42 +1,35 @@ -@using System.Configuration -@using System.Xml.Linq +@using App_Code @{ - 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"] ?? ""; + var q = Request.QueryString["q"]; + var page = int.Parse(Request.QueryString["p"] ?? "1"); 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) { + var resultSet = SearchHelpers.Query(HttpContext.Current, q, page); + var documents = resultSet.Documents; + if (resultSet.TotalCount == 0) { + @:No results found. + } + else { +
@resultSet.TotalCount @(resultSet.TotalCount > 1 ? "documents" : "document") found.
- } + if (resultSet.TotalCount > SearchHelpers.PageSize) { + int pages = (resultSet.TotalCount / SearchHelpers.PageSize) + 1; + + } } } \ No newline at end of file diff --git a/Styles/Site.css b/Styles/Site.css index 82994793..f7e6e8d3 100644 --- a/Styles/Site.css +++ b/Styles/Site.css @@ -369,6 +369,14 @@ html>body #ContainerDiv {height: auto;} background:url(Images/background_module.gif) no-repeat bottom right; } +#SidebarDiv h2 { + margin-top: 6px; +} + +#SidebarDiv div { + margin-bottom: 19px; +} + /* Contains the contents of a Page */ #MainDiv { padding:12px 10px 10px 22px; @@ -1089,6 +1097,23 @@ img.thumb { list-style: none; } +.searchPagination { + margin-top: 20px; +} + +.searchPagination li { + list-style: none; + display: inline; +} + +.searchButton { + border: none; + background: transparent; + font-size: 1.4em; + color: #006699; + cursor: pointer; +} + /* Search page end */ #siteInfo { diff --git a/_AppStart.cshtml b/_AppStart.cshtml index 6b063c43..0d286fc5 100644 --- a/_AppStart.cshtml +++ b/_AppStart.cshtml @@ -1,57 +1,12 @@ -@using MarkdownWebPages -@using System.Text.RegularExpressions - -@functions { - string ProcessIncludes(string content, MarkdownWebPage page) { - return Regex.Replace(content, @"^@include\((?~/.*?)\)", match => MarkdownWebPage.RenderFile(match.Groups["include"].Value, page), RegexOptions.Multiline); - } - - string ProcessComments(string content, MarkdownWebPage page) { - return Regex.Replace(content, @"^//(.*?)$", match => String.Empty, RegexOptions.Multiline); - } - - // First Header | Second Header - // ------------- | ------------- - // Content Cell | Content Cell - // Content Cell | Content Cell - string ProcessTables(string content, MarkdownWebPage page) { - return Regex.Replace(content, - @"\r\n(\s*(.*?)\s+\|)+\s+(.*?)\s*" + - @"\r\n(\s*(-+?)\s+\|)+\s+(-+?)\s*" + - @"\r\n((\s*(.*?)\s+\|)+\s+(.*?)\s*\r\n)+", - match => { - var writer = new StringWriter(); - writer.WriteLine(""); - foreach (Capture header in match.Groups[1].Captures) { - writer.WriteLine(" "); - } - writer.WriteLine(" "); - writer.WriteLine(""); - var rows = match.Groups[7].Captures; - var cells = match.Groups[9].Captures; - var colCount = cells.Count/rows.Count; - var i = 0; - foreach (Capture row in rows) { - writer.WriteLine(" "); - for (var j = 0; j < colCount; j++ ) { - writer.WriteLine(" "); - } - writer.WriteLine(" "); - writer.WriteLine(" "); - } - writer.WriteLine("
" + header.Value.Substring(0, header.Length - 1).Trim() + "" + match.Groups[3].Value.Trim() + "
" + cells[colCount * i + j] + "" + match.Groups[10].Captures[i++] + "
"); - return writer.ToString(); - } - , RegexOptions.Multiline); - } -} - +@using App_Code +@using MarkdownWebPages @{ MarkdownWebPage.TransformUrls = true; MarkdownWebPage.AlterBehaviors(b => b.Clear()); - MarkdownWebPage.AlterBehaviors(b => b.Add(ProcessIncludes)); - MarkdownWebPage.AlterBehaviors(b => b.Add(ProcessComments)); - MarkdownWebPage.AlterBehaviors(b => b.Add(ProcessTables)); -} - - + MarkdownWebPage.AlterBehaviors(b => b.Add(MarkdownExtensions.ProcessIncludes)); + MarkdownWebPage.AlterBehaviors(b => b.Add(MarkdownExtensions.ProcessComments)); + MarkdownWebPage.AlterBehaviors(b => b.Add(MarkdownExtensions.ProcessTables)); + + // Index the whole documentation on app start + SearchHelpers.BuildIndex(HttpContext.Current); +} \ No newline at end of file diff --git a/_SiteLayout.cshtml b/_SiteLayout.cshtml index a6b3bd11..aa60dd21 100644 --- a/_SiteLayout.cshtml +++ b/_SiteLayout.cshtml @@ -1,4 +1,7 @@ - +@{ + var isDoc = Request.FilePath.IndexOf("/Documentation/") != -1; +} + @@ -37,17 +40,19 @@
-
-
-
- »
+

Search

+ +
+ @if (isDoc) { +

Table of Contents

+ }