diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-09-28 09:36:34 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2022-09-28 09:36:34 -0500 |
| commit | db7866c9b0cae53c53ba4d16f52a1653df646265 (patch) | |
| tree | 8425d4253c2876591be33900114ed7737f275b7f /src/slskd/Shares/SharedFileCache.cs | |
| parent | 77d1463b7183aa658cc7da3610b795d462ab493f (diff) | |
| download | slskd-db7866c9b0cae53c53ba4d16f52a1653df646265.tar.gz | |
move search
Diffstat (limited to 'src/slskd/Shares/SharedFileCache.cs')
| -rw-r--r-- | src/slskd/Shares/SharedFileCache.cs | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/src/slskd/Shares/SharedFileCache.cs b/src/slskd/Shares/SharedFileCache.cs index 6ccea3fc..4a443468 100644 --- a/src/slskd/Shares/SharedFileCache.cs +++ b/src/slskd/Shares/SharedFileCache.cs @@ -30,7 +30,6 @@ namespace slskd.Shares using System.Threading.Tasks; using Microsoft.Data.Sqlite; using Serilog; - using Soulseek; /// <summary> /// Shared file cache. @@ -51,13 +50,6 @@ namespace slskd.Shares Task FillAsync(IEnumerable<Share> shares, IEnumerable<Regex> filters); /// <summary> - /// Searches the cache for the specified <paramref name="query"/> and returns the matching files. - /// </summary> - /// <param name="query">The query for which to search.</param> - /// <returns>The matching files.</returns> - IEnumerable<File> Search(SearchQuery query); - - /// <summary> /// Cancels the currently running fill operation, if one is running. /// </summary> /// <returns>A value indicating whether a fill operation was cancelled.</returns> @@ -365,59 +357,6 @@ namespace slskd.Shares } /// <summary> - /// Searches the cache for the specified <paramref name="query"/> and returns the matching files. - /// </summary> - /// <param name="query">The query for which to search.</param> - /// <returns>The matching files.</returns> - public IEnumerable<File> Search(SearchQuery query) - { - string Clean(string str) => str.Replace("/", " ") - .Replace("\\", " ") - .Replace(":", " ") - .Replace("\"", " ") - .Replace("'", "''"); - - var match = string.Join(" AND ", query.Terms.Select(token => $"\"{Clean(token)}\"")); - var exclusions = string.Join(" OR ", query.Exclusions.Select(exclusion => $"\"{Clean(exclusion)}\"")); - - var sql = $"SELECT files.maskedFilename, files.code, files.size, files.extension, files.attributeJson FROM filenames " + - "INNER JOIN files ON filenames.maskedFilename = files.maskedFilename " + - $"WHERE filenames MATCH '({match}) {(query.Exclusions.Any() ? $"NOT ({exclusions})" : string.Empty)}' " + - "ORDER BY filenames.maskedFilename ASC;"; - - var results = new List<File>(); - SqliteDataReader reader = default; - - try - { - using var conn = GetConnection(); - using var cmd = new SqliteCommand(sql, conn); - reader = cmd.ExecuteReader(); - - while (reader.Read()) - { - var filename = reader.GetString(0); - var code = reader.GetInt32(1); - var size = reader.GetInt64(2); - var extension = reader.GetString(3); - var attributeJson = reader.GetString(4); - - var attributeList = attributeJson.FromJson<List<FileAttribute>>(); - - var file = new File(code, filename, size, extension, attributeList); - results.Add(file); - } - - return results; - } - catch (Exception ex) - { - Log.Warning(ex, "Failed to execute shared file query '{Query}': {Message}", query, ex.Message); - return Enumerable.Empty<File>(); - } - } - - /// <summary> /// Cancels the currently running fill operation, if one is running. /// </summary> /// <returns>A value indicating whether a fill operation was cancelled.</returns> |
