aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-08-25 08:52:19 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-08-25 08:52:19 -0500
commitbb5f2cdfb27b3e1773d622ee92b05aa6b8f1950b (patch)
treedd101368b9f017776d7aac328b59f1c48c7e96fc
parent4a029673ef45ae77ba4e84fac268ded0ee959b9e (diff)
downloadslskd-bb5f2cdfb27b3e1773d622ee92b05aa6b8f1950b.tar.gz
filter search results
-rw-r--r--src/slskd/Application/Search/SearchService.cs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/slskd/Application/Search/SearchService.cs b/src/slskd/Application/Search/SearchService.cs
index 84cfd756..87ac5e22 100644
--- a/src/slskd/Application/Search/SearchService.cs
+++ b/src/slskd/Application/Search/SearchService.cs
@@ -15,6 +15,8 @@
// along with this program. If not, see https://www.gnu.org/licenses/.
// </copyright>
+using Microsoft.Extensions.Options;
+
namespace slskd.Search
{
using System;
@@ -22,6 +24,7 @@ namespace slskd.Search
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
+ using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
@@ -41,14 +44,17 @@ namespace slskd.Search
/// <summary>
/// Initializes a new instance of the <see cref="SearchService"/> class.
/// </summary>
+ /// <param name="optionsMonitor"></param>
/// <param name="client">The client instance to use.</param>
/// <param name="contextFactory">The database context to use.</param>
/// <param name="log">The logger.</param>
public SearchService(
+ IOptionsMonitor<Options> optionsMonitor,
ISoulseekClient client,
IDbContextFactory<SearchDbContext> contextFactory,
ILogger<SearchService> log)
{
+ OptionsMonitor = optionsMonitor;
Client = client;
ContextFactory = contextFactory;
Log = log;
@@ -57,6 +63,7 @@ namespace slskd.Search
private ConcurrentDictionary<Guid, CancellationTokenSource> CancellationTokens { get; }
= new ConcurrentDictionary<Guid, CancellationTokenSource>();
+ private IOptionsMonitor<Options> OptionsMonitor { get; }
private ISoulseekClient Client { get; }
private IDbContextFactory<SearchDbContext> ContextFactory { get; }
private ILogger<SearchService> Log { get; set; }
@@ -83,10 +90,15 @@ namespace slskd.Search
StartedAt = DateTime.UtcNow,
};
+ var filters = OptionsMonitor.CurrentValue.Filters.File
+ .Select(filter => new Regex(filter, RegexOptions.Compiled));
+
options ??= new SearchOptions();
options = options.WithActions(
stateChanged: (args) => UpdateSearchState(search, args.Search),
responseReceived: (args) => UpdateSearchState(search, args.Search));
+ options = options.WithFilters(
+ fileFilter: (file) => !filters.Any(filter => filter.IsMatch(file.Filename)));
try
{