Order found products by IsOnWarehouse property
This commit is contained in:
parent
b7e4bf6887
commit
bdf5f4f727
@ -4,24 +4,25 @@ using RhSolutions.Models;
|
||||
|
||||
namespace RhSolutions.Api.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
public class SearchController : ControllerBase
|
||||
{
|
||||
private RhSolutionsContext context;
|
||||
[Route("api/[controller]")]
|
||||
public class SearchController : ControllerBase
|
||||
{
|
||||
private RhSolutionsContext context;
|
||||
|
||||
public SearchController(RhSolutionsContext context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
public SearchController(RhSolutionsContext context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IAsyncEnumerable<Product> SearchProducts([FromQuery] string query)
|
||||
{
|
||||
return context.Products
|
||||
.Where(p => EF.Functions.ToTsVector(
|
||||
"russian", string.Join(' ', new[] { p.Name, string.Join(' ', p.ProductLines)}))
|
||||
.Matches(EF.Functions.WebSearchToTsQuery("russian", query)))
|
||||
.AsAsyncEnumerable();
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public IAsyncEnumerable<Product> SearchProducts([FromQuery] string query)
|
||||
{
|
||||
return context.Products
|
||||
.Where(p => EF.Functions.ToTsVector(
|
||||
"russian", string.Join(' ', new[] { p.Name, string.Join(' ', p.ProductLines)}))
|
||||
.Matches(EF.Functions.WebSearchToTsQuery("russian", query)))
|
||||
.OrderByDescending(p => p.IsOnWarehouse)
|
||||
.AsAsyncEnumerable();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user