/**
  * {@inheritdoc}
  */
 public function handle(CriteriaPartInterface $criteriaPart, Criteria $criteria, Search $search, ShopContextInterface $context)
 {
     /** @var PriceSorting $criteriaPart */
     $field = $this->fieldMapping->getPriceField($context);
     $sort = new FieldSort($field, strtolower($criteriaPart->getDirection()));
     $search->addSort($sort);
 }
 /**
  * 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;
 }
Beispiel #3
0
 /**
  * Set the query sort values values.
  *
  * @param string|array $fields
  * @param null         $order
  * @param array        $parameters
  *
  * @return $this
  */
 public function sortBy($fields, $order = null, array $parameters = [])
 {
     $fields = is_array($fields) ? $fields : [$fields];
     foreach ($fields as $field) {
         $sort = new FieldSort($field, $order, $parameters);
         $this->query->addSort($sort);
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function handle(CriteriaPartInterface $criteriaPart, Criteria $criteria, Search $search, ShopContextInterface $context)
 {
     /** @var ProductNameSorting $criteriaPart */
     $search->addSort(new FieldSort('name.raw', strtolower($criteriaPart->getDirection())));
 }
Beispiel #5
0
 $Pagination = new Pagination('cg', $AppearancesPerPage);
 // Search query exists
 if (!empty($_GET['q']) && mb_strlen(trim($_GET['q'])) > 0) {
     $SearchQuery = preg_replace(new RegExp('[^\\w\\d\\s\\*\\?]'), '', trim($_GET['q']));
     $title .= "{$SearchQuery} - ";
     if (preg_match(new RegExp('[\\*\\?]'), $SearchQuery)) {
         $queryString = new ElasticsearchDSL\Query\QueryStringQuery($SearchQuery, ['fields' => ['label^20', 'tags'], 'default_operator' => 'and', 'phrase_slop' => 3]);
         $search->addQuery($queryString);
         $orderByID = false;
     } else {
         $multiMatch = new ElasticsearchDSL\Query\MultiMatchQuery(['label^20', 'tags'], $SearchQuery, ['type' => 'cross_fields', 'minimum_should_match' => '100%']);
         $search->addQuery($multiMatch);
     }
 } else {
     $sort = new ElasticsearchDSL\Sort\FieldSort('order', 'asc');
     $search->addSort($sort);
 }
 $boolquery = new BoolQuery();
 if (Permission::insufficient('staff')) {
     $boolquery->add(new TermQuery('private', true), BoolQuery::MUST_NOT);
 }
 $boolquery->add(new TermQuery('ishuman', $EQG), BoolQuery::MUST);
 $search->addQuery($boolquery);
 $search->setSource(false);
 $search = $search->toArray();
 $search = CGUtils::searchElastic($search, $Pagination);
 $Pagination->calcMaxPages($search['hits']['total']);
 if (!empty($search['hits']['hits'])) {
     $ids = [];
     foreach ($search['hits']['hits'] as $hit) {
         $ids[] = $hit['_id'];
 /**
  * {@inheritdoc}
  */
 public function handle(CriteriaPartInterface $criteriaPart, Criteria $criteria, Search $search, ShopContextInterface $context)
 {
     /** @var SearchRankingSorting $criteriaPart */
     $search->addSort(new FieldSort('_score', strtolower($criteriaPart->getDirection())));
 }
 /**
  * {@inheritdoc}
  */
 public function handle(CriteriaPartInterface $criteriaPart, Criteria $criteria, Search $search, ShopContextInterface $context)
 {
     /** @var PopularitySorting $criteriaPart */
     $search->addSort(new FieldSort('sales', strtolower($criteriaPart->getDirection())));
 }
 /**
  * {@inheritdoc}
  */
 public function handle(CriteriaPartInterface $criteriaPart, Criteria $criteria, Search $search, ShopContextInterface $context)
 {
     /** @var ProductAttributeSorting $criteriaPart */
     $field = 'attributes.core.' . $criteriaPart->getField();
     $search->addSort(new FieldSort($field, strtolower($criteriaPart->getDirection())));
 }
 /**
  * {@inheritdoc}
  */
 public function handle(CriteriaPartInterface $criteriaPart, Criteria $criteria, Search $search, ShopContextInterface $context)
 {
     /** @var ReleaseDateSorting $criteriaPart */
     $search->addSort(new FieldSort('formattedReleaseDate', strtolower($criteriaPart->getDirection())));
 }
 /**
  * {@inheritdoc}
  */
 public function hydrate(array $elasticResult, ProductNumberSearchResult $result, Criteria $criteria, ShopContextInterface $context)
 {
     if (!isset($elasticResult['aggregations'])) {
         return;
     }
     if (!isset($elasticResult['aggregations']['agg_properties'])) {
         return;
     }
     $data = $elasticResult['aggregations']['agg_properties']['buckets'];
     $ids = array_column($data, 'key');
     if (empty($ids)) {
         return;
     }
     $groupIds = $this->getGroupIds($ids);
     $search = new Search();
     $search->addFilter(new IdsFilter($groupIds));
     $search->addFilter(new TermFilter('filterable', 1));
     $search->addSort(new FieldSort('name'));
     $index = $this->indexFactory->createShopIndex($context->getShop());
     $data = $this->client->search(['index' => $index->getName(), 'type' => PropertyMapping::TYPE, 'body' => $search->toArray()]);
     $data = $data['hits']['hits'];
     $properties = $this->hydrateProperties($data, $ids);
     $actives = $this->getFilteredValues($criteria);
     $criteriaPart = $this->createCollectionResult($properties, $actives);
     $result->addFacet($criteriaPart);
 }
 public function handle(CriteriaPartInterface $criteriaPart, Criteria $criteria, Search $search, ShopContextInterface $context)
 {
     $sort = new Sort('sales', 'desc');
     $search->addSort($sort);
 }