react-version #1

Merged
memartel_loc merged 290 commits from react-version into main 2023-11-04 09:48:15 -04:00
Showing only changes of commit cdd0927796 - Show all commits

View File

@ -22,7 +22,7 @@ public class SearchController : Controller {
_logger = logger; _logger = logger;
_context = context; _context = context;
_cache = cache; _cache = cache;
if (_cache.isOk()) if (_cache.isOk()) // Se fait une copie de la cache si elle est fonctionnelle.
_searchCache = _cache.GetCacheCopy(); _searchCache = _cache.GetCacheCopy();
} }
@ -43,7 +43,7 @@ public class SearchController : Controller {
if (deep.HasValue && deep == true) { if (deep.HasValue && deep == true) {
List<Product> title = new(), desc = new(), cat = new(); List<Product> title = new(), desc = new(), cat = new();
query = query.ToLower(); query = query.ToLower();
foreach (Product prod in _context.Products.ToList()) { foreach (Product prod in _context.Products.ToArray()) {
string sTitle = prod.Title.Replace(",", " ").ToLower(), string sTitle = prod.Title.Replace(",", " ").ToLower(),
sCat = prod.Category.ToLower(), sCat = prod.Category.ToLower(),
sDesc = prod.Description.Replace(".", " ").Replace(",", " ").ToLower(); sDesc = prod.Description.Replace(".", " ").Replace(",", " ").ToLower();
@ -61,10 +61,10 @@ public class SearchController : Controller {
products.AddRange(cat); products.AddRange(cat);
} else { } else {
products = _context.Products.Where(x => x.Title.Contains(query)).ToList(); products = _context.Products.Where(x => x.Title.Contains(query)).ToList();
foreach (Product prod in _context.Products.Where(x => x.Description.Contains(query)).ToList()) foreach (Product prod in _context.Products.Where(x => x.Description.Contains(query)).ToArray())
if (!products.Contains(prod)) if (!products.Contains(prod))
products.Add(prod); products.Add(prod);
foreach (Product prod in _context.Products.Where(x => x.Category.Contains(query)).ToList()) foreach (Product prod in _context.Products.Where(x => x.Category.Contains(query)).ToArray())
if (!products.Contains(prod)) if (!products.Contains(prod))
products.Add(prod); products.Add(prod);
} }
@ -80,7 +80,7 @@ public class SearchController : Controller {
query = query.Trim(); query = query.Trim();
if (_searchCache is null) { if (_searchCache is null) {
_logger.LogError(8, "Erreur de cache."); _logger.LogError(8, "Erreur de cache.");
return Search(query, preview, deep); return Search(query, preview, deep); // Fallback vers version non-cached en cas d'erreur.
} }
try { // Pour faire une liste priorisée. try { // Pour faire une liste priorisée.
if (preview.HasValue && preview == true) if (preview.HasValue && preview == true)
@ -107,17 +107,17 @@ public class SearchController : Controller {
products.AddRange(cat); products.AddRange(cat);
} else { } else {
products = _searchCache.Where(x => x.Title.Contains(query)).ToList(); products = _searchCache.Where(x => x.Title.Contains(query)).ToList();
foreach (Product prod in _searchCache.Where(x => x.Description.Contains(query)).ToList()) foreach (Product prod in _searchCache.Where(x => x.Description.Contains(query)).ToArray())
if (!products.Contains(prod)) if (!products.Contains(prod))
products.Add(prod); products.Add(prod);
foreach (Product prod in _searchCache.Where(x => x.Category.Contains(query)).ToList()) foreach (Product prod in _searchCache.Where(x => x.Category.Contains(query)).ToArray())
if (!products.Contains(prod)) if (!products.Contains(prod))
products.Add(prod); products.Add(prod);
} }
} }
} catch (Exception e) { } catch (Exception e) {
_logger.LogError(8, e.Message); _logger.LogError(8, e.Message);
return Search(query, preview, deep); return Search(query, preview, deep); // Fallback vers version non-cached en cas d'erreur.
} }
return products; return products;
} }