[backend/api-shared] Allow searching for notes with polls
This commit is contained in:
parent
e810b00644
commit
1e761f5008
3 changed files with 14 additions and 5 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue