Finished advanced search functionality

This commit is contained in:
2025-07-05 15:11:02 +02:00
parent 68a4479c2d
commit 66d03513eb
13 changed files with 272 additions and 151 deletions

View File

@@ -300,12 +300,17 @@
await Reload();
}
private void SearchSuggestionSelected(string? suggestion) {
private async Task SearchSuggestionSelected(string? suggestion) {
if (string.IsNullOrWhiteSpace(suggestion)) return;
_searchTerm = SearchSuggestions.CompleteSearchSuggestion(_config!, _searchTerm ?? string.Empty, suggestion);
_searchBox!.Value = _searchTerm;
_searchBox.FocusAsync();
UpdateSearchSuggestions();
if (!suggestion.EndsWith('='))
await OnSearch(new() {
Value = _searchTerm
});
}
private void UpdateSearchSuggestions() {

View File

@@ -4,7 +4,7 @@ using HopFrame.Web.Helpers;
namespace HopFrame.Web.Services.Implementation;
public sealed class SearchSuggestionProvider(IContextExplorer explorer, IServiceProvider provider) : ISearchSuggestionProvider {
public sealed class SearchSuggestionProvider : ISearchSuggestionProvider {
public IEnumerable<string> GenerateSearchSuggestions(TableConfig table, string searchText) {
if (table.ContextConfig is not DbContextConfig) return [];
@@ -27,15 +27,6 @@ public sealed class SearchSuggestionProvider(IContextExplorer explorer, IService
if (property.Info.PropertyType == typeof(TimeOnly))
return [TimeOnly.FromDateTime(DateTime.Now).ToString()];
if (property.IsRelation) {
var manager = explorer.GetTableManager(table.TableType);
var entries = manager!.LoadPage(0, 100).Result;
return entries
.Select(e => manager.DisplayProperty(e, property).Result)
.Distinct()
.Take(10);
}
}
if (searchText.Length != 0 && !searchText.EndsWith(' '))
@@ -45,6 +36,7 @@ public sealed class SearchSuggestionProvider(IContextExplorer explorer, IService
var searchableProperties = table.Properties
.Where(p => !p.IsVirtualProperty)
.Where(p => p.List)
.Where(p => p.Searchable)
.Where(p =>
p.Info.PropertyType.IsEnum ||
p.Info.PropertyType.IsNumeric() ||