diff --git a/jellyfin-plugin/Jellyfin.Plugin.SceneSearch/SceneSearchProvider.cs b/jellyfin-plugin/Jellyfin.Plugin.SceneSearch/SceneSearchProvider.cs index bff438e..098e34c 100644 --- a/jellyfin-plugin/Jellyfin.Plugin.SceneSearch/SceneSearchProvider.cs +++ b/jellyfin-plugin/Jellyfin.Plugin.SceneSearch/SceneSearchProvider.cs @@ -12,17 +12,21 @@ namespace Jellyfin.Plugin.SceneSearch; /// public sealed class SceneSearchProvider : IExternalSearchProvider { - // Normal providers such as Jellyfin Meilisearch return relevance in the - // 0..1 range. An explicit scene: query intentionally moves Scene Search - // into a reserved range above 1.0 so its results rank first without - // modifying or forking the other provider. + // Jellyfin merges all external provider results by descending score and + // truncates to query.Limit. Normal Meilisearch relevance is in 0..1, so + // simply returning our website results at the same scores does NOT preserve + // any of them: another provider can push every Scene Search hit beyond the + // cap. Reserve up to half the limit (at most 10 items) for Scene Search, + // leaving the other half available for normal title matches. + // Prioritise in website/API ORDER rather than re-ranking by SigLIP scores. + private const int MaxBlendedSceneSlots = 10; + private const float BlendedSceneScoreCeiling = 1.20f; + private const float BlendedSceneScoreStep = 0.01f; + + // The optional scene: prefix continues to prefer Scene Search results + // more strongly than normal queries (which reserve only a limited slice). private const float ExplicitSceneScoreFloor = 1.1f; private const float ExplicitSceneScoreRange = 0.9f; - // Small boost for at most two exact caption-text matches returned by the - // backend. This prevents a full page of ordinary Meilisearch results from - // pushing all caption matches beyond Jellyfin's result cap. - private const float CaptionTextScoreFloor = 1.01f; - private const float CaptionTextScoreRange = 0.05f; private static readonly HashSet SupportedKinds = [ @@ -102,6 +106,10 @@ public sealed class SceneSearchProvider : IExternalSearchProvider var yielded = 0; var invalidIds = 0; var typeFiltered = 0; + var promoted = 0; + var blendedSceneSlots = Math.Min( + MaxBlendedSceneSlots, + Math.Max(1, (Math.Max(limit, 1) + 1) / 2)); foreach (var result in results) { @@ -129,9 +137,14 @@ public sealed class SceneSearchProvider : IExternalSearchProvider { score = ExplicitSceneScoreFloor + (ExplicitSceneScoreRange * score); } - else if (result.CaptionTextMatch) + else if (promoted < blendedSceneSlots) { - score = CaptionTextScoreFloor + (CaptionTextScoreRange * score); + // The backend already groups by Jellyfin item and places + // caption-text matches first. Keep its exact ordering for a + // bounded number of Scene Search matches, above Meilisearch's + // 0..1 scores. The rest compete normally with other providers. + score = BlendedSceneScoreCeiling - (promoted * BlendedSceneScoreStep); + promoted++; } yielded++; @@ -139,9 +152,11 @@ public sealed class SceneSearchProvider : IExternalSearchProvider } _logger.LogInformation( - "Scene Search API returned {ApiCount} grouped item(s); yielded {Yielded}, invalid ids {InvalidIds}, type-filtered {TypeFiltered}", + "Scene Search API returned {ApiCount} grouped item(s); yielded {Yielded}, reserved {Promoted}/{ReservedSlots} blended scene slots, invalid ids {InvalidIds}, type-filtered {TypeFiltered}", results.Count, yielded, + promoted, + explicitSceneQuery ? 0 : blendedSceneSlots, invalidIds, typeFiltered); }