blob: a2ed1943e50dd7b9650d57e0f71dee209c4ce494 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
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();
}
}
}
|