0
0
RhSolutions-Api/RhSolutions.Api/Controllers/SearchController.cs

28 lines
735 B
C#
Raw Normal View History

2022-12-14 09:53:10 +03:00
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
2023-05-11 07:55:26 +03:00
using RhSolutions.Models;
2022-12-14 09:53:10 +03:00
namespace RhSolutions.Api.Controllers
{
[Route("api/[controller]")]
public class SearchController : ControllerBase
{
private RhSolutionsContext context;
2022-12-14 09:53:10 +03:00
public SearchController(RhSolutionsContext context)
{
this.context = context;
}
2022-12-14 09:53:10 +03:00
[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();
}
}
2022-12-14 09:53:10 +03:00
}