feat(search): why this matched highlights (#15)
CI / backend (push) Successful in 50s
CI / frontend (push) Successful in 14s
Deploy Staging / deploy (push) Successful in 29s
Security / secrets (push) Successful in 4s
Security / dependencies (push) Successful in 55s
CI / backend (pull_request) Successful in 47s
CI / frontend (pull_request) Successful in 12s
Security / secrets (pull_request) Successful in 3s
Security / dependencies (pull_request) Successful in 54s
CI / backend (push) Successful in 50s
CI / frontend (push) Successful in 14s
Deploy Staging / deploy (push) Successful in 29s
Security / secrets (push) Successful in 4s
Security / dependencies (push) Successful in 55s
CI / backend (pull_request) Successful in 47s
CI / frontend (pull_request) Successful in 12s
Security / secrets (pull_request) Successful in 3s
Security / dependencies (pull_request) Successful in 54s
This commit was merged in pull request #15.
This commit is contained in:
@@ -16,7 +16,12 @@ public record EmailSummaryDto(
|
||||
long SizeEstimateBytes,
|
||||
EmailCategory Category,
|
||||
bool HasListUnsubscribe,
|
||||
bool SupportsOneClick);
|
||||
bool SupportsOneClick,
|
||||
// "Why this matched": a ts_headline fragment of the body with matched terms wrapped in
|
||||
// U+E000/U+E001 sentinels (NOT HTML — the client renders them as escaped <mark> elements,
|
||||
// so untrusted email content can never inject markup). Null unless the search had a
|
||||
// free-text query. Optional/last so other DTO constructors are unaffected.
|
||||
string? MatchHighlight = null);
|
||||
|
||||
/// <summary>Full single-email view, including body text, for the detail pane.</summary>
|
||||
public record EmailDetailDto(
|
||||
|
||||
@@ -77,15 +77,39 @@ public class SearchService : ISearchService
|
||||
.ThenByDescending(e => e.SentAtUtc)
|
||||
: q.OrderByDescending(e => e.SentAtUtc);
|
||||
|
||||
var items = await ranked
|
||||
.Skip((r.Page - 1) * r.PageSize)
|
||||
.Take(r.PageSize)
|
||||
.Select(e => new EmailSummaryDto(
|
||||
e.Id, e.GmailMessageId, e.Subject, e.Snippet,
|
||||
e.Sender!.Address, e.Sender.DisplayName, e.SentAtUtc,
|
||||
e.IsUnread, e.IsStarred, e.HasAttachments, e.SizeEstimateBytes, e.Category,
|
||||
e.HasListUnsubscribe, e.SupportsOneClickUnsubscribe))
|
||||
.ToListAsync(ct);
|
||||
var paged = ranked.Skip((r.Page - 1) * r.PageSize).Take(r.PageSize);
|
||||
|
||||
// Two unconditional projections (no DB function inside a C# ternary → no doubt about
|
||||
// EF translation). The browse path never touches ts_headline, so it's byte-for-byte
|
||||
// unchanged AND safe under the InMemory test provider.
|
||||
List<EmailSummaryDto> items;
|
||||
if (hasFreeTextQuery)
|
||||
{
|
||||
// "Why this matched": ts_headline body fragment with matched terms wrapped in
|
||||
// U+E000/U+E001 sentinels (safe, non-HTML — the client renders them as escaped
|
||||
// <mark> spans; see EmailSummaryDto).
|
||||
var headlineOpts =
|
||||
$"StartSel={(char)0xE000},StopSel={(char)0xE001},MaxWords=16,MinWords=5,ShortWord=2,HighlightAll=false";
|
||||
items = await paged
|
||||
.Select(e => new EmailSummaryDto(
|
||||
e.Id, e.GmailMessageId, e.Subject, e.Snippet,
|
||||
e.Sender!.Address, e.Sender.DisplayName, e.SentAtUtc,
|
||||
e.IsUnread, e.IsStarred, e.HasAttachments, e.SizeEstimateBytes, e.Category,
|
||||
e.HasListUnsubscribe, e.SupportsOneClickUnsubscribe,
|
||||
EF.Functions.WebSearchToTsQuery("english", term).GetResultHeadline("english", e.BodyText ?? "", headlineOpts)))
|
||||
.ToListAsync(ct);
|
||||
}
|
||||
else
|
||||
{
|
||||
items = await paged
|
||||
.Select(e => new EmailSummaryDto(
|
||||
e.Id, e.GmailMessageId, e.Subject, e.Snippet,
|
||||
e.Sender!.Address, e.Sender.DisplayName, e.SentAtUtc,
|
||||
e.IsUnread, e.IsStarred, e.HasAttachments, e.SizeEstimateBytes, e.Category,
|
||||
e.HasListUnsubscribe, e.SupportsOneClickUnsubscribe,
|
||||
null))
|
||||
.ToListAsync(ct);
|
||||
}
|
||||
|
||||
return new PagedResult<EmailSummaryDto>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user