/** * 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; }
/** * @inheritDoc */ public function getRouteCollectionForRequest(Request $request) { if (!$this->manager) { throw new \Exception('Manager must be set to execute query to the elasticsearch'); } $routeCollection = new RouteCollection(); $requestPath = $request->getPathInfo(); $search = new Search(); $search->addQuery(new MatchQuery('url', $requestPath)); $results = $this->manager->execute(array_keys($this->routeMap), $search, Result::RESULTS_OBJECT); try { foreach ($results as $document) { $type = $this->collector->getDocumentType(get_class($document)); if (array_key_exists($type, $this->routeMap)) { $route = new Route($document->url, ['_controller' => $this->routeMap[$type], 'document' => $document, 'type' => $type]); $routeCollection->add('ongr_route_' . $route->getDefault('type'), $route); } else { throw new RouteNotFoundException(sprintf('Route for type %s% cannot be generated.', $type)); } } } catch (\Exception $e) { throw new RouteNotFoundException('Document is not correct or route cannot be generated.'); } return $routeCollection; }
/** * Match all test */ public function testMatchAll() { $search = new Search(); $matchAll = new MatchAllQuery(); $search->addQuery($matchAll); $results = $this->executeSearch($search); $this->assertEquals($this->getDataArray()['product'], $results); }
/** * Append a query. * * @param $query * * @return $this */ public function append($query) { if ($this->getFilteringState()) { $this->query->addFilter($query, $this->getBoolState()); } else { $this->query->addQuery($query, $this->getBoolState()); } return $this; }
public function testToArray() { $query = new TermQuery('foo', 'bar'); $search = new Search(); $search->addQuery($query); $hit = new ParentInnerHit('test', 'acme', $search); $expected = ['type' => ['acme' => ['query' => $query->toArray()]]]; $this->assertEquals($expected, $hit->toArray()); }
/** * Tests getters and setters for $name, $path and $query */ public function testGettersAndSetters() { $query = new MatchQuery('acme', 'test'); $search = new Search(); $search->addQuery($query); $hit = new NestedInnerHit('test', 'acme', new Search()); $hit->setName('foo'); $hit->setPath('bar'); $hit->setSearch($search); $this->assertEquals('foo', $hit->getName()); $this->assertEquals('bar', $hit->getPath()); $this->assertEquals($search, $hit->getSearch()); }
private function searchBlog(Criteria $criteria, Struct\ProductContextInterface $context) { /**@var $condition SearchTermCondition*/ $condition = $criteria->getCondition('search'); $query = $this->createMultiMatchQuery($condition); $search = new Search(); $search->addQuery($query); $search->setFrom(0)->setSize(5); $index = $this->indexFactory->createShopIndex($context->getShop()); $params = ['index' => $index->getName(), 'type' => 'blog', 'body' => $search->toArray()]; $raw = $this->client->search($params); return $this->createBlogStructs($raw); }
/** * Check if `token_count` field works as expected. */ public function testPersistTokenCountField() { $manager = $this->repository->getManager(); $product = new ProductDocument(); $product->tokenPiecesCount = 't e s t'; $manager->persist($product); $manager->commit(); // Analyzer is whitespace, so there are four tokens. $search = new Search(); $search->addQuery(new TermQuery('pieces_count.count', '4')); $this->assertEquals(1, $this->repository->execute($search)->count()); // Test with invalid count. $search = new Search(); $search->addQuery(new TermQuery('pieces_count.count', '6')); $this->assertEquals(0, $this->repository->execute($search)->count()); }
/** * @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; }
try { $elasticAvail = CoreUtils::elasticClient()->ping(); } catch (Elasticsearch\Common\Exceptions\NoNodesAvailableException $e) { $elasticAvail = false; } if ($elasticAvail) { $search = new ElasticsearchDSL\Search(); $orderByID = true; $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);
/** * {@inheritdoc} */ public function handle(CriteriaPartInterface $criteriaPart, Criteria $criteria, Search $search, ShopContextInterface $context) { /** @var SearchTermCondition $criteriaPart */ $query = $this->queryBuilder->buildQuery($context, $criteriaPart->getTerm()); $search->addQuery($query); }
/** * {@inheritdoc} */ public function handle(CriteriaPartInterface $criteriaPart, Criteria $criteria, Search $search, ShopContextInterface $context) { $query = new TermQuery('hasAvailableVariant', true); $search->addQuery($query); }