From 7faaffef98f8c3fcef45b399721a95ad1318f18f Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Mon, 29 Aug 2022 14:01:59 +0200 Subject: [PATCH] 100 search results --- .../app/modules/search/overlay.vue | 2 +- zero.Core/Pages/ZeroPageModule.cs | 4 +-- zero.Core/Search/Models/SearchIndexMap.cs | 26 +++++++++---------- zero.Core/Search/SearchService.cs | 7 +++-- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/zero.Backoffice.UI/app/modules/search/overlay.vue b/zero.Backoffice.UI/app/modules/search/overlay.vue index 8dd7bfcb..eae7d3a0 100644 --- a/zero.Backoffice.UI/app/modules/search/overlay.vue +++ b/zero.Backoffice.UI/app/modules/search/overlay.vue @@ -101,7 +101,7 @@ return; } - const result = await api.query(this.query, { pageSize: 20 }); + const result = await api.query(this.query, { pageSize: 100 }); if (result.data) { diff --git a/zero.Core/Pages/ZeroPageModule.cs b/zero.Core/Pages/ZeroPageModule.cs index 52932a3d..d996aed5 100644 --- a/zero.Core/Pages/ZeroPageModule.cs +++ b/zero.Core/Pages/ZeroPageModule.cs @@ -36,9 +36,9 @@ internal class ZeroPageModule : ZeroModule services.Configure(opts => { - opts.Map().Display((x, res, opts) => + opts.Map().Display((x, res, ctx) => { - FlavorConfig flavor = opts.For().Get(x.Flavor); + FlavorConfig flavor = ctx.Options.For().Get(x.Flavor); if (flavor != null) { res.Icon = flavor.Icon; diff --git a/zero.Core/Search/Models/SearchIndexMap.cs b/zero.Core/Search/Models/SearchIndexMap.cs index e925fcc1..5ee0c775 100644 --- a/zero.Core/Search/Models/SearchIndexMap.cs +++ b/zero.Core/Search/Models/SearchIndexMap.cs @@ -9,7 +9,7 @@ public class SearchIndexMap protected string _group; protected string[] _fields; protected float _boost = 0; - protected Func _modify; + protected Func _modify; const string mapTemplate = @"map('{collection}', function (x) { return { @@ -54,11 +54,11 @@ public class SearchIndexMap return Type.IsAssignableFrom(type); } - internal async Task Modify(ZeroEntity entity, SearchResult result, IZeroOptions options) + internal async Task Modify(ZeroEntity entity, SearchResult result, IZeroContext context) { if (_modify != null) { - await _modify(entity, result, options); + await _modify(entity, result, context); } } } @@ -86,26 +86,26 @@ public class SearchIndexMap : SearchIndexMap where T : ZeroEntity public SearchIndexMap Display(Func modify = null) { - _modify = (x, res, opts) => modify?.Invoke(x as T, res); + _modify = (x, res, ctx) => modify?.Invoke(x as T, res); return this; } - public SearchIndexMap Display(Action modify = null) + public SearchIndexMap Display(Func modify = null) { - _modify = (x, res, opts) => + _modify = (x, res, ctx) => modify?.Invoke(x as T, res, ctx); + return this; + } + + public SearchIndexMap Display(Action modify = null) + { + _modify = (x, res, ctx) => { - modify?.Invoke(x as T, res, opts); + modify?.Invoke(x as T, res, ctx); return Task.CompletedTask; }; return this; } - public SearchIndexMap Display(Func modify = null) - { - _modify = (x, res, opts) => modify?.Invoke(x as T, res, opts); - return this; - } - public SearchIndexMap Fields(params string[] fieldNames) { _fields = fieldNames; diff --git a/zero.Core/Search/SearchService.cs b/zero.Core/Search/SearchService.cs index a9321a6f..830778c5 100644 --- a/zero.Core/Search/SearchService.cs +++ b/zero.Core/Search/SearchService.cs @@ -9,12 +9,15 @@ public class SearchService : ISearchService protected IZeroStore Store { get; private set; } protected IZeroOptions Options { get; private set; } + + protected IZeroContext Context { get; private set; } - public SearchService(IZeroStore store, IZeroOptions options) + public SearchService(IZeroStore store, IZeroOptions options, IZeroContext context) { Store = store; Options = options; + Context = context; } @@ -53,7 +56,7 @@ public class SearchService : ISearchService Url = "/" }; - await map.Modify(result, searchResult, Options); + await map.Modify(result, searchResult, Context); items.Add(searchResult); }