U4-2676 - fix
This commit is contained in:
@@ -133,7 +133,7 @@ namespace Umbraco.Web.Editors
|
||||
|
||||
result[treeAttribute.GetRootNodeDisplayName(Services.TextService)] = new TreeSearchResult
|
||||
{
|
||||
Results = searchableTree.Value.SearchableTree.Search(query, 200, 0, out total),
|
||||
Results = searchableTree.Value.SearchableTree.Search(Umbraco, query, 200, 0, out total),
|
||||
TreeAlias = searchableTree.Key,
|
||||
AppAlias = searchableTree.Value.AppAlias,
|
||||
JsFormatterService = searchableTreeAttribute == null ? "" : searchableTreeAttribute.ServiceName,
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Umbraco.Web.Search
|
||||
/// <summary>
|
||||
/// Searches for results based on the entity type
|
||||
/// </summary>
|
||||
/// <param name="umbracoHelper"></param>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="totalFound"></param>
|
||||
/// <param name="searchFrom">
|
||||
@@ -22,6 +23,6 @@ namespace Umbraco.Web.Search
|
||||
/// <param name="pageSize"></param>
|
||||
/// <param name="pageIndex"></param>
|
||||
/// <returns></returns>
|
||||
IEnumerable<SearchResultItem> Search(string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null);
|
||||
IEnumerable<SearchResultItem> Search(UmbracoHelper umbracoHelper, string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ using System.Text.RegularExpressions;
|
||||
using AutoMapper;
|
||||
using Examine;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
|
||||
namespace Umbraco.Web.Search
|
||||
@@ -28,9 +29,9 @@ namespace Umbraco.Web.Search
|
||||
/// <returns></returns>
|
||||
public IEnumerable<SearchResultItem> ExamineSearch(
|
||||
UmbracoHelper umbracoHelper,
|
||||
string query,
|
||||
UmbracoEntityTypes entityType,
|
||||
int pageSize,
|
||||
string query,
|
||||
UmbracoEntityTypes entityType,
|
||||
int pageSize,
|
||||
long pageIndex, out long totalFound, string searchFrom = null)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
@@ -55,35 +56,13 @@ namespace Umbraco.Web.Search
|
||||
break;
|
||||
case UmbracoEntityTypes.Media:
|
||||
type = "media";
|
||||
|
||||
var mediaSearchFrom = int.MinValue;
|
||||
|
||||
if (umbracoHelper.UmbracoContext.Security.CurrentUser.StartMediaId > 0 ||
|
||||
//if searchFrom is specified and it is greater than 0
|
||||
(searchFrom != null && int.TryParse(searchFrom, out mediaSearchFrom) && mediaSearchFrom > 0))
|
||||
{
|
||||
sb.Append("+__Path: \\-1*\\,");
|
||||
sb.Append(mediaSearchFrom > 0
|
||||
? mediaSearchFrom.ToString(CultureInfo.InvariantCulture)
|
||||
: umbracoHelper.UmbracoContext.Security.CurrentUser.StartMediaId.ToString(CultureInfo.InvariantCulture));
|
||||
sb.Append("\\,* ");
|
||||
}
|
||||
var allMediaStartNodes = umbracoHelper.UmbracoContext.Security.CurrentUser.CalculateMediaStartNodeIds(ApplicationContext.Current.Services.EntityService);
|
||||
AppendPath(sb, UmbracoObjectTypes.Media, allMediaStartNodes, searchFrom);
|
||||
break;
|
||||
case UmbracoEntityTypes.Document:
|
||||
type = "content";
|
||||
|
||||
var contentSearchFrom = int.MinValue;
|
||||
|
||||
if (umbracoHelper.UmbracoContext.Security.CurrentUser.StartContentId > 0 ||
|
||||
//if searchFrom is specified and it is greater than 0
|
||||
(searchFrom != null && int.TryParse(searchFrom, out contentSearchFrom) && contentSearchFrom > 0))
|
||||
{
|
||||
sb.Append("+__Path: \\-1*\\,");
|
||||
sb.Append(contentSearchFrom > 0
|
||||
? contentSearchFrom.ToString(CultureInfo.InvariantCulture)
|
||||
: umbracoHelper.UmbracoContext.Security.CurrentUser.StartContentId.ToString(CultureInfo.InvariantCulture));
|
||||
sb.Append("\\,* ");
|
||||
}
|
||||
var allContentStartNodes = umbracoHelper.UmbracoContext.Security.CurrentUser.CalculateContentStartNodeIds(ApplicationContext.Current.Services.EntityService);
|
||||
AppendPath(sb, UmbracoObjectTypes.Document, allContentStartNodes, searchFrom);
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException("The " + typeof(UmbracoTreeSearcher) + " currently does not support searching against object type " + entityType);
|
||||
@@ -220,6 +199,58 @@ namespace Umbraco.Web.Search
|
||||
}
|
||||
}
|
||||
|
||||
private void AppendPath(StringBuilder sb, UmbracoObjectTypes objectType, int[] startNodeIds, string searchFrom)
|
||||
{
|
||||
var entityService = ApplicationContext.Current.Services.EntityService;
|
||||
|
||||
int searchFromId;
|
||||
var entityPath = int.TryParse(searchFrom, out searchFromId) && searchFromId > 0
|
||||
? entityService.GetAllPaths(objectType, searchFromId).FirstOrDefault()
|
||||
: null;
|
||||
if (entityPath != null)
|
||||
{
|
||||
// find... only what's underneath
|
||||
sb.Append("+__Path:");
|
||||
AppendPath(sb, entityPath.Path, false);
|
||||
sb.Append(" ");
|
||||
}
|
||||
else if (startNodeIds.Length == 0)
|
||||
{
|
||||
// make sure we don't find anything
|
||||
sb.Append("+__Path:none ");
|
||||
}
|
||||
else if (startNodeIds.Contains(-1) == false) // -1 = no restriction
|
||||
{
|
||||
var entityPaths = entityService.GetAllPaths(objectType, startNodeIds);
|
||||
|
||||
// for each start node, find the start node, and what's underneath
|
||||
// +__Path:(-1*,1234 -1*,1234,* -1*,5678 -1*,5678,* ...)
|
||||
sb.Append("+__Path:(");
|
||||
var first = true;
|
||||
foreach (var ep in entityPaths)
|
||||
{
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
sb.Append(" ");
|
||||
AppendPath(sb, ep.Path, true);
|
||||
}
|
||||
sb.Append(") ");
|
||||
}
|
||||
}
|
||||
|
||||
private void AppendPath(StringBuilder sb, string path, bool includeThisNode)
|
||||
{
|
||||
path = path.Replace("-", "\\-").Replace(",", "\\,");
|
||||
if (includeThisNode)
|
||||
{
|
||||
sb.Append(path);
|
||||
sb.Append(" ");
|
||||
}
|
||||
sb.Append(path);
|
||||
sb.Append("\\,*");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a collection of entities for media based on search results
|
||||
/// </summary>
|
||||
|
||||
@@ -259,9 +259,9 @@ namespace Umbraco.Web.Trees
|
||||
return menu;
|
||||
}
|
||||
|
||||
public IEnumerable<SearchResultItem> Search(string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null)
|
||||
public IEnumerable<SearchResultItem> Search(UmbracoHelper umbracoHelper, string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null)
|
||||
{
|
||||
return _treeSearcher.ExamineSearch(Umbraco, query, UmbracoEntityTypes.Document, pageSize, pageIndex, out totalFound, searchFrom);
|
||||
return _treeSearcher.ExamineSearch(umbracoHelper, query, UmbracoEntityTypes.Document, pageSize, pageIndex, out totalFound, searchFrom);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,7 +142,7 @@ namespace Umbraco.Web.Trees
|
||||
return menu;
|
||||
}
|
||||
|
||||
public IEnumerable<SearchResultItem> Search(string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null)
|
||||
public IEnumerable<SearchResultItem> Search(UmbracoHelper umbracoHelper, string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null)
|
||||
{
|
||||
var results = Services.EntityService.GetPagedDescendantsFromRoot(UmbracoObjectTypes.DocumentType, pageIndex, pageSize, out totalFound, filter: query);
|
||||
return Mapper.Map<IEnumerable<SearchResultItem>>(results);
|
||||
|
||||
@@ -127,7 +127,7 @@ namespace Umbraco.Web.Trees
|
||||
return menu;
|
||||
}
|
||||
|
||||
public IEnumerable<SearchResultItem> Search(string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null)
|
||||
public IEnumerable<SearchResultItem> Search(UmbracoHelper umbracoHelper, string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null)
|
||||
{
|
||||
var results = Services.EntityService.GetPagedDescendantsFromRoot(UmbracoObjectTypes.DataType, pageIndex, pageSize, out totalFound, filter: query);
|
||||
return Mapper.Map<IEnumerable<SearchResultItem>>(results);
|
||||
|
||||
@@ -173,9 +173,9 @@ namespace Umbraco.Web.Trees
|
||||
return Security.CurrentUser.HasPathAccess(media, Services.EntityService);
|
||||
}
|
||||
|
||||
public IEnumerable<SearchResultItem> Search(string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null)
|
||||
public IEnumerable<SearchResultItem> Search(UmbracoHelper umbracoHelper, string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null)
|
||||
{
|
||||
return _treeSearcher.ExamineSearch(Umbraco, query, UmbracoEntityTypes.Media, pageSize, pageIndex, out totalFound, searchFrom);
|
||||
return _treeSearcher.ExamineSearch(umbracoHelper, query, UmbracoEntityTypes.Media, pageSize, pageIndex, out totalFound, searchFrom);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,7 +129,7 @@ namespace Umbraco.Web.Trees
|
||||
return menu;
|
||||
}
|
||||
|
||||
public IEnumerable<SearchResultItem> Search(string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null)
|
||||
public IEnumerable<SearchResultItem> Search(UmbracoHelper umbracoHelper, string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null)
|
||||
{
|
||||
var results = Services.EntityService.GetPagedDescendantsFromRoot(UmbracoObjectTypes.MediaType, pageIndex, pageSize, out totalFound, filter: query);
|
||||
return Mapper.Map<IEnumerable<SearchResultItem>>(results);
|
||||
|
||||
@@ -184,9 +184,9 @@ namespace Umbraco.Web.Trees
|
||||
return menu;
|
||||
}
|
||||
|
||||
public IEnumerable<SearchResultItem> Search(string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null)
|
||||
public IEnumerable<SearchResultItem> Search(UmbracoHelper umbracoHelper, string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null)
|
||||
{
|
||||
return _treeSearcher.ExamineSearch(Umbraco, query, UmbracoEntityTypes.Member, pageSize, pageIndex, out totalFound, searchFrom);
|
||||
return _treeSearcher.ExamineSearch(umbracoHelper, query, UmbracoEntityTypes.Member, pageSize, pageIndex, out totalFound, searchFrom);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,7 +133,7 @@ namespace Umbraco.Web.Trees
|
||||
: null;
|
||||
}
|
||||
|
||||
public IEnumerable<SearchResultItem> Search(string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null)
|
||||
public IEnumerable<SearchResultItem> Search(UmbracoHelper umbracoHelper, string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null)
|
||||
{
|
||||
var results = Services.EntityService.GetPagedDescendantsFromRoot(UmbracoObjectTypes.Template, pageIndex, pageSize, out totalFound, filter: query);
|
||||
return Mapper.Map<IEnumerable<SearchResultItem>>(results);
|
||||
|
||||
Reference in New Issue
Block a user