From 3c221c12790ac8ea001ecde7862412382ac440e5 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 24 Feb 2024 22:05:50 -0600 Subject: capture excluded phrases --- src/slskd/Application.cs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index aa6af2bc..27f9e882 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -181,6 +181,8 @@ namespace slskd Client.DownloadDenied += (e, args) => Log.Information("Download of {Filename} from {Username} was denied: {Message}", args.Filename, args.Username, args.Message); Client.DownloadFailed += (e, args) => Log.Information("Download of {Filename} from {Username} failed", args.Filename, args.Username); + Client.ExcludedSearchPhrasesReceived += (e, args) => ExcludedSearchPhrases = args; + ConnectionWatchdog = connectionWatchdog; Clock.EveryMinute += Clock_EveryMinute; @@ -221,6 +223,7 @@ namespace slskd private IEnumerable CompiledSearchResponseFilters { get; set; } private IEnumerable ActiveDownloadIdsAtPreviousShutdown { get; set; } = Enumerable.Empty(); private Options.FlagsOptions Flags { get; set; } + private IReadOnlyCollection ExcludedSearchPhrases { get; set; } = Enumerable.Empty().ToList(); public void CollectGarbage() { -- cgit v1.2.3 From 4cf7752282adb80a9e6d20187d50745e77e67bf0 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 24 Feb 2024 22:23:49 -0600 Subject: append excluded phrases to searches --- src/slskd/Application.cs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 27f9e882..a3bea5b2 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -1374,6 +1374,10 @@ namespace slskd return null; } + // append the list of excluded search phrases supplied by the server + // see https://github.com/jpdillingham/Soulseek.NET/issues/803 + query = new SearchQuery(terms: query.Terms, exclusions: query.Exclusions.Concat(ExcludedSearchPhrases).Distinct()); + try { var sw = new Stopwatch(); -- cgit v1.2.3 From 92e5bd61becad8877d2733696260556db6c8a514 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 25 Feb 2024 14:36:21 -0600 Subject: filter using substring matching on filenames --- src/slskd/Shares/SqliteShareRepository.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/slskd/Shares/SqliteShareRepository.cs b/src/slskd/Shares/SqliteShareRepository.cs index 882ede74..029d74b8 100644 --- a/src/slskd/Shares/SqliteShareRepository.cs +++ b/src/slskd/Shares/SqliteShareRepository.cs @@ -539,6 +539,17 @@ namespace slskd.Shares while (reader.Read()) { var filename = reader.GetString(0); + + // SQLite takes care of matching on tokens, but unfortunately doesn't work in cases where an exclusion appears as a substring. + // example: the token matching works to exclude the result "foo bar baz" given a "bar" exclusion, but does not exclude "foo xbarx baz" + // for this reason we must iterate over the exclusion list and ensure none appear as substrings + // **CAUTION** performance of this will degrade exponentially as the list of exclusions grows + if (query.Exclusions.Any(x => filename.Contains(x, StringComparison.OrdinalIgnoreCase))) + { + Log.Debug("Dropping excluded filename {File}", filename); + continue; + } + var code = reader.GetInt32(1); var size = reader.GetInt64(2); var extension = reader.GetString(3); -- cgit v1.2.3 From 1fd51e9ffadc263942ca36e5e9b1209138bf3e88 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 25 Feb 2024 14:37:07 -0600 Subject: move handler to private function --- src/slskd/Application.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index a3bea5b2..75b2eee6 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -181,7 +181,7 @@ namespace slskd Client.DownloadDenied += (e, args) => Log.Information("Download of {Filename} from {Username} was denied: {Message}", args.Filename, args.Username, args.Message); Client.DownloadFailed += (e, args) => Log.Information("Download of {Filename} from {Username} failed", args.Filename, args.Username); - Client.ExcludedSearchPhrasesReceived += (e, args) => ExcludedSearchPhrases = args; + Client.ExcludedSearchPhrasesReceived += Client_ExcludedSearchPhrasesReceived; ConnectionWatchdog = connectionWatchdog; @@ -1096,6 +1096,12 @@ namespace slskd } } + private void Client_ExcludedSearchPhrasesReceived(object sender, IReadOnlyCollection e) + { + Log.Debug("Excluded search phrases: {Phrases}", string.Join(", ", e)); + ExcludedSearchPhrases = e; + } + private void Client_TransferProgressUpdated(object sender, TransferProgressUpdatedEventArgs args) { // no-op. this is really verbose, use for troubleshooting. @@ -1369,7 +1375,7 @@ namespace slskd // sometimes clients send search queries consisting only of exclusions; drop them. // no other clients send search results for these, even though it is technically possible. - if (!query.Terms.Any()) + if (query.Terms.Count == 0) { return null; } -- cgit v1.2.3