/** * @param ElasticSearchQueryResult $queryResultObject * @param NodeInterface $node * @param array|string $path * @return array */ public function render(ElasticSearchQueryResult $queryResultObject, NodeInterface $node, $path = NULL) { $hitArray = $queryResultObject->searchHitForNode($node); if (!empty($path)) { return \TYPO3\Flow\Utility\Arrays::getValueByPath($hitArray, $path); } return $hitArray; }
/** * @test */ public function aSingleValueWillBeReturnedForADottedPath() { $singleValue = 'bar'; $hitArray = ['foo' => [0 => $singleValue], 'sort' => [0 => '14', 0 => '14', 1 => '18']]; $this->mockQueryResult->expects($this->exactly(2))->method('searchHitForNode')->willReturn($hitArray); $singleResult = $this->viewHelper->render($this->mockQueryResult, $this->mockNode, 'foo.0'); $this->assertEquals($singleValue, $singleResult, 'Only a single value will be returned if path is dotted'); $fullResult = $this->viewHelper->render($this->mockQueryResult, $this->mockNode, 'sort'); $this->assertEquals($hitArray['sort'], $fullResult, 'Full array will be returned if there are multiple values'); }
/** * @test */ public function ifNoAggregationsAreSetInTheQueyBuilderResultAnEmptyArrayWillBeReturnedIfYouFetchTheAggregations() { $resultArrayWithoutAggregations = array("nodes" => array("some", "nodes")); $queryBuilder = $this->getMock(ElasticSearchQueryBuilder::class, array("fetch")); $queryBuilder->method("fetch")->will($this->returnValue($resultArrayWithoutAggregations)); $esQuery = new \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Eel\ElasticSearchQuery($queryBuilder); $queryResult = new ElasticSearchQueryResult($esQuery); $actual = $queryResult->getAggregations(); $this->assertTrue(is_array($actual)); $this->assertEmpty($actual); }
/** * @test */ public function ifNoAggregationsAreSetInTheQueyBuilderResultAnEmptyArrayWillBeReturnedIfYouFetchTheAggregations() { $resultArrayWithoutAggregations = ["nodes" => ["some", "nodes"]]; $queryBuilder = $this->getMockBuilder(ElasticSearchQueryBuilder::class)->setMethods(["fetch"])->getMock(); $queryBuilder->method("fetch")->will($this->returnValue($resultArrayWithoutAggregations)); $esQuery = new ElasticSearchQuery($queryBuilder); $queryResult = new ElasticSearchQueryResult($esQuery); $actual = $queryResult->getAggregations(); $this->assertTrue(is_array($actual)); $this->assertEmpty($actual); }