200 lines
8.1 KiB
Plaintext
200 lines
8.1 KiB
Plaintext
@using Examine.SearchCriteria
|
|
@using OurUmbraco.Our
|
|
@using OurUmbraco.Our.Examine
|
|
@inherits Umbraco.Web.Macros.PartialViewMacroPage
|
|
@{
|
|
const int pagesToShowLeft = 4;
|
|
const int pagesToShowRight = 2;
|
|
var orderMode = !string.IsNullOrEmpty(Request["orderBy"]) ? Request["orderBy"] : "createDate";
|
|
var page = !string.IsNullOrEmpty(Request["page"]) ? int.Parse(Request["page"]) : 1;
|
|
var category = Request["category"];
|
|
var version = Request["version"];
|
|
var term = Request["term"];
|
|
var pageSize = 20;
|
|
var headline = orderMode == "createDate" ? "latest" : "most popular";
|
|
if (version != null)
|
|
{
|
|
headline = "version " + version;
|
|
}
|
|
if (category != null)
|
|
{
|
|
headline = category.ToLowerInvariant();
|
|
}
|
|
|
|
var filters = new List<SearchFilters>();
|
|
if (!string.IsNullOrEmpty(category))
|
|
{
|
|
var categoryFilters = new SearchFilters(BooleanOperation.Or);
|
|
//NOTE: We could add multiple category searches here if we wanted to match on multiple,
|
|
// you'd need to split the 'category' query string into each category and add a filter per item
|
|
// since it is an "OR" clause above it will match any of the categories
|
|
//NOTE: categories are indexed as lower case and are not tokenized so must be an exact match and therefore
|
|
// require quotes
|
|
categoryFilters.Filters.Add(new SearchFilter("categoryFolder", string.Format("\"{0}\"", category.ToLowerInvariant().Trim())));
|
|
filters.Add(categoryFilters);
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(version))
|
|
{
|
|
var versionFilters = new SearchFilters(BooleanOperation.Or);
|
|
//NOTE: We could add multiple version searches here if we wanted to match on multiple,
|
|
// you'd need to split the 'version' query string into each version and add a filter per item
|
|
// since it is an "OR" clause above it will match any of the versions, if however you wanted to filter
|
|
// to only match projects that are tagged for the inclusive versions, you'd change the Boolean op to AND.
|
|
//NOTE: We are doing a *wildcard* search here because versions are stored as comma delimited values in the index
|
|
// when I release the next version of Examine this will be different since we'll store each version separately in the same version
|
|
// field which will be nicer to query.
|
|
versionFilters.Filters.Add(new SearchFilter("versions", string.Format("{0}.*", version.Trim())));
|
|
filters.Add(versionFilters);
|
|
}
|
|
|
|
var searcher = new OurSearcher(term, "project", orderMode, filters: filters, maxResults: pageSize * page);
|
|
|
|
var search = searcher.Search();
|
|
var total = search.SearchResults.TotalItemCount;
|
|
var pages = (total / pageSize) + 1;
|
|
|
|
var url = string.Format("orderBy={0}&q={1}&version={2}&category={3}", orderMode, term, version, category);
|
|
var result = search.SearchResults.Skip((page - 1) * pageSize).Take(pageSize);
|
|
}
|
|
@if (Context.IsDebuggingEnabled)
|
|
{
|
|
<p style="border: 1px solid orange;">
|
|
<strong>Debugging output</strong><br />
|
|
<strong>Query:</strong> @search.LuceneQuery<br />
|
|
<strong>Order by:</strong> @search.OrderBy<br />
|
|
<strong>Time elapsed:</strong> @search.Totalmilliseconds<br />
|
|
<strong>Total results:</strong> @total<br />
|
|
<strong>Pages:</strong> @pages
|
|
</p>
|
|
}
|
|
<div class="search-big">
|
|
<input type="search" class="project-search-input" required placeholder="Search for projects">
|
|
<label for="search">Search projects</label>
|
|
</div>
|
|
@functions{
|
|
public string GetField(IDictionary<string, string> fields, string field, string defaultVal = "")
|
|
{
|
|
if (fields != null && fields.ContainsKey(field))
|
|
return fields[field];
|
|
|
|
return defaultVal;
|
|
}
|
|
|
|
public string ParseVersion(string version)
|
|
{
|
|
if (string.IsNullOrEmpty(version))
|
|
return "n/a";
|
|
|
|
var versions = version.Trim(',').Split(',').Select(decimal.Parse).ToArray();
|
|
|
|
if (!versions.Any())
|
|
return "n/a";
|
|
|
|
if (versions.Count() == 1)
|
|
return (versions.First()) + "+";
|
|
|
|
var high = versions.Max();
|
|
var low = versions.Min();
|
|
|
|
return high.ToString("N2") + "-" + low.ToString("N2");
|
|
}
|
|
}
|
|
<h1>Browse @headline projects</h1>
|
|
<script type="text/template" class="search-item-project">
|
|
<div class="box">
|
|
<div class="row">
|
|
<div class="col-xs-2 col-md-1">
|
|
<img src="{{image}}" alt="">
|
|
</div>
|
|
<div class="col-xs-10 col-md-6">
|
|
<div class="forum-thread-text">
|
|
<h3><a href="{{url}}">{{nodeName}}</a></h3>
|
|
<p>{{body}}</p>
|
|
</div>
|
|
</div>
|
|
<div class="col-xs-12 col-md-5">
|
|
<div class="other">
|
|
<div class="package-badge">
|
|
<span class="package-name">version</span>
|
|
<span class="package-number">{{versions}}</span>
|
|
</div>
|
|
<span class="stats">
|
|
<span class="downloads">
|
|
{{downloads}}<span><i class="icon-Download-alt"></i></span>
|
|
</span>
|
|
<span class="karma">
|
|
{{karma}}<span><i class="icon-Hearts"></i></span>
|
|
</span>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</script>
|
|
<div class="projects-search-listing"></div>
|
|
<div class="projects-default-listing">
|
|
@foreach (var childPage in result)
|
|
{
|
|
var childContent = Umbraco.TypedContent(childPage.Id);
|
|
if (childContent != null)
|
|
{
|
|
<div class="box">
|
|
<div class="row">
|
|
<div class="col-xs-2 col-md-1">
|
|
@{
|
|
var defaultScreenshot = "/css/img/package2.png";
|
|
if (childContent != null)
|
|
{
|
|
defaultScreenshot = childContent.GetPropertyValue<string>("defaultScreenshotPath");
|
|
}
|
|
}
|
|
<img src="@Utils.GetScreenshotPath(defaultScreenshot)?width=50&height=50&bgcolor=fff" />
|
|
</div>
|
|
<div class="col-xs-10 col-md-6">
|
|
<div class="forum-thread-text">
|
|
<h3>
|
|
<a href="@childContent.Url">@childContent.Name</a>
|
|
</h3>
|
|
<p>@Html.Raw(GetField(childPage.Fields, "body", "No description available").StripHtml().Truncate(150))</p>
|
|
</div>
|
|
</div>
|
|
<div class="col-xs-12 col-md-5">
|
|
|
|
<div class="other">
|
|
<div class="package-badge">
|
|
<span class="package-name">version</span>
|
|
<span class="package-number">@ParseVersion(GetField(childPage.Fields, "versions"))</span>
|
|
</div>
|
|
<span class="stats">
|
|
<span class="downloads">
|
|
@GetField(childPage.Fields, "downloads", "0")<span><i class="icon-Download-alt"></i></span>
|
|
</span>
|
|
<span class="karma">
|
|
@GetField(childPage.Fields, "karma", "0")<span><i class="icon-Hearts"></i></span>
|
|
</span>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|
|
<nav class="pagination" role="navigation">
|
|
@if (page > 1)
|
|
{
|
|
<a class="prev" href="?page=@(page - 1)&@url">Prev</a>
|
|
}
|
|
|
|
@for (var i = (page - 1 > 0 ? page - 1 : 1); i < (page + (pagesToShowLeft - (page - 1 > 0 ? 1 : 0))) && i <= pages; i++)
|
|
{
|
|
<a class="@Umbraco.If(i == page, "active")" href="?page=@i&@url">@i</a>
|
|
}
|
|
|
|
@if (page < pages)
|
|
{
|
|
<span>…</span>
|
|
<a class="next" href="?page=@(page + 1)&@url">Next</a>
|
|
}
|
|
</nav>
|
|
</div> |