Update SearchController.cs
This commit is contained in:
parent
33a451a43f
commit
bcdd04f426
@ -20,17 +20,24 @@ public class SearchController : Controller {
|
||||
[HttpPost(Name = "Search")]
|
||||
public IEnumerable<Product> Post(string query, bool? preview) {
|
||||
const int PREVIEW = 3;
|
||||
HashSet<Product> products = new();
|
||||
List<Product> products = new();
|
||||
|
||||
query = query.Trim();
|
||||
|
||||
try { // Pour faire une liste priorisée.
|
||||
if (preview.HasValue && preview == true)
|
||||
products = _context.Products.Where(x => x.Title.Contains(query)).Take(PREVIEW).ToHashSet();
|
||||
products = _context.Products.Where(x => x.Title.Contains(query)).Take(PREVIEW).ToList();
|
||||
else {
|
||||
products.Concat(_context.Products.Where(x => x.Title.Contains(query)).ToHashSet());
|
||||
products.Concat(_context.Products.Where(x => x.Category.Contains(query)).ToHashSet());
|
||||
products.Concat(_context.Products.Where(x => x.Description.Contains(query)).ToHashSet());
|
||||
products = _context.Products.Where(x => x.Title.Contains(query)).ToList();
|
||||
|
||||
foreach (Product prod in _context.Products.Where(x => x.Category.Contains(query)).ToList()) {
|
||||
if (!products.Contains(prod))
|
||||
products.Add(prod);
|
||||
}
|
||||
foreach (Product prod in _context.Products.Where(x => x.Description.Contains(query)).ToList()) {
|
||||
if (!products.Contains(prod))
|
||||
products.Add(prod);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
_logger.LogError(8, e.Message);
|
||||
|
Loading…
Reference in New Issue
Block a user