Updated search logic. More UI updates.
This commit is contained in:
@@ -5,6 +5,7 @@ using JSMR.Domain.Enums;
|
||||
using JSMR.Infrastructure.Common.Queries;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq.Expressions;
|
||||
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
||||
using CircleStatus = JSMR.Application.VoiceWorks.Queries.Search.CircleStatus;
|
||||
|
||||
namespace JSMR.Infrastructure.Data.Repositories.VoiceWorks;
|
||||
@@ -20,6 +21,8 @@ public class VoiceWorkQuery
|
||||
|
||||
public class VoiceWorkSearchProvider(AppDbContext context, IVoiceWorkFullTextSearch fullTextSearch) : SearchProvider<VoiceWorkSearchResult, VoiceWorkSearchCriteria, VoiceWorkSortField, VoiceWorkQuery>, IVoiceWorkSearchProvider
|
||||
{
|
||||
protected override bool UseSelectIdQuery => true;
|
||||
|
||||
protected override IQueryable<VoiceWorkQuery> GetBaseQuery()
|
||||
{
|
||||
return
|
||||
@@ -45,14 +48,6 @@ public class VoiceWorkSearchProvider(AppDbContext context, IVoiceWorkFullTextSea
|
||||
IQueryable<VoiceWorkQuery> filteredQuery = query;
|
||||
|
||||
filteredQuery = ApplyKeywordsFilter(filteredQuery, criteria);
|
||||
filteredQuery = ApplyCircleStatusFilter(filteredQuery, criteria);
|
||||
filteredQuery = ApplyTagStatusFilter(filteredQuery, criteria);
|
||||
filteredQuery = ApplyCreatorStatusFilter(filteredQuery, criteria);
|
||||
filteredQuery = ApplyTagIdsFilter(filteredQuery, criteria);
|
||||
filteredQuery = ApplyCreatorIdsFilter(filteredQuery, criteria);
|
||||
|
||||
if (criteria.Status is not null)
|
||||
filteredQuery = filteredQuery.Where(x => x.VoiceWork.Status == (byte)criteria.Status);
|
||||
|
||||
switch (criteria.SaleStatus)
|
||||
{
|
||||
@@ -64,6 +59,18 @@ public class VoiceWorkSearchProvider(AppDbContext context, IVoiceWorkFullTextSea
|
||||
break;
|
||||
}
|
||||
|
||||
if (criteria.SupportedLanguages.Length > 0)
|
||||
filteredQuery = filteredQuery.Where(x => criteria.SupportedLanguages.Contains((Language)x.VoiceWork.SubtitleLanguage));
|
||||
|
||||
filteredQuery = ApplyCircleStatusFilter(filteredQuery, criteria);
|
||||
filteredQuery = ApplyTagStatusFilter(filteredQuery, criteria);
|
||||
filteredQuery = ApplyCreatorStatusFilter(filteredQuery, criteria);
|
||||
filteredQuery = ApplyTagIdsFilter(filteredQuery, criteria);
|
||||
filteredQuery = ApplyCreatorIdsFilter(filteredQuery, criteria);
|
||||
|
||||
if (criteria.Status is not null)
|
||||
filteredQuery = filteredQuery.Where(x => x.VoiceWork.Status == (byte)criteria.Status);
|
||||
|
||||
if (criteria.ScheduledReleaseDateStart is not null)
|
||||
filteredQuery = filteredQuery.Where(x => x.VoiceWork.PlannedReleaseDate >= criteria.ScheduledReleaseDateStart.Value.ToDateTime(TimeOnly.MinValue));
|
||||
|
||||
@@ -79,8 +86,8 @@ public class VoiceWorkSearchProvider(AppDbContext context, IVoiceWorkFullTextSea
|
||||
if (criteria.AgeRatings.Length > 0)
|
||||
filteredQuery = filteredQuery.Where(x => criteria.AgeRatings.Contains((AgeRating)x.VoiceWork.Rating));
|
||||
|
||||
if (criteria.SupportedLanguages.Length > 0)
|
||||
filteredQuery = filteredQuery.Where(x => criteria.SupportedLanguages.Contains((Language)x.VoiceWork.SubtitleLanguage));
|
||||
//if (criteria.SupportedLanguages.Length > 0)
|
||||
// filteredQuery = filteredQuery.Where(x => criteria.SupportedLanguages.Contains((Language)x.VoiceWork.SubtitleLanguage));
|
||||
|
||||
if (criteria.AIGenerationOptions.Length > 0)
|
||||
filteredQuery = filteredQuery.Where(x => criteria.AIGenerationOptions.Contains((AIGeneration)x.VoiceWork.AIGeneration));
|
||||
@@ -133,6 +140,19 @@ public class VoiceWorkSearchProvider(AppDbContext context, IVoiceWorkFullTextSea
|
||||
break;
|
||||
}
|
||||
|
||||
//switch (criteria.CircleStatus)
|
||||
//{
|
||||
// case CircleStatus.NotBlacklisted:
|
||||
// query = query.Where(x => x.Circle.Blacklisted == false);
|
||||
// break;
|
||||
// case CircleStatus.Favorited:
|
||||
// query = query.Where(x => x.Circle.Favorite);
|
||||
// break;
|
||||
// case CircleStatus.Blacklisted:
|
||||
// query = query.Where(x => x.Circle.Blacklisted);
|
||||
// break;
|
||||
//}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
@@ -314,13 +334,15 @@ public class VoiceWorkSearchProvider(AppDbContext context, IVoiceWorkFullTextSea
|
||||
|
||||
protected override IEnumerable<(Expression<Func<VoiceWorkQuery, object>> Selector, SortDirection Dir)> GetDefaultSortChain()
|
||||
{
|
||||
yield return (x => x.VoiceWork.ProductId, SortDirection.Ascending);
|
||||
yield return (x => x.VoiceWork.ProductId, SortDirection.Descending);
|
||||
}
|
||||
|
||||
protected override Expression<Func<VoiceWorkQuery, object>> GetSortExpression(VoiceWorkSortField field) => field switch
|
||||
protected override Expression<Func<VoiceWorkQuery, object?>> GetSortExpression(VoiceWorkSortField field) => field switch
|
||||
{
|
||||
VoiceWorkSortField.ScheduledReleaseDate => x => x.VoiceWork.PlannedReleaseDate ?? x.VoiceWork.PlannedReleaseDate ?? DateTime.MinValue,
|
||||
VoiceWorkSortField.ReleaseDate => x => x.VoiceWork.SalesDate ?? x.VoiceWork.ExpectedDate ?? DateTime.MinValue,
|
||||
VoiceWorkSortField.ExpectedReleaseDate => x => x.VoiceWork.ExpectedDate,
|
||||
VoiceWorkSortField.ScheduledReleaseDate => x => x.VoiceWork.PlannedReleaseDate,
|
||||
VoiceWorkSortField.ReleaseDate => x => x.VoiceWork.SalesDate,
|
||||
VoiceWorkSortField.AnyReleaseDate => x => x.VoiceWork.SalesDate ?? x.VoiceWork.PlannedReleaseDate ?? x.VoiceWork.ExpectedDate,
|
||||
VoiceWorkSortField.Downloads => x => x.VoiceWork.Downloads ?? 0,
|
||||
VoiceWorkSortField.WishlistCount => x => x.VoiceWork.WishlistCount ?? 0,
|
||||
VoiceWorkSortField.StarRating => x => x.VoiceWork.StarRating ?? 0,
|
||||
@@ -328,6 +350,11 @@ public class VoiceWorkSearchProvider(AppDbContext context, IVoiceWorkFullTextSea
|
||||
_ => x => x.VoiceWork.ProductId
|
||||
};
|
||||
|
||||
protected override IQueryable<int> GetSelectIdQuery(IOrderedQueryable<VoiceWorkQuery> query)
|
||||
{
|
||||
return query.Select(x => x.VoiceWork.VoiceWorkId);
|
||||
}
|
||||
|
||||
protected override IQueryable<VoiceWorkSearchResult> GetSelectQuery(IOrderedQueryable<VoiceWorkQuery> query)
|
||||
{
|
||||
var result =
|
||||
@@ -363,6 +390,43 @@ public class VoiceWorkSearchProvider(AppDbContext context, IVoiceWorkFullTextSea
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override async Task<Dictionary<int, VoiceWorkSearchResult>> GetItems(int[] ids)
|
||||
{
|
||||
var result =
|
||||
from voiceWork in context.VoiceWorks.AsNoTracking()
|
||||
join englishVoiceWork in context.EnglishVoiceWorks.AsNoTracking() on voiceWork.VoiceWorkId equals englishVoiceWork.VoiceWorkId into ps
|
||||
from englishVoiceWork in ps.DefaultIfEmpty()
|
||||
join circle in context.Circles.AsNoTracking() on voiceWork.CircleId equals circle.CircleId into cs
|
||||
from circle in cs.DefaultIfEmpty()
|
||||
let productLinkPage = voiceWork.SalesDate.HasValue ? "work" : "announce"
|
||||
where ids.Contains(voiceWork.VoiceWorkId)
|
||||
select new VoiceWorkSearchResult()
|
||||
{
|
||||
VoiceWorkId = voiceWork.VoiceWorkId,
|
||||
ProductId = voiceWork.ProductId,
|
||||
OriginalProductId = voiceWork.OriginalProductId,
|
||||
ProductName = englishVoiceWork != null ? englishVoiceWork.ProductName : voiceWork.ProductName,
|
||||
ProductUrl = "http://www.dlsite.com/maniax/" + productLinkPage + "/=/product_id/" + voiceWork.ProductId + ".html",
|
||||
Description = englishVoiceWork != null ? englishVoiceWork.Description : voiceWork.Description,
|
||||
Favorite = voiceWork.Favorite,
|
||||
HasImage = voiceWork.HasImage,
|
||||
Maker = circle.Name,
|
||||
MakerId = circle.MakerId,
|
||||
ExpectedDate = voiceWork.ExpectedDate,
|
||||
SalesDate = voiceWork.SalesDate,
|
||||
PlannedReleaseDate = voiceWork.PlannedReleaseDate,
|
||||
Downloads = voiceWork.Downloads,
|
||||
WishlistCount = voiceWork.WishlistCount,
|
||||
Status = voiceWork.Status,
|
||||
SubtitleLanguage = voiceWork.SubtitleLanguage,
|
||||
HasTrial = voiceWork.HasTrial,
|
||||
HasChobit = voiceWork.HasChobit,
|
||||
IsValid = voiceWork.IsValid
|
||||
};
|
||||
|
||||
return await result.ToDictionaryAsync(x => x.VoiceWorkId);
|
||||
}
|
||||
|
||||
protected override async Task PostLoadAsync(IList<VoiceWorkSearchResult> items, CancellationToken cancellationToken)
|
||||
{
|
||||
if (items.Count == 0)
|
||||
|
||||
Reference in New Issue
Block a user