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
|
|
|
|
|
{
|
2023-05-12 07:46:06 +03:00
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
public class SearchController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private RhSolutionsContext context;
|
2022-12-14 09:53:10 +03:00
|
|
|
|
|
2023-05-12 07:46:06 +03:00
|
|
|
|
public SearchController(RhSolutionsContext context)
|
|
|
|
|
{
|
|
|
|
|
this.context = context;
|
|
|
|
|
}
|
2022-12-14 09:53:10 +03:00
|
|
|
|
|
2024-01-14 23:03:52 +03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Поиск артикула в базе данных через предварительную мультиклассовую классификацию с применением ML-модели артикулов
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="query">Запрос в свободной форме</param>
|
|
|
|
|
/// <returns></returns>
|
2023-05-12 07:46:06 +03:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IAsyncEnumerable<Product> SearchProducts([FromQuery] string query)
|
|
|
|
|
{
|
|
|
|
|
return context.Products
|
2024-01-18 22:32:40 +03:00
|
|
|
|
.Where(p => EF.Functions.ToTsVector("russian", p.Name)
|
2023-05-12 07:46:06 +03:00
|
|
|
|
.Matches(EF.Functions.WebSearchToTsQuery("russian", query)))
|
2024-01-18 22:32:40 +03:00
|
|
|
|
.Where(p => p.ProductLines.Contains("RAUTITAN"))
|
2023-05-12 07:46:06 +03:00
|
|
|
|
.OrderByDescending(p => p.IsOnWarehouse)
|
|
|
|
|
.AsAsyncEnumerable();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-14 09:53:10 +03:00
|
|
|
|
}
|