<?php

namespace KupShop\CatalogBundle\Query;

class Search
{
    public static function searchFields($search_term, $fields, $operator = 'AND')
    {
        return function (\Query\QueryBuilder $qb) use ($search_term, $fields, $operator) {
            $search = get_search_query($search_term, $fields, $operator);

            if ($search['order']) {
                $ordering = $qb->getQueryPart('orderBy');
                $qb->orderBySql($search['order']);
                $qb->add('orderBy', $ordering, true);
            }

            $qb->addParameters($search['data']);

            return $search['where'];
        };
    }
}
