поиск+доставка
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Services\PriceTierService;
|
||||
use App\Services\SmartSearchService;
|
||||
|
||||
final class ProductRepository extends BaseRepository
|
||||
{
|
||||
@@ -51,6 +52,22 @@ final class ProductRepository extends BaseRepository
|
||||
return (int) $statement->fetchColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{products: array<int, array<string, mixed>>, total: int}
|
||||
*/
|
||||
public function searchCatalog(string $query, int $limit = 48, int $offset = 0, bool $includeHidden = false): array
|
||||
{
|
||||
$limit = max(1, min($limit, 5000));
|
||||
$offset = max(0, $offset);
|
||||
$products = $this->catalogPreview(5000, 0, $includeHidden);
|
||||
$rankedProducts = (new SmartSearchService())->rankProducts($query, $products);
|
||||
|
||||
return [
|
||||
'products' => array_slice($rankedProducts, $offset, $limit),
|
||||
'total' => count($rankedProducts),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user