Major Search Enhancements (#1238)

* Pull progress information for some of the recommended stuff.

* Fixed some redirection code from last PR

* Implemented the ability to search for files in the search and open the series directly.

* Fixed nav search bar expanding too much

* Fixed a bug in nav module not having router so some links broke

* Fixed an issue where with new localized series tag, merging could fail if the user had 2 series with the series and localized series.

Added extra error handling for tracking series parsed from disk.

* Fixed the slowness when typing in a typeahead by using auditTime vs debounceTime

* Removed some cleaning of Edition tags from the Parser. Only Omnibus and Uncensored will be ignored when cleaning titles, Full Color, Full Contact, etc will now stay in the title for Series name.

* Implemented ability to search against chapter's title (from epub or title in comicinfo). This should help users search for books in a series a lot easier.

* Restrict each search type to 15 records only to keep query performant and UI useful.

* Wrote some extra messaging on invite user flow around email.

* Messaging update
This commit is contained in:
Joseph Milazzo 2022-04-30 12:09:54 -05:00 committed by GitHub
parent a2d5ee18a0
commit d411ab03f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 244 additions and 49 deletions

View file

@ -30,6 +30,7 @@ public class RecommendedController : BaseApiController
userParams ??= new UserParams();
var series = await _unitOfWork.SeriesRepository.GetQuickReads(user.Id, libraryId, userParams);
Response.AddPaginationHeader(series.CurrentPage, series.PageSize, series.TotalCount, series.TotalPages);
return Ok(series);
}
@ -46,6 +47,7 @@ public class RecommendedController : BaseApiController
userParams ??= new UserParams();
var series = await _unitOfWork.SeriesRepository.GetHighlyRated(user.Id, libraryId, userParams);
await _unitOfWork.SeriesRepository.AddSeriesModifiers(user.Id, series);
Response.AddPaginationHeader(series.CurrentPage, series.PageSize, series.TotalCount, series.TotalPages);
return Ok(series);
}
@ -62,6 +64,8 @@ public class RecommendedController : BaseApiController
userParams ??= new UserParams();
var series = await _unitOfWork.SeriesRepository.GetMoreIn(user.Id, libraryId, genreId, userParams);
await _unitOfWork.SeriesRepository.AddSeriesModifiers(user.Id, series);
Response.AddPaginationHeader(series.CurrentPage, series.PageSize, series.TotalCount, series.TotalPages);
return Ok(series);
}

View file

@ -342,6 +342,32 @@ namespace API.Controllers
return await _seriesService.GetSeriesDetail(seriesId, userId);
}
/// <summary>
/// Returns the series for the MangaFile id. If the user does not have access (shouldn't happen by the UI),
/// then null is returned
/// </summary>
/// <param name="mangaFileId"></param>
/// <returns></returns>
[HttpGet("series-for-mangafile")]
public async Task<ActionResult<SeriesDto>> GetSeriesForMangaFile(int mangaFileId)
{
var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
return Ok(await _unitOfWork.SeriesRepository.GetSeriesForMangaFile(mangaFileId, userId));
}
/// <summary>
/// Returns the series for the Chapter id. If the user does not have access (shouldn't happen by the UI),
/// then null is returned
/// </summary>
/// <param name="chapterId"></param>
/// <returns></returns>
[HttpGet("series-for-chapter")]
public async Task<ActionResult<SeriesDto>> GetSeriesForChapter(int chapterId)
{
var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
return Ok(await _unitOfWork.SeriesRepository.GetSeriesForChapter(chapterId, userId));
}
/// <summary>
/// Fetches the related series for a given series
/// </summary>

View file

@ -4,9 +4,10 @@ namespace API.DTOs
{
public class MangaFileDto
{
public int Id { get; init; }
public string FilePath { get; init; }
public int Pages { get; init; }
public MangaFormat Format { get; init; }
}
}
}

View file

@ -17,5 +17,8 @@ public class SearchResultGroupDto
public IEnumerable<PersonDto> Persons { get; set; }
public IEnumerable<GenreTagDto> Genres { get; set; }
public IEnumerable<TagDto> Tags { get; set; }
public IEnumerable<MangaFileDto> Files { get; set; }
public IEnumerable<ChapterDto> Chapters { get; set; }
}

View file

