/**
  * Data provider for testIteration.
  *
  * @return array
  */
 public function getIterationData()
 {
     $out = [];
     // Case #0: no search type set, with a sort, results should be sorted.
     $search = new Search();
     $search->setSize(2);
     $search->setScroll('1m');
     $search->addSort(new FieldSort('price'));
     $search->addQuery(new MatchAllQuery());
     $out[] = ['search' => $search, true];
     // Case #1: search type set to scan, with a sort, results should not be sorted.
     $search = new Search();
     $search->setSize(2);
     $search->setScroll('1m');
     $search->setSearchType('scan');
     $search->addSort(new FieldSort('price'));
     $search->addQuery(new MatchAllQuery());
     $out[] = ['search' => $search, false];
     // Case #3: minimum size, should give the same results.
     $search = new Search();
     $search->setSize(1);
     $search->setScroll('1m');
     $search->addSort(new FieldSort('price'));
     $search->addQuery(new MatchAllQuery());
     $out[] = ['search' => $search, true];
     return $out;
 }
Example #2
0
 /**
  * Paginate the search.
  *
  * @param  int|null $perPage
  * @param  string $pageName
  * @param  int|null $page
  * @return $this
  */
 public function paginate($perPage = null, $pageName = 'page', $page = null)
 {
     $perPage = $perPage ?: $this->getModel()->getPerPage();
     $page = $page ?: (int) Paginator::resolveCurrentPage($pageName);
     $this->search->setFrom($perPage * $page);
     $this->search->setSize($perPage);
     $results = $this->get();
     return new LengthAwarePaginator($results, $perPage, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => $pageName]);
 }
Example #3
0
 /**
  * Data provider for test testSettingParams()
  *
  * @return array
  */
 public function getTestSettingParamsData()
 {
     $cases = [];
     $search = new Search();
     $search->setSize(3);
     $cases['Only size is set'] = [$search, ['size' => 3]];
     $search = new Search();
     $search->setFrom(4);
     $cases['Only from is set'] = [$search, ['from' => 4]];
     $search = new Search();
     $search->setTimeout('2s');
     $cases['Only timeout is set'] = [$search, ['timeout' => '2s']];
     $search = new Search();
     $search->setTerminateAfter(100);
     $cases['Only terminate_after is set'] = [$search, ['terminate_after' => 100]];
     $search = new Search();
     $search->setSize(3);
     $search->setFrom(4);
     $search->setTimeout('2s');
     $search->setTerminateAfter(100);
     $cases['Multiple parameters are set'] = [$search, ['size' => 3, 'from' => 4, 'timeout' => '2s', 'terminate_after' => 100]];
     return $cases;
 }
Example #4
0
 /**
  * Set the query limit/size value.
  *
  * @param int $limit
  *
  * @return $this
  */
 public function size($limit)
 {
     $this->query->setSize($limit);
     return $this;
 }
 /**
  * @param Struct\ListProduct $product
  * @param Struct\ShopContextInterface $context
  * @param $limit
  * @return Search
  */
 protected function getSearch($product, Struct\ShopContextInterface $context, $limit)
 {
     $search = new Search();
     $search->setSize($limit);
     $search->addQuery($this->getSimilarQuery($product));
     $search->addFilter($this->getProductNumberFilter($product));
     $search->addFilter($this->getCategoryFilter($context->getShop()->getCategory()));
     $search->addFilter($this->getCustomerGroupFilter($context->getCurrentCustomerGroup()));
     return $search;
 }