protected function getResultCollection($word) { $keywords = new Keywords(); $keywords->addKeyword($word); $query = new Query($keywords); $query->setIndex('produtoIndex'); $collection = Search::getInstance()->findByQuery($query); return $collection; }
/** * @dataProvider dataProviderProdutosComMarcaNoNome */ public function testResultadosComPropriedadesProcessadas($keyword) { if (!$this->hasHost()) { return $this->markTestSkipped(); } $collection = new Collection(); $results = Search::getInstance()->getResultsByKeyword($keyword, $collection); $this->assertInstanceOf('\\Gpupo\\Search\\Result\\CollectionInterface', $results); $this->assertGreaterThan(2, $results->count()); foreach ($results->toArray() as $produto) { $this->assertInstanceOf('\\Gpupo\\Search\\Result\\ItemInterface', $produto); } return $results; }
/** * @depends testPalavrasChavesModeladasEmObjeto */ public function testPesquisaAPartirDeQueriesModeladas(KeywordsInterface $keywords) { if (!$this->hasHost()) { return $this->markTestSkipped(); } $query = new Query($keywords); $query->setIndex('produtoIndex'); $this->assertEquals('produtoIndex', $query->getIndex()); $collection = Search::getInstance()->findByQuery($query); $this->assertInstanceOf('\\Gpupo\\Search\\Result\\Collection', $collection); $this->assertGreaterThan(2, $collection->getTotal()); $this->assertGreaterThan(2, $collection->getTotalFound()); $this->assertInternalType('integer', $collection->getTotal()); $this->assertInternalType('integer', $collection->getTotalFound()); return $query; }
/** * @dataProvider dataProviderFrasesValidas */ public function testSucessoAoPesquisarComFrases($string) { if (!$this->hasHost()) { return $this->markTestSkipped(); } $keywords = new Keywords(); $keywords->readString($string); $query = new Query($keywords); $query->setIndex('produtoIndex'); $collection = Search::getInstance()->findByQuery($query); $this->assertInstanceOf('\\Gpupo\\Search\\Result\\Collection', $collection); $this->assertGreaterThan(5, $collection->getTotal()); $this->assertGreaterThan(5, $collection->getTotalFound()); $this->assertInternalType('integer', $collection->getTotal()); $this->assertInternalType('integer', $collection->getTotalFound()); }
public function testSuporteAMultiQueries() { $query = []; $query[] = ['key' => '*', 'values' => ['shampoo'], 'strict' => false]; $query[] = ['key' => '*', 'values' => ['perfume'], 'strict' => false]; if (!$this->hasHost()) { return $this->markTestSkipped(); } $multipleResults = Search::getInstance()->query('produtoIndex', null, $query, null, 2, 0); $this->assertCount(2, $multipleResults); foreach ($multipleResults as $results) { $this->assertArrayHasKey('total', $results); $this->assertArrayHasKey('matches', $results); foreach ($results['matches'] as $item) { $this->assertArrayHasKey('attrs', $item); } } }
/** * O mesmo teste que testSimplificaMultiplasQueriesGroupby() mas * usando Search::query(). */ public function testMultiqueryComGroupby() { $countableAttributes = ['categoria', 'fornecedor', 'tamanho']; $querys = []; $querys[] = ['key' => '*', 'values' => ['shampoo'], 'countableAttributes' => $countableAttributes]; if (!$this->hasHost()) { return $this->markTestSkipped(); } $results = Search::getInstance()->query('produtoIndex', null, $querys, null, 2, 0); foreach ($results[0]['matches'] as $item) { $this->assertArrayNotHasKey('@count', $item['attrs']); } $this->assertMultiQueryResults($results); }