28 lines
715 B
C#
28 lines
715 B
C#
|
using Microsoft.AspNetCore.Mvc;
|
||
|
using Microsoft.EntityFrameworkCore;
|
||
|
using RhSolutions.Api.Models;
|
||
|
|
||
|
namespace RhSolutions.Api.Controllers
|
||
|
{
|
||
|
[Route("api/[controller]")]
|
||
|
public class SearchController : ControllerBase
|
||
|
{
|
||
|
private RhSolutionsContext 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.ProductLine ?? string.Empty, p.Name ?? string.Empty }))
|
||
|
.Matches(EF.Functions.WebSearchToTsQuery("russian", query)))
|
||
|
.AsAsyncEnumerable();
|
||
|
}
|
||
|
}
|
||
|
}
|