Beispiel #1
0
 public function __construct(ArrayAdapter $paginator)
 {
     $this->paginator = $paginator->getArray();
     $this->firstResult = 0;
     $this->maxResults = count($this->paginator);
     $this->totalItems = count($this->paginator);
 }
Beispiel #2
0
 /**
  * Perform a search and return a JSON response.
  *
  * @param Request $request
  *
  * @return Response
  */
 public function searchAction(Request $request)
 {
     $queryString = $request->query->get('q');
     $index = $request->query->get('index', null);
     $locale = $request->query->get('locale', null);
     $page = $this->listRestHelper->getPage();
     $limit = $this->listRestHelper->getLimit();
     $startTime = microtime(true);
     $indexes = $index ? [$index] : $this->getAllowedIndexes();
     $query = $this->searchManager->createSearch($queryString);
     if ($locale) {
         $query->locale($locale);
     }
     $query->indexes($indexes);
     $query->setLimit($limit);
     $time = microtime(true) - $startTime;
     $adapter = new ArrayAdapter(iterator_to_array($query->execute()));
     $pager = new Pagerfanta($adapter);
     $pager->setMaxPerPage($limit);
     $pager->setCurrentPage($page);
     $representation = new SearchResultRepresentation(new CollectionRepresentation($pager->getCurrentPageResults(), 'result'), 'sulu_search_search', ['locale' => $locale, 'query' => $query, 'index' => $index], (int) $page, (int) $limit, $pager->getNbPages(), 'page', 'limit', false, $adapter->getNbResults(), $this->getIndexTotals($adapter->getArray()), number_format($time, 8));
     $view = View::create($representation);
     $context = SerializationContext::create();
     $context->enableMaxDepthChecks();
     $context->setSerializeNull(true);
     $view->setSerializationContext($context);
     return $this->viewHandler->handle($view);
 }
 public function testGetArray()
 {
     $this->assertSame($this->array, $this->adapter->getArray());
 }