[backend/api-shared] Allow searching for notes with polls

This commit is contained in:
Laura Hausmann 2024-06-05 15:53:57 +02:00
parent e810b00644
commit 1e761f5008
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
3 changed files with 14 additions and 5 deletions

View file

@ -173,7 +173,9 @@ public static class QueryableFtsExtensions
[Projectable]
internal static IQueryable<Note> ApplyRegularAttachmentFilter(this IQueryable<Note> query, AttachmentFilter filter)
=> AttachmentQuery(filter.Value)
? query.Where(p => EF.Functions.ILike(p.RawAttachments, GetAttachmentILikeQuery(filter.Value)))
? filter.Value.Equals(AttachmentFilterType.Poll)
? query.Where(p => p.HasPoll)
: query.Where(p => EF.Functions.ILike(p.RawAttachments, GetAttachmentILikeQuery(filter.Value)))
: filter.Value.Equals(AttachmentFilterType.Any)
? query.Where(p => p.AttachedFileTypes.Count != 0)
: query.Where(p => p.AttachedFileTypes.Count != 0 &&
@ -187,7 +189,9 @@ public static class QueryableFtsExtensions
[Projectable]
internal static IQueryable<Note> ApplyNegatedAttachmentFilter(this IQueryable<Note> query, AttachmentFilter filter)
=> AttachmentQuery(filter.Value)
? query.Where(p => !EF.Functions.ILike(p.RawAttachments, GetAttachmentILikeQuery(filter.Value)))
? filter.Value.Equals(AttachmentFilterType.Poll)
? query.Where(p => !p.HasPoll)
: query.Where(p => !EF.Functions.ILike(p.RawAttachments, GetAttachmentILikeQuery(filter.Value)))
: filter.Value.Equals(AttachmentFilterType.Any)
? query.Where(p => p.AttachedFileTypes.Count == 0)
: query.Where(p => EF.Functions
@ -205,6 +209,8 @@ public static class QueryableFtsExtensions
return true;
if (filter.Equals(AttachmentFilterType.Audio))
return true;
if (filter.Equals(AttachmentFilterType.Poll))
return true;
return false;
}

View file

@ -84,6 +84,7 @@ module SearchQueryFilters =
| Video
| Audio
| File
| Poll
type AttachmentFilter(neg: bool, value: string) =
inherit Filter()
@ -96,6 +97,7 @@ module SearchQueryFilters =
| "video" -> Video
| "audio" -> Audio
| "file" -> File
| "poll" -> Poll
| _ -> failwith $"Invalid type: {value}"
type AfterFilter(d: DateOnly) =
@ -206,7 +208,7 @@ module private SearchQueryParser =
<| fun n v -> InFilter(n.IsSome, v) :> Filter
let attachmentFilter =
negKeyFilter [ "has"; "attachment"; "attached" ] [ "any"; "image"; "video"; "audio"; "file" ]
negKeyFilter [ "has"; "attachment"; "attached" ] [ "any"; "image"; "video"; "audio"; "file"; "poll" ]
<| fun n v -> AttachmentFilter(n.IsSome, v) :> Filter
let afterFilter =

View file

@ -88,7 +88,7 @@ public class SearchQueryTests
{
List<string> keyCandidates = ["has", "attachment", "attached"];
if (negated) keyCandidates = keyCandidates.Select(p => "-" + p).ToList();
List<string> candidates = ["any", "image", "video", "audio", "file"];
List<string> candidates = ["any", "image", "video", "audio", "file", "poll"];
var results =
keyCandidates.Select(k => candidates.Select(v => $"{k}:{v}").SelectMany(SearchQuery.parse).ToList());
List<Filter> expectedResults =
@ -97,7 +97,8 @@ public class SearchQueryTests
new AttachmentFilter(negated, "image"),
new AttachmentFilter(negated, "video"),
new AttachmentFilter(negated, "audio"),
new AttachmentFilter(negated, "file")
new AttachmentFilter(negated, "file"),
new AttachmentFilter(negated, "poll")
];
results.Should()
.HaveCount(keyCandidates.Count)