updates main search listing for projects to use updateDate instead of createDate, makes this inline with the results for the back office
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
@using Examine.SearchCriteria
|
||||
@using OurUmbraco.Our
|
||||
@using Umbraco.Core.Cache
|
||||
@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 orderMode = !string.IsNullOrEmpty(Request["orderBy"]) ? Request["orderBy"] : "updateDate";
|
||||
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";
|
||||
var headline = orderMode == "updateDate" ? "latest" : "most popular";
|
||||
if (version != null)
|
||||
{
|
||||
headline = "version " + version;
|
||||
@@ -25,9 +25,6 @@
|
||||
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
|
||||
|
||||
@@ -47,16 +44,15 @@
|
||||
{
|
||||
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())));
|
||||
// you'd need to 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.
|
||||
versionFilters.Filters.Add(new SearchFilter("versions", version.Trim()));
|
||||
filters.Add(versionFilters);
|
||||
}
|
||||
|
||||
//TODO: cache for 1 minute with this key just need to ensure the enumerable in the result is finalized
|
||||
//var key = string.Format("ListProjects.{0}.{1}.{2}.{3}.{4}", page, orderMode, term, version, category);
|
||||
|
||||
var searcher = new OurSearcher(term, "project", orderMode, filters: filters, maxResults: pageSize * page);
|
||||
|
||||
var search = searcher.Search();
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
using System.Linq;
|
||||
using OurUmbraco.MarketPlace.Interfaces;
|
||||
using OurUmbraco.Our;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Web;
|
||||
|
||||
namespace OurUmbraco.MarketPlace.Providers
|
||||
@@ -16,10 +18,29 @@ namespace OurUmbraco.MarketPlace.Providers
|
||||
}
|
||||
|
||||
public IEnumerable<IKarma> GetProjectsKarmaList()
|
||||
{
|
||||
return GetProjectsKarmaList(null);
|
||||
}
|
||||
|
||||
public IEnumerable<IKarma> GetProjectsKarmaList(int[] ids)
|
||||
{
|
||||
var karmaList = new List<IKarma>();
|
||||
|
||||
using (var reader = Data.SqlHelper.ExecuteReader("SELECT id as ProjectId, SUM(points) Points FROM powersProject GROUP BY id ORDER BY SUM(points) DESC"))
|
||||
string sql;
|
||||
if (ids == null || ids.Length == 0)
|
||||
{
|
||||
sql = "SELECT id as ProjectId, SUM(points) Points FROM powersProject GROUP BY id ORDER BY SUM(points) DESC";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ids.Length > 2000) throw new InvalidOperationException("Cannot query for more than 2000 items");
|
||||
|
||||
sql = string.Format(
|
||||
"SELECT id as ProjectId, SUM(points) Points FROM powersProject WHERE id IN ({0}) GROUP BY id ORDER BY SUM(points) DESC",
|
||||
string.Join(",", ids));
|
||||
}
|
||||
|
||||
using (var reader = Data.SqlHelper.ExecuteReader(sql))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
@@ -35,6 +56,20 @@ namespace OurUmbraco.MarketPlace.Providers
|
||||
return karmaList;
|
||||
}
|
||||
|
||||
public IEnumerable<IKarma> GetProjectsKarmaList(long pageIndex, long pageSize, out long totalItems)
|
||||
{
|
||||
var pagedResult = ApplicationContext.Current.DatabaseContext.Database.Page<dynamic>(pageIndex + 1, pageSize,
|
||||
"SELECT * FROM (SELECT id as ProjectId, SUM(points) Points FROM powersProject GROUP BY id) tmp ORDER BY Points DESC");
|
||||
|
||||
totalItems = pagedResult.TotalItems;
|
||||
|
||||
return pagedResult.Items.Select(x => new Karma
|
||||
{
|
||||
ProjectId = x.ProjectId,
|
||||
Points = x.Points
|
||||
});
|
||||
}
|
||||
|
||||
public IEnumerable<IKarma> GetProjectsKarmaListByDate(DateTime afterDate)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
Reference in New Issue
Block a user