[parsing] Add support for has:media search query

This commit is contained in:
Laura Hausmann 2024-11-11 01:52:48 +01:00
parent 43ed9d4c5d
commit 2b046fc444
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
3 changed files with 8 additions and 6 deletions

View file

@ -182,7 +182,7 @@ public static class QueryableFtsExtensions
private static IQueryable<Note> ApplyRegularAttachmentFilter(this IQueryable<Note> query, AttachmentFilter filter)
{
if (filter.Value.IsAny)
if (filter.Value.IsMedia)
return query.Where(p => p.AttachedFileTypes.Count != 0);
if (filter.Value.IsPoll)
return query.Where(p => p.HasPoll);
@ -209,7 +209,7 @@ public static class QueryableFtsExtensions
private static IQueryable<Note> ApplyNegatedAttachmentFilter(this IQueryable<Note> query, AttachmentFilter filter)
{
if (filter.Value.IsAny)
if (filter.Value.IsMedia)
return query.Where(p => p.AttachedFileTypes.Count == 0);
if (filter.Value.IsPoll)
return query.Where(p => !p.HasPoll);

View file

@ -84,7 +84,7 @@ module SearchQueryFilters =
type AttachmentFilterType =
| Any
| Media
| Image
| Video
| Audio
@ -97,7 +97,8 @@ module SearchQueryFilters =
member val Value =
match value with
| "any" -> Any
| "any" -> Media
| "media" -> Media
| "image" -> Image
| "video" -> Video
| "audio" -> Audio
@ -215,7 +216,7 @@ module private SearchQueryParser =
<| fun n v -> InFilter(n.IsSome, v) :> Filter
let attachmentFilter =
negKeyFilter [ "has"; "attachment"; "attached" ] [ "any"; "image"; "video"; "audio"; "file"; "poll" ]
negKeyFilter [ "has"; "attachment"; "attached" ] [ "any"; "media"; "image"; "video"; "audio"; "file"; "poll" ]
<| fun n v -> AttachmentFilter(n.IsSome, v) :> Filter
let afterFilter =

View file

@ -98,12 +98,13 @@ 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", "poll"];
List<string> candidates = ["any", "media", "image", "video", "audio", "file", "poll"];
var results =
keyCandidates.Select(k => candidates.Select(v => $"{k}:{v}").SelectMany(SearchQuery.parse).ToList());
List<Filter> expectedResults =
[
new AttachmentFilter(negated, "any"),
new AttachmentFilter(negated, "media"),
new AttachmentFilter(negated, "image"),
new AttachmentFilter(negated, "video"),
new AttachmentFilter(negated, "audio"),