43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
namespace LaaProduction.Search
|
|
{
|
|
using LaaProduction.Search.Data.Interfaces;
|
|
using LaaProductionDI;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
public class SearchManager : ISearchManager
|
|
{
|
|
private readonly IWildcardRepository wildcardRepository;
|
|
|
|
public SearchManager()
|
|
=> this.wildcardRepository = LaaServiceProvider.GetService<IWildcardRepository>();
|
|
|
|
public IEnumerable<IDictionary<string, object>> SearchWildcard(string token, IEnumerable<string> selectedFields)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(token))
|
|
{
|
|
return Array.Empty<IDictionary<string, object>>();
|
|
}
|
|
|
|
token = token.Replace(" ", string.Empty).Trim();
|
|
selectedFields = selectedFields ?? Array.Empty<string>();
|
|
|
|
if (selectedFields.Any())
|
|
{
|
|
selectedFields = this.wildcardRepository.Fields().Intersect(selectedFields);
|
|
}
|
|
else
|
|
{
|
|
selectedFields = this.wildcardRepository.Fields();
|
|
}
|
|
|
|
return this.wildcardRepository.Find(token, selectedFields);
|
|
}
|
|
|
|
public IEnumerable<string> WildcardFields()
|
|
=> this.wildcardRepository.Fields();
|
|
}
|
|
}
|