summaryrefslogtreecommitdiff
path: root/RhSolutions.Api/Controllers/SearchController.cs
blob: 162e961098085ae2c33365cc12f331962efcba40 (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
29
30
31
32
33
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();
		}
	}
}