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