diff options
| author | JP Dillingham <jp@dillingham.me> | 2024-12-16 18:12:07 -0600 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2024-12-16 18:12:07 -0600 |
| commit | d16cd958001f4c9474a2bd511fb3b40a4d7c7daf (patch) | |
| tree | 4ad7abc7b4a394dbe059a4c2b52d22973cbe5b51 /src/slskd/Search/SearchService.cs | |
| parent | 915bcc9544575f60ab918ee7b127ada431d4ffc6 (diff) | |
| download | slskd-d16cd958001f4c9474a2bd511fb3b40a4d7c7daf.tar.gz | |
consolidate I/SearchService
Diffstat (limited to 'src/slskd/Search/SearchService.cs')
| -rw-r--r-- | src/slskd/Search/SearchService.cs | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/src/slskd/Search/SearchService.cs b/src/slskd/Search/SearchService.cs index 3d2e2750..ed661b1f 100644 --- a/src/slskd/Search/SearchService.cs +++ b/src/slskd/Search/SearchService.cs @@ -1,4 +1,4 @@ -// <copyright file="SearchService.cs" company="slskd Team"> +// <copyright file="SearchService.cs" company="slskd Team"> // Copyright (c) slskd Team. All rights reserved. // // This program is free software: you can redistribute it and/or modify @@ -39,6 +39,60 @@ namespace slskd.Search /// <summary> /// Handles the lifecycle and persistence of searches. /// </summary> + public interface ISearchService + { + /// <summary> + /// Deletes the specified search. + /// </summary> + /// <param name="search">The search to delete.</param> + /// <returns>The operation context.</returns> + Task DeleteAsync(Search search); + + /// <summary> + /// Finds a single search matching the specified <paramref name="expression"/>. + /// </summary> + /// <param name="expression">The expression to use to match searches.</param> + /// <param name="includeResponses">A value indicating whether to include search responses in the result.</param> + /// <returns>The found search, or default if not found.</returns> + /// <exception cref="ArgumentException">Thrown when an expression is not supplied.</exception> + Task<Search> FindAsync(Expression<Func<Search, bool>> expression, bool includeResponses = false); + + /// <summary> + /// Returns a list of all completed and in-progress searches, with responses omitted, matching the optional <paramref name="expression"/>. + /// </summary> + /// <param name="expression">An optional expression used to match searches.</param> + /// <returns>The list of searches matching the specified expression, or all searches if no expression is specified.</returns> + Task<List<Search>> ListAsync(Expression<Func<Search, bool>> expression = null); + + /// <summary> + /// Performs a search for the specified <paramref name="query"/> and <paramref name="scope"/>. + /// </summary> + /// <param name="id">A unique identifier for the search.</param> + /// <param name="query">The search query.</param> + /// <param name="scope">The search scope.</param> + /// <param name="options">Search options.</param> + /// <returns>The completed search.</returns> + Task<Search> StartAsync(Guid id, SearchQuery query, SearchScope scope, SearchOptions options = null); + + /// <summary> + /// Cancels the search matching the specified <paramref name="id"/>, if it is in progress. + /// </summary> + /// <param name="id">The unique identifier for the search.</param> + /// <returns>A value indicating whether the search was successfully cancelled.</returns> + bool TryCancel(Guid id); + + /// <summary> + /// Removes <see cref="SearchStates.Completed"/> searches older than the specified <paramref name="age"/>. + /// </summary> + /// <param name="age">The age after which records are eligible for pruning, in minutes.</param> + /// <param name="state">An optional, additional state by which records are filtered for pruning.</param> + /// <returns>The number of pruned records.</returns> + int Prune(int age, SearchStates state = SearchStates.Completed); + } + + /// <summary> + /// Handles the lifecycle and persistence of searches. + /// </summary> public class SearchService : ISearchService { /// <summary> |
