mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-19 00:03:36 +00:00
Reserve half of combined Jellyfin result slots for top scene search matches
This commit is contained in:
@@ -12,17 +12,21 @@ namespace Jellyfin.Plugin.SceneSearch;
|
||||
/// </summary>
|
||||
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<BaseItemKind> 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user