@ -21,7 +21,9 @@ using API.Services.Tasks;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using Kavita.Common.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using SQLitePCL;
namespace API.Data.Repositories;
@ -115,6 +117,8 @@ public interface ISeriesRepository
Task<PagedList<SeriesDto>> GetHighlyRated(int userId, int libraryId, UserParams userParams);
Task<PagedList<SeriesDto>> GetMoreIn(int userId, int libraryId, int genreId, UserParams userParams);
Task<PagedList<SeriesDto>> GetRediscover(int userId, int libraryId, UserParams userParams);
Task<SeriesDto> GetSeriesForMangaFile(int mangaFileId, int userId);
Task<SeriesDto> GetSeriesForChapter(int chapterId, int userId);
}
public class SeriesRepository : ISeriesRepository
@ -287,7 +291,7 @@ public class SeriesRepository : ISeriesRepository
public async Task<SearchResultGroupDto> SearchSeries(int userId, bool isAdmin, int[] libraryIds, string searchQuery)
{
const int maxRecords = 15;
var result = new SearchResultGroupDto();
var searchQueryNormalized = Parser.Parser.Normalize(searchQuery);
@ -301,6 +305,7 @@ public class SeriesRepository : ISeriesRepository
.Where(l => EF.Functions.Like(l.Name, $"%{searchQuery}%"))
.OrderBy(l => l.Name)
.AsSplitQuery()
.Take(maxRecords)
.ProjectTo<LibraryDto>(_mapper.ConfigurationProvider)
.ToListAsync();
@ -308,7 +313,7 @@ public class SeriesRepository : ISeriesRepository
var hasYearInQuery = !string.IsNullOrEmpty(justYear);
var yearComparison = hasYearInQuery ? int.Parse(justYear) : 0;
result.Series = await _context.Series
result.Series = _context.Series
.Where(s => libraryIds.Contains(s.LibraryId))
.Where(s => EF.Functions.Like(s.Name, $"%{searchQuery}%")
|| EF.Functions.Like(s.OriginalName, $"%{searchQuery}%")
@ -319,14 +324,16 @@ public class SeriesRepository : ISeriesRepository
.OrderBy(s => s.SortName)
.AsNoTracking()
.AsSplitQuery()
.Take(maxRecords)
.ProjectTo<SearchResultDto>(_mapper.ConfigurationProvider)
.ToListAsync();
.AsEnumerable();
result.ReadingLists = await _context.ReadingList
.Where(rl => rl.AppUserId == userId || rl.Promoted)
.Where(rl => EF.Functions.Like(rl.Title, $"%{searchQuery}%"))
.AsSplitQuery()
.Take(maxRecords)
.ProjectTo<ReadingListDto>(_mapper.ConfigurationProvider)
.ToListAsync();
@ -336,6 +343,8 @@ public class SeriesRepository : ISeriesRepository
.Where(s => s.Promoted || isAdmin)
.OrderBy(s => s.Title)
.AsNoTracking()
.AsSplitQuery()
.Take(maxRecords)
.OrderBy(c => c.NormalizedTitle)
.ProjectTo<CollectionTagDto>(_mapper.ConfigurationProvider)
.ToListAsync();
@ -344,6 +353,7 @@ public class SeriesRepository : ISeriesRepository
.Where(sm => seriesIds.Contains(sm.SeriesId))
.SelectMany(sm => sm.People.Where(t => EF.Functions.Like(t.Name, $"%{searchQuery}%")))
.AsSplitQuery()
.Take(maxRecords)
.Distinct()
.ProjectTo<PersonDto>(_mapper.ConfigurationProvider)
.ToListAsync();
@ -354,6 +364,7 @@ public class SeriesRepository : ISeriesRepository
.AsSplitQuery()
.OrderBy(t => t.Title)
.Distinct()
.Take(maxRecords)
.ProjectTo<GenreTagDto>(_mapper.ConfigurationProvider)
.ToListAsync();
@ -363,9 +374,34 @@ public class SeriesRepository : ISeriesRepository
.AsSplitQuery()
.OrderBy(t => t.Title)
.Distinct()
.Take(maxRecords)
.ProjectTo<TagDto>(_mapper.ConfigurationProvider)
.ToListAsync();
var fileIds = _context.Series
.Where(s => libraryIds.Contains(s.LibraryId))
.AsSplitQuery()
.SelectMany(s => s.Volumes)
.SelectMany(v => v.Chapters)
.SelectMany(c => c.Files.Select(f => f.Id));
result.Files = await _context.MangaFile
.Where(m => EF.Functions.Like(m.FilePath, $"%{searchQuery}%") && fileIds.Contains(m.Id))
.AsSplitQuery()
.Take(maxRecords)
.ProjectTo<MangaFileDto>(_mapper.ConfigurationProvider)
.ToListAsync();
result.Chapters = await _context.Chapter
.Include(c => c.Files)
.Where(c => EF.Functions.Like(c.TitleName, $"%{searchQuery}%"))
.Where(c => c.Files.All(f => fileIds.Contains(f.Id)))
.AsSplitQuery()
.Take(maxRecords)
.ProjectTo<ChapterDto>(_mapper.ConfigurationProvider)
.ToListAsync();
return result;
}
@ -1044,6 +1080,33 @@ public class SeriesRepository : ISeriesRepository
return await PagedList<SeriesDto>.CreateAsync(query, userParams.PageNumber, userParams.PageSize);
}
public async Task<SeriesDto> GetSeriesForMangaFile(int mangaFileId, int userId)
{
var libraryIds = GetLibraryIdsForUser(userId);
return await _context.MangaFile
.Where(m => m.Id == mangaFileId)
.AsSplitQuery()
.Select(f => f.Chapter)
.Select(c => c.Volume)
.Select(v => v.Series)
.Where(s => libraryIds.Contains(s.LibraryId))
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)
.SingleOrDefaultAsync();
}
public async Task<SeriesDto> GetSeriesForChapter(int chapterId, int userId)
{
var libraryIds = GetLibraryIdsForUser(userId);
return await _context.Chapter
.Where(m => m.Id == chapterId)
.AsSplitQuery()
.Select(c => c.Volume)
.Select(v => v.Series)
.Where(s => libraryIds.Contains(s.LibraryId))
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)
.SingleOrDefaultAsync();
}
public async Task<PagedList<SeriesDto>> GetHighlyRated(int userId, int libraryId, UserParams userParams)
{

View file

@ -452,10 +452,6 @@ namespace API.Parser
};
private static readonly Regex[] MangaEditionRegex = {
// Tenjo Tenge {Full Contact Edition} v01 (2011) (Digital) (ASTC).cbz
new Regex(
@"(?<Edition>({|\(|\[).* Edition(}|\)|\]))",
MatchOptions, RegexTimeout),
// Tenjo Tenge {Full Contact Edition} v01 (2011) (Digital) (ASTC).cbz
new Regex(
@"(\b|_)(?<Edition>Omnibus(( |_)?Edition)?)(\b|_)?",
MatchOptions, RegexTimeout),
@ -463,10 +459,6 @@ namespace API.Parser
new Regex(
@"(\b|_)(?<Edition>Uncensored)(\b|_)",
MatchOptions, RegexTimeout),
// AKIRA - c003 (v01) [Full Color] [Darkhorse].cbz
new Regex(
@"(\b|_)(?<Edition>Full(?: |_)Color)(\b|_)?",
MatchOptions, RegexTimeout),
};
private static readonly Regex[] CleanupRegex =

