[parsing] Add support for has:media search query
This commit is contained in:
parent
43ed9d4c5d
commit
2b046fc444
3 changed files with 8 additions and 6 deletions
|
@ -182,7 +182,7 @@ public static class QueryableFtsExtensions
|
||||||
|
|
||||||
private static IQueryable<Note> ApplyRegularAttachmentFilter(this IQueryable<Note> query, AttachmentFilter filter)
|
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);
|
return query.Where(p => p.AttachedFileTypes.Count != 0);
|
||||||
if (filter.Value.IsPoll)
|
if (filter.Value.IsPoll)
|
||||||
return query.Where(p => p.HasPoll);
|
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)
|
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);
|
return query.Where(p => p.AttachedFileTypes.Count == 0);
|
||||||
if (filter.Value.IsPoll)
|
if (filter.Value.IsPoll)
|
||||||
return query.Where(p => !p.HasPoll);
|
return query.Where(p => !p.HasPoll);
|
||||||
|
|
|
@ -84,7 +84,7 @@ module SearchQueryFilters =
|
||||||
|
|
||||||
|
|
||||||
type AttachmentFilterType =
|
type AttachmentFilterType =
|
||||||
| Any
|
| Media
|
||||||
| Image
|
| Image
|
||||||
| Video
|
| Video
|
||||||
| Audio
|
| Audio
|
||||||
|
@ -97,7 +97,8 @@ module SearchQueryFilters =
|
||||||
|
|
||||||
member val Value =
|
member val Value =
|
||||||
match value with
|
match value with
|
||||||
| "any" -> Any
|
| "any" -> Media
|
||||||
|
| "media" -> Media
|
||||||
| "image" -> Image
|
| "image" -> Image
|
||||||
| "video" -> Video
|
| "video" -> Video
|
||||||
| "audio" -> Audio
|
| "audio" -> Audio
|
||||||
|
@ -215,7 +216,7 @@ module private SearchQueryParser =
|
||||||
<| fun n v -> InFilter(n.IsSome, v) :> Filter
|
<| fun n v -> InFilter(n.IsSome, v) :> Filter
|
||||||
|
|
||||||
let attachmentFilter =
|
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
|
<| fun n v -> AttachmentFilter(n.IsSome, v) :> Filter
|
||||||
|
|
||||||
let afterFilter =
|
let afterFilter =
|
||||||
|
|
|
@ -98,12 +98,13 @@ public class SearchQueryTests
|
||||||
{
|
{
|
||||||
List<string> keyCandidates = ["has", "attachment", "attached"];
|
List<string> keyCandidates = ["has", "attachment", "attached"];
|
||||||
if (negated) keyCandidates = keyCandidates.Select(p => "-" + p).ToList();
|
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 =
|
var results =
|
||||||
keyCandidates.Select(k => candidates.Select(v => $"{k}:{v}").SelectMany(SearchQuery.parse).ToList());
|
keyCandidates.Select(k => candidates.Select(v => $"{k}:{v}").SelectMany(SearchQuery.parse).ToList());
|
||||||
List<Filter> expectedResults =
|
List<Filter> expectedResults =
|
||||||
[
|
[
|
||||||
new AttachmentFilter(negated, "any"),
|
new AttachmentFilter(negated, "any"),
|
||||||
|
new AttachmentFilter(negated, "media"),
|
||||||
new AttachmentFilter(negated, "image"),
|
new AttachmentFilter(negated, "image"),
|
||||||
new AttachmentFilter(negated, "video"),
|
new AttachmentFilter(negated, "video"),
|
||||||
new AttachmentFilter(negated, "audio"),
|
new AttachmentFilter(negated, "audio"),
|
||||||
|
|
Loading…
Add table
Reference in a new issue