summaryrefslogtreecommitdiff
path: root/Services
diff options
context:
space:
mode:
authorJake Mannens <jake@asger.xyz>2023-08-25 02:38:38 +1000
committerJake Mannens <jake@asger.xyz>2023-08-25 02:38:38 +1000
commit652a5a558b4b7f811a1a6d433191d16067908898 (patch)
tree87bfae6d6914ae30314226aa07998a9eacd9b71e /Services
parente42cbabf9330a32484e9f0c5aefb87df5ae561eb (diff)
Improved search engine
Diffstat (limited to 'Services')
-rw-r--r--Services/SearchService.cs34
1 files changed, 21 insertions, 13 deletions
diff --git a/Services/SearchService.cs b/Services/SearchService.cs
index cebc704..8a109ea 100644
--- a/Services/SearchService.cs
+++ b/Services/SearchService.cs
@@ -19,20 +19,28 @@ public class SearchService : ISearchService {
var matchedTag = db.TagDefinitions
.FirstOrDefault(td => td.Name.ToLower() == query)?.Guid;
- if(matchedTag is not null)
- return db.Media
- .Include(m => m.Tags)
- .ThenInclude(t => t.TagDefinition)
- .Where(m => m.Tags
- .Select(t => t.TagDefinition)
- .Select(td => td.Guid)
- .Contains((Guid) matchedTag))
- .ToArray();
- var matchingTags = db.TagDefinitions
- .Where(td => td.Name.ToLower().Contains(query))
- .Select(td => td.Guid);
+ Guid[] guids;
+
+ if(matchedTag is not null) {
+ guids = new[] { (Guid) matchedTag };
+ } else {
+ guids = db.TagDefinitions
+ .Where(td => td.Name.ToLower().Contains(query))
+ .Select(td => td.Guid)
+ .ToArray();
+ }
- throw new NotImplementedException();
+ return db.Media
+ .Include(m => m.Tags)
+ .ThenInclude(m => m.TagDefinition)
+ .AsEnumerable()
+ .Where(m => m.Tags.IntersectBy(guids, t => t.TagDefinition.Guid).Any())
+ .Concat(db.Media
+ .Where(m =>
+ (m.ShortDescription != null && m.ShortDescription.ToLower().Contains(query)) ||
+ (m.LongDescription != null && m.LongDescription.ToLower().Contains(query))))
+ .DistinctBy(m => m.Guid)
+ .ToArray();
}
}