perf(search): prefix-by-default Deployments and config-audit search; bounded Contains opt-in (ScadaBridge#50)

Deployments free-text search and the config-audit EntityName filter no longer
emit LIKE '%term%' by default. Prefix (LIKE 'term%') is the default; substring
is an explicit opt-in (DeploymentSearchMode.Contains / entityNameContains)
always bounded by a DeployedAt/Timestamp window (explicit, else 30 days).
Migration PrefixSearchIndexes adds DeployedBy, RevisionHash and EntityName
indexes. Deployments page gains a 'Match anywhere' checkbox.

Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
Joseph Doherty
2026-11-09 15:42:56 -05:00
parent 0ce6633270
commit 47f3a703bf
15 changed files with 2620 additions and 44 deletions
@@ -56,11 +56,18 @@ public interface ICentralUiRepository
/// <param name="from">Optional start of date range filter.</param>
/// <param name="to">Optional end of date range filter.</param>
/// <param name="entityId">Optional entity ID filter.</param>
/// <param name="entityName">Optional entity name filter.</param>
/// <param name="entityName">
/// Optional entity name filter. A case-insensitive PREFIX match by default (index-friendly);
/// see <paramref name="entityNameContains"/>.
/// </param>
/// <param name="bundleImportId">Optional bundle import correlation ID filter.</param>
/// <param name="page">One-based page number.</param>
/// <param name="pageSize">Number of entries per page.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <param name="entityNameContains">
/// Opt in to a substring match on <paramref name="entityName"/>. This scans, so it is always
/// bounded to a time window: <paramref name="from"/>, or the last 30 days when null.
/// </param>
/// <returns>A task that resolves to a tuple of the matching entries and the total count.</returns>
Task<(IReadOnlyList<AuditLogEntry> Entries, int TotalCount)> GetAuditLogEntriesAsync(
string? user = null,
@@ -73,7 +80,8 @@ public interface ICentralUiRepository
Guid? bundleImportId = null,
int page = 1,
int pageSize = 50,
CancellationToken cancellationToken = default);
CancellationToken cancellationToken = default,
bool entityNameContains = false);
/// <summary>Persists pending changes to the underlying store.</summary>
/// <param name="cancellationToken">Cancellation token.</param>
@@ -21,9 +21,11 @@ namespace ZB.MOM.WW.ScadaBridge.Commons.Types.Deployment;
/// must keep showing its own total while that same status is the active filter.
/// </param>
/// <param name="Search">
/// Free-text term matched (case-insensitively, as a substring) against the
/// instance unique name, the deployment id, the revision hash and the initiating
/// user. Blank/whitespace is treated as unconstrained.
/// Free-text term matched (case-insensitively) against the instance unique name,
/// the deployment id, the revision hash and the initiating user. By default
/// (<see cref="DeploymentSearchMode.Prefix"/>) it is a PREFIX match, which can seek
/// the column indexes; <see cref="DeploymentSearchMode.Contains"/> opts back into the
/// substring match, bounded to a time window. Blank/whitespace is unconstrained.
/// </param>
/// <param name="SiteIdScope">
/// When non-null, restrict to deployments whose instance belongs to one of these
@@ -33,12 +35,33 @@ namespace ZB.MOM.WW.ScadaBridge.Commons.Types.Deployment;
/// "no filter"; <see langword="null"/> is the system-wide case.
/// </param>
/// <param name="InstanceId">Restrict to one instance's deployment history, or <see langword="null"/> for all.</param>
/// <param name="SearchMode">Prefix (default, index-friendly) or bounded Contains. Only meaningful with <paramref name="Search"/>.</param>
/// <param name="DeployedFrom">
/// Lower bound on <c>DeployedAt</c>. Optional for Prefix searches; in Contains mode a
/// window is ALWAYS applied: this value, or the last
/// <see cref="DeploymentListFilter.ContainsDefaultWindow"/> when null.
/// </param>
public sealed record DeploymentListFilter(
DeploymentStatus? Status = null,
string? Search = null,
IReadOnlyCollection<int>? SiteIdScope = null,
int? InstanceId = null)
int? InstanceId = null,
DeploymentSearchMode SearchMode = DeploymentSearchMode.Prefix,
DateTimeOffset? DeployedFrom = null)
{
/// <summary>Time window applied to a Contains search that supplies no explicit <see cref="DeployedFrom"/>.</summary>
public static readonly TimeSpan ContainsDefaultWindow = TimeSpan.FromDays(30);
/// <summary>
/// The effective <c>DeployedAt</c> lower bound at <paramref name="nowUtc"/>: the explicit
/// <see cref="DeployedFrom"/>, else (Contains search only) now minus
/// <see cref="ContainsDefaultWindow"/>, else <see langword="null"/>.
/// </summary>
public DateTimeOffset? EffectiveDeployedFrom(DateTimeOffset nowUtc) =>
DeployedFrom ?? (NormalizedSearch is not null && SearchMode == DeploymentSearchMode.Contains
? nowUtc - ContainsDefaultWindow
: null);
/// <summary>
/// The trimmed search term, or <see langword="null"/> when the term is absent
/// or whitespace-only. Repository implementations use this rather than
@@ -48,3 +71,13 @@ public sealed record DeploymentListFilter(
public string? NormalizedSearch =>
string.IsNullOrWhiteSpace(Search) ? null : Search.Trim();
}
/// <summary>How <see cref="DeploymentListFilter.Search"/> is matched.</summary>
public enum DeploymentSearchMode
{
/// <summary>Case-insensitive prefix (<c>LIKE 'term%'</c>); can use the column indexes.</summary>
Prefix = 0,
/// <summary>Substring (<c>LIKE '%term%'</c>); scans, so it is always bounded by a DeployedAt window.</summary>
Contains = 1,
}