0
0
RhSolutions-Api/RhSolutions.Api/Controllers/SearchController.cs
2024-01-23 23:30:47 +03:00

33 lines
1.1 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using RhSolutions.Models;
namespace RhSolutions.Api.Controllers
{
[Route("api/[controller]")]
public class SearchController : ControllerBase
{
private RhSolutionsContext context;
public SearchController(RhSolutionsContext context)
{
this.context = context;
}
/// <summary>
/// Поиск артикула в базе данных через предварительную мультиклассовую классификацию с применением ML-модели артикулов
/// </summary>
/// <param name="query">Запрос в свободной форме</param>
/// <returns></returns>
[HttpGet]
public IAsyncEnumerable<Product> SearchProducts([FromQuery] string query)
{
return context.Products
.Where(p => EF.Functions.ToTsVector("russian", p.Name)
.Matches(EF.Functions.WebSearchToTsQuery("russian", query)))
.Where(p => p.ProductLines.Contains("RAUTITAN"))
.OrderByDescending(p => p.IsOnWarehouse)
.AsAsyncEnumerable();
}
}
}