Last active
October 5, 2017 19:02
-
-
Save kgiszewski/df4d374896234e5e3a93e2cdc4e1ae23 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="main" class="search-page"> | |
<section class="container"> | |
<h2>Showing @pagedResultList.TotalItemCount result(s) for keywords "@keywords":</h2> | |
<ol> | |
@foreach (var result in pagedResultList) | |
{ | |
var umbracoContent = Umbraco.TypedContent(result.Id); | |
<li> | |
<h3> | |
<a href="@umbracoContent.Url">@umbracoContent.Name</a> | |
</h3> | |
<small>@umbracoContent.Url</small> | |
</li> | |
} | |
</ol> | |
</section> | |
<section class="container"> | |
@Html.PagedListPager(pagedResultList, page => ("?q=" + keywords + "&p=" + page)) | |
</section> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var keywords = HttpContext.Current.Request.QueryString["q"]; | |
if (string.IsNullOrEmpty(keywords)) | |
{ | |
Response.Redirect("/"); | |
return; | |
} | |
var searcher = new SearchHelper(new SearchOnlyOwnSiteContentNoMediaStrategy()); | |
var results = searcher.Search(keywords).OrderByDescending(x => x.Score); | |
//use 'p' query string as the page number | |
var pageQueryString = HttpContext.Current.Request.QueryString["p"]; | |
var pageNumber = 1; | |
if (pageQueryString != null) | |
{ | |
pageNumber = Convert.ToInt32(pageQueryString); | |
} | |
var pagedResultList = results.ToPagedList(pageNumber, 10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment