Redis
This commit is contained in:
@ -2,12 +2,18 @@
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Search
|
||||
{
|
||||
public function __construct(protected Venta $ventaService, protected Repository\Venta $ventaRepository, protected Repository\Venta\Unidad $unidadRepository, protected Repository\Proyecto\TipoUnidad $tipoUnidadRepository) {}
|
||||
public function __construct(
|
||||
protected Proyecto $proyectoService,
|
||||
protected Venta $ventaService,
|
||||
protected Repository\Venta $ventaRepository,
|
||||
protected Repository\Venta\Unidad $unidadRepository,
|
||||
protected Repository\Proyecto\TipoUnidad $tipoUnidadRepository) {}
|
||||
|
||||
public function query(string $query, string $tipo): array
|
||||
{
|
||||
@ -39,7 +45,12 @@ class Search
|
||||
}
|
||||
protected function find(string $query, string $tipo): array
|
||||
{
|
||||
$queries = explode(' ', $query);
|
||||
preg_match_all('/["\']([\s\w]+)["\']|(\w+)/i', $query, $matches, PREG_SET_ORDER | PREG_UNMATCHED_AS_NULL);
|
||||
$queries = array_map(function($match) {
|
||||
array_shift($match);
|
||||
$valid = array_filter($match, function($line) {return $line !== null;});
|
||||
return implode(' ', $valid);
|
||||
}, $matches);
|
||||
$tiposUnidades = $this->getTiposUnidades();
|
||||
$results = [];
|
||||
foreach ($queries as $q) {
|
||||
@ -113,7 +124,8 @@ class Search
|
||||
protected function findProyecto(string $query): array
|
||||
{
|
||||
try {
|
||||
return $this->ventaService->getByProyecto($query);
|
||||
$proyecto = $this->proyectoService->getByName($query);
|
||||
return $this->ventaService->getByProyecto($proyecto->id);
|
||||
} catch (EmptyResult) {
|
||||
return [];
|
||||
}
|
||||
|
Reference in New Issue
Block a user