2018-12-19 16:00:29 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2017-09-08 19:39:13 +02:00
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
|
using System.Linq;
|
2018-12-19 16:00:29 +01:00
|
|
|
|
using Umbraco.Core;
|
2017-09-08 19:39:13 +02:00
|
|
|
|
using Umbraco.Core.Composing;
|
|
|
|
|
|
using Umbraco.Core.Services;
|
2019-01-17 13:20:19 +11:00
|
|
|
|
using Umbraco.Web.Services;
|
2017-09-08 19:39:13 +02:00
|
|
|
|
using Umbraco.Web.Trees;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Search
|
|
|
|
|
|
{
|
2017-09-13 17:35:20 +02:00
|
|
|
|
public class SearchableTreeCollection : BuilderCollectionBase<ISearchableTree>
|
2017-09-08 19:39:13 +02:00
|
|
|
|
{
|
|
|
|
|
|
private readonly Dictionary<string, SearchableApplicationTree> _dictionary;
|
|
|
|
|
|
|
|
|
|
|
|
public SearchableTreeCollection(IEnumerable<ISearchableTree> items, IApplicationTreeService treeService)
|
|
|
|
|
|
: base(items)
|
|
|
|
|
|
{
|
|
|
|
|
|
_dictionary = CreateDictionary(treeService);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Dictionary<string, SearchableApplicationTree> CreateDictionary(IApplicationTreeService treeService)
|
|
|
|
|
|
{
|
2018-12-11 17:51:47 +11:00
|
|
|
|
var appTrees = treeService.GetAll()
|
|
|
|
|
|
.OrderBy(x => x.SortOrder)
|
|
|
|
|
|
.ToArray();
|
2018-12-19 16:00:29 +01:00
|
|
|
|
var dictionary = new Dictionary<string, SearchableApplicationTree>(StringComparer.OrdinalIgnoreCase);
|
2017-09-08 19:39:13 +02:00
|
|
|
|
var searchableTrees = this.ToArray();
|
2018-12-11 17:51:47 +11:00
|
|
|
|
foreach (var appTree in appTrees)
|
2017-09-08 19:39:13 +02:00
|
|
|
|
{
|
2018-12-19 16:00:29 +01:00
|
|
|
|
var found = searchableTrees.FirstOrDefault(x => x.TreeAlias.InvariantEquals(appTree.Alias));
|
2017-09-08 19:39:13 +02:00
|
|
|
|
if (found != null)
|
|
|
|
|
|
{
|
2018-12-11 17:51:47 +11:00
|
|
|
|
dictionary[found.TreeAlias] = new SearchableApplicationTree(appTree.ApplicationAlias, appTree.Alias, found);
|
2017-09-08 19:39:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return dictionary;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-30 12:22:23 +11:00
|
|
|
|
public IReadOnlyDictionary<string, SearchableApplicationTree> SearchableApplicationTrees => _dictionary;
|
2017-09-08 19:39:13 +02:00
|
|
|
|
|
|
|
|
|
|
public SearchableApplicationTree this[string key] => _dictionary[key];
|
|
|
|
|
|
}
|
2017-09-23 10:08:18 +02:00
|
|
|
|
}
|