Support localization for content search (backoffice) (#12618)

* Support localization for content search

* Formatting

Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>

* Review changes

* Review changes

Co-authored-by: kjac <kjn@impact.dk>
Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>
This commit is contained in:
Kenn Jacobsen
2022-07-04 13:45:33 +02:00
committed by GitHub
parent 173c1c8c8f
commit f2a98309b4
3 changed files with 38 additions and 4 deletions

View File

@@ -204,6 +204,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
return result;
}
var culture = ClientCulture();
var allowedSections = _backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.AllowedSections.ToArray();
var searchTasks = new List<Task>();
@@ -221,7 +222,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
var rootNodeDisplayName = Tree.GetRootNodeDisplayName(tree, _localizedTextService);
if (rootNodeDisplayName is not null)
{
searchTasks.Add(ExecuteSearchAsync(query, searchableTree, rootNodeDisplayName,result));
searchTasks.Add(ExecuteSearchAsync(query, culture, searchableTree, rootNodeDisplayName,result));
}
}
}
@@ -232,13 +233,22 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
private static async Task ExecuteSearchAsync(
string query,
string? culture,
KeyValuePair<string, SearchableApplicationTree> searchableTree,
string rootNodeDisplayName,
ConcurrentDictionary<string, TreeSearchResult> result)
{
ISearchableTree searcher = searchableTree.Value.SearchableTree;
const int pageSize = 200;
IEnumerable<SearchResultEntity> results = (
searcher is ISearchableTreeWithCulture searcherWithCulture
? await searcherWithCulture.SearchAsync(query, pageSize, 0, culture: culture)
: await searcher.SearchAsync(query, pageSize, 0))
.WhereNotNull();
var searchResult = new TreeSearchResult
{
Results = (await searchableTree.Value.SearchableTree.SearchAsync(query, 200, 0)).WhereNotNull(),
Results = results,
TreeAlias = searchableTree.Key,
AppAlias = searchableTree.Value.AppAlias,
JsFormatterService = searchableTree.Value.FormatterService,