#154 : Première optimisation de la recherche
This commit is contained in:
@@ -8,52 +8,32 @@ namespace Webzine.WebApplication.Controllers
|
||||
|
||||
using Webzine.Repository.Contracts;
|
||||
using Webzine.WebApplication.ViewModels.Recherche;
|
||||
using Webzine.WebApplication.ViewModels.Titre;
|
||||
|
||||
[Route("recherche")]
|
||||
public class RechercheController : Controller
|
||||
{
|
||||
private readonly ILogger<RechercheController> logger;
|
||||
private readonly ITitreRepository titreRepository;
|
||||
private readonly IArtisteRepository artisteRepository;
|
||||
|
||||
public RechercheController(ILogger<RechercheController> logger, ITitreRepository titreRepository)
|
||||
public RechercheController(
|
||||
ILogger<RechercheController> logger,
|
||||
ITitreRepository titreRepository,
|
||||
IArtisteRepository artisteRepository)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.titreRepository = titreRepository;
|
||||
this.artisteRepository = artisteRepository;
|
||||
}
|
||||
|
||||
[HttpPost("")]
|
||||
public IActionResult Index(string mot)
|
||||
{
|
||||
this.logger.LogInformation("Recherche artistes/titres pour le mot : {Mot}.", mot);
|
||||
|
||||
var titres = this.titreRepository.Search(mot)
|
||||
.Concat(this.titreRepository.SearchByStyle(mot))
|
||||
.DistinctBy(t => t.IdTitre)
|
||||
.OrderBy(t => t.Libelle)
|
||||
.Select(t => new TitreStyleItem
|
||||
{
|
||||
IdTitre = t.IdTitre,
|
||||
Libelle = t.Libelle,
|
||||
ArtisteNom = t.Artiste?.Nom,
|
||||
UrlJaquette = t.UrlJaquette,
|
||||
Duree = t.Duree,
|
||||
})
|
||||
.ToList();
|
||||
var titres = this.titreRepository.Search(mot).ToList();
|
||||
|
||||
var artistes = this.titreRepository.FindAll()
|
||||
.Select(t => t.Artiste)
|
||||
.Where(a => a != null
|
||||
&& !string.IsNullOrWhiteSpace(a.Nom)
|
||||
&& !string.IsNullOrWhiteSpace(mot)
|
||||
&& a.Nom.Contains(mot, StringComparison.OrdinalIgnoreCase))
|
||||
.DistinctBy(a => a!.IdArtiste)
|
||||
.OrderBy(a => a!.Nom)
|
||||
.Select(a => new RechercheArtisteItem
|
||||
{
|
||||
Nom = a!.Nom,
|
||||
NombreDeTitres = a.Titres?.Count ?? 0,
|
||||
})
|
||||
var artistes = this.artisteRepository
|
||||
.FindAll()
|
||||
.Where(a => a.Nom.ToLower().Contains(mot.ToLower()))
|
||||
.ToList();
|
||||
|
||||
var vm = new RechercheIndexViewModel
|
||||
|
||||
Reference in New Issue
Block a user