View file

@ -4,6 +4,7 @@ using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using API.Archive;

View file

@ -133,7 +133,14 @@ namespace API.Services.Tasks.Scanner
}
}
TrackSeries(info);
try
{
TrackSeries(info);
}
catch (Exception ex)
{
_logger.LogError(ex, "There was an exception that occurred during tracking {FilePath}. Skipping this file", info.FullFilePath);
}
}
@ -183,8 +190,9 @@ namespace API.Services.Tasks.Scanner
{
var normalizedSeries = Parser.Parser.Normalize(info.Series);
var normalizedLocalSeries = Parser.Parser.Normalize(info.LocalizedSeries);
// We use FirstOrDefault because this was introduced late in development and users might have 2 series with both names
var existingName =
_scannedSeries.SingleOrDefault(p =>
_scannedSeries.FirstOrDefault(p =>
(Parser.Parser.Normalize(p.Key.NormalizedName) == normalizedSeries ||
Parser.Parser.Normalize(p.Key.NormalizedName) == normalizedLocalSeries) && p.Key.Format == info.Format)
.Key;

View file

@ -195,7 +195,7 @@ public class ScannerService : IScannerService
// Check if any of the folder roots are not available (ie disconnected from network, etc) and fail if any of them are
if (folders.Any(f => !_directoryService.IsDriveMounted(f)))
{
_logger.LogError("Some of the root folders for library ({LibraryName} are not accessible. Please check that drives are connected and rescan. Scan will be aborted", libraryName);
_logger.LogCritical("Some of the root folders for library ({LibraryName} are not accessible. Please check that drives are connected and rescan. Scan will be aborted", libraryName);
await _eventHub.SendMessageAsync(MessageFactory.Error,
MessageFactory.ErrorEvent("Some of the root folders for library are not accessible. Please check that drives are connected and rescan. Scan will be aborted",
@ -267,6 +267,7 @@ public class ScannerService : IScannerService
if (!await CheckMounts(library.Name, library.Folders.Select(f => f.Path).ToList()))
{
_logger.LogCritical("Some of the root folders for library are not accessible. Please check that drives are connected and rescan. Scan will be aborted");
return;
}