diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-08-21 12:05:35 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-08-21 12:05:35 -0500 |
| commit | 05c9d7308aa2ef405352271f4254a519c397d317 (patch) | |
| tree | 8afbbc0193cfe21a0ea83029e4ad73366f050823 /src/slskd/Application/SharedFileCache.cs | |
| parent | 8332f3877b5c17a72de87932c696e66ffb3ad039 (diff) | |
| download | slskd-05c9d7308aa2ef405352271f4254a519c397d317.tar.gz | |
exclude terms prefixed with -
Diffstat (limited to 'src/slskd/Application/SharedFileCache.cs')
| -rw-r--r-- | src/slskd/Application/SharedFileCache.cs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/slskd/Application/SharedFileCache.cs b/src/slskd/Application/SharedFileCache.cs index 860bcfa3..5d12ed63 100644 --- a/src/slskd/Application/SharedFileCache.cs +++ b/src/slskd/Application/SharedFileCache.cs @@ -275,17 +275,16 @@ namespace slskd /// <returns>The matching files.</returns> public async Task<IEnumerable<File>> SearchAsync(SearchQuery query) { - // sanitize the query string. there's probably more to it than this. - var text = query.Query - .Replace("/", " ") + string Clean(string str) => str.Replace("/", " ") .Replace("\\", " ") .Replace(":", " ") .Replace("\"", " ") .Replace("'", "''"); - var tokens = text.Split(' ').Select(token => $"\"{token}\""); + 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 * FROM cache WHERE cache MATCH '{string.Join(" AND ", tokens)}'"; + var sql = $"SELECT * FROM cache WHERE cache MATCH '({match}) {(query.Exclusions.Any() ? $"NOT ({exclusions})" : string.Empty)}'"; try { |
