/** * Returns scan results iterator. * * @param Repository $repository * @param int $chunkSize * * @return RawResultIterator */ protected function getResults(Repository $repository, $chunkSize) { $search = $repository->createSearch(); $search->setScroll()->setSize($chunkSize); $search->addQuery(new MatchAllQuery()); return $repository->execute($search, Repository::RESULTS_RAW_ITERATOR); }
/** * Removes pair by key. * * @param string $key */ public function remove($key) { $pair = $this->repository->find($key); if ($pair !== null) { $this->repository->remove($pair->getId()); $this->manager->flush(); $this->manager->refresh(); } }
/** * Executes search. * * @param SearchRequest $request * * @return SearchResponse */ public function search(SearchRequest $request) { $search = $this->container->buildSearch($request); /** @var FilterInterface[] $filters */ foreach ($this->container->all() as $name => $filter) { // We simply exclude not related filters and current filter itself. $relatedFilters = $this->container->getFiltersByRelation(new AndRelation([$filter->getSearchRelation(), new ExcludeRelation([$name])])); $filter->preProcessSearch($search, $this->container->buildSearch($request, $relatedFilters), $request->get($name)); } $result = $this->repository->execute($search); return new SearchResponse($this->getFiltersViewData($result, $request), $result, $this->composeUrlParameters($request)); }
/** * Test for getTypes(). * * @param array $types * @param array $expectedTypes * @param array $bundlesMapping * * @dataProvider getExecuteData */ public function testGetTypes($types, $expectedTypes, $bundlesMapping) { $manager = $this->getMockBuilder('ONGR\\ElasticsearchBundle\\ORM\\Manager')->disableOriginalConstructor()->getMock(); $manager->expects($this->exactly(2))->method('getBundlesMapping')->willReturn($bundlesMapping); $connection = $this->getMockBuilder('ONGR\\ElasticsearchBundle\\Client\\Connection')->disableOriginalConstructor()->getMock(); $connection->expects($this->once())->method('search')->with($expectedTypes, [], [])->willReturn(['test']); $manager->expects($this->once())->method('getConnection')->willReturn($connection); $search = new Search(); $repository = new Repository($manager, $types); $results = $repository->execute($search, Repository::RESULTS_RAW); $this->assertEquals(['test'], $results); }
/** * Creates and returns Products array filled with test data. * * @param Repository $repository * * @return array */ protected function getDocumentsData($repository) { $document = $repository->createDocument(); $document->setId('test-product-1'); $document->title = 'Test title'; $document->setScore(0.0); $this->getManager()->persist($document); $document2 = $repository->createDocument(); $document2->setId('test-product-2'); $document2->title = 'Test title2'; $document2->setScore(0.0); $this->getManager()->persist($document2); $this->getManager()->commit(); $return[$document->getId()] = $document; $return[$document2->getId()] = $document2; return $return; }
/** * Exception when rates are not loaded. * * @expectedException \ONGR\CurrencyExchangeBundle\Exception\RatesNotLoadedException */ public function testException() { $this->repositoryMock->expects($this->any())->method('execute')->willReturn([]); $pool = $this->getCachePool(); $pool->expects($this->any())->method('getItem')->with('ongr_currency')->willReturn($this->getCacheItem([])); $service = new CurrencyRatesService($this->getDriverMock('EUR', []), $this->esManagerMock, $pool, false); $service->setLogger($this->getLogger()); $service->getRates(); }
/** * Tests prefix filter and ids filter without cache. */ public function testPrefixFilterAndIdsFilterWithoutCache() { $search = $this->repository->createSearch(); $search->addFilter(new PrefixFilter('title', 'foo')); $search->addFilter(new IdsFilter(['1', '2']), 'must'); $search->setBoolFilterParameters(['_cache' => false]); $expected = [$this->getProductsArray()[0]]; $this->assertEquals($expected, $this->getSearchResultsArray($search)); }
/** * {@inheritdoc} */ public function valid() { if (array_key_exists($this->key, $this->documents)) { return true; } $raw = $this->repository->scan($this->scrollId, $this->scrollDuration, Repository::RESULTS_RAW); $this->setScrollId($raw['_scroll_id']); $this->documents = array_merge($this->documents, $raw['hits']['hits']); return isset($this->documents[$this->key]); }
/** * Returns setting model by name and profile or creates new if $mustExist is set to FALSE. * * @param string $name * @param string $profile * @param bool $mustExist * @param string $type * * @throws \UnexpectedValueException * * @return Setting */ public function get($name, $profile = 'default', $mustExist = true, $type = 'string') { $setting = $this->repo->find($profile . '_' . $name); if ($setting === null) { if ($mustExist == true) { throw new \UnexpectedValueException(); } $setting = $this->createSetting($name, $profile, $type); } return $setting; }
/** * {@inheritdoc} */ public function valid() { if (parent::key() !== null) { return true; } if ($this->key >= $this->getTotalCount()) { return false; } $this->rawData = $this->repository->scan($this->scrollId, $this->scrollDuration, Repository::RESULTS_RAW); $this->setScrollId($this->rawData['_scroll_id']); $this->documents =& $this->rawData['hits']['hits']; return reset($this->documents) !== false; }
/** * Test for get(). * * @param string $key * @param string $value * @param bool $exception * * @dataProvider getDataSetForSet */ public function testGet($key, $value, $exception) { if ($exception) { $this->repositoryMock->expects($this->once())->method('find')->will($this->returnValue(null)); } else { $pair = new Pair(); $pair->setId($key); $pair->setValue($value); $this->repositoryMock->expects($this->once())->method('find')->willReturn($pair); } $this->ormManagerMock->expects($this->once())->method('getRepository')->willReturn($this->repositoryMock); $pairStorage = $this->getPairStorage($this->ormManagerMock); $this->assertEquals($exception ? null : $value, $pairStorage->get($key)); }
/** * Create and execute highlighted search. * * @param Repository $repository * @param TermQuery $termQuery * @param Highlight $highlight * @param string $resultsType * * @return array|Product[] */ private function executeHighlight($repository, $termQuery, $highlight, $resultsType = Repository::RESULTS_RAW) { $search = $repository->createSearch()->addQuery($termQuery)->setHighlight($highlight); $results = $repository->execute($search, $resultsType); return $results; }
/** * {@inheritdoc} */ public function current() { $doctrineEntity = parent::current(); return new ImportItem($doctrineEntity[0], $this->repository->createDocument()); }