Skip to content

Commit 1fd35b0

Browse files
committed
[TASK] Make adjustments according to the comments
1 parent 853070b commit 1fd35b0

2 files changed

Lines changed: 14 additions & 20 deletions

File tree

Classes/Flowpack/ElasticSearch/ContentRepositoryAdaptor/Eel/ElasticSearchQueryBuilder.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ public function log($message = NULL) {
512512
* @return integer
513513
*/
514514
public function getTotalItems() {
515-
return $this->result['totalItemCount'];
515+
return $this->result['total'];
516516
}
517517

518518
/**
@@ -554,27 +554,19 @@ public function fetch() {
554554
$response = $this->elasticSearchClient->getIndex()->request('GET', '/_search', array(), json_encode($this->request));
555555
$timeAfterwards = microtime(TRUE);
556556

557-
$treatedContent = $response->getTreatedContent();
557+
$this->result =& $response->getTreatedContent();
558558

559-
$hits = array();
560559
$this->result['nodes'] = array();
561-
if(array_key_exists('hits', $treatedContent) && is_array($treatedContent['hits']) && count($treatedContent['hits']) > 0) {
562-
$hits = $treatedContent['hits'];
563-
$this->result['nodes'] = $this->convertHitsToNodes($treatedContent['hits']);
560+
if (array_key_exists('hits', $this->result) && is_array($this->result['hits']) && count($this->result['hits']) > 0) {
561+
$this->result['nodes'] = $this->convertHitsToNodes($this->result['hits']);
564562
}
565563

566564
if ($this->logThisQuery === TRUE) {
567565
$this->logger->log(sprintf('Query Log (%s): %s -- execution time: %s ms -- Limit: %s -- Number of results returned: %s -- Total Results: %s',
568-
$this->logMessage, json_encode($this->request), (($timeAfterwards - $timeBefore) * 1000), $this->limit, count($hits['hits']), $hits['total'])
566+
$this->logMessage, json_encode($this->request), (($timeAfterwards - $timeBefore) * 1000), $this->limit, count($this->result['hits']['hits']), $this->result['hits']['total'])
569567
, LOG_DEBUG);
570568
}
571569

572-
$this->result['totalItemCount'] = $hits['total'];
573-
574-
if(array_key_exists('aggregations', $treatedContent)) {
575-
$this->result['aggregations'] = $treatedContent['aggregations'];
576-
}
577-
578570
return $this->result;
579571
}
580572

@@ -704,10 +696,10 @@ public function allowsCallOfMethod($methodName) {
704696
}
705697

706698
/**
707-
* @param $hits
708-
* @return array
699+
* @param array $hits
700+
* @return array Array of Node objects
709701
*/
710-
protected function convertHitsToNodes($hits) {
702+
protected function convertHitsToNodes(array $hits) {
711703
$nodes = array();
712704
$elasticSearchHitPerNode = array();
713705

Tests/Functional/Eel/ElasticSearchQueryTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ public function filterNodeByProperty()
102102
*/
103103
public function filterLimitQuery()
104104
{
105+
$resultCount = $this->queryBuilder->query($this->context->getRootNode())->limit(1)->count();
106+
$this->assertEquals(6, $resultCount, 'Asserting the count query returns the total count.');
107+
105108
$result = $this->queryBuilder->query($this->context->getRootNode())->limit(1)->execute();
106109
$this->assertCount(1, $result, 'Asserting the executed query returns a valid number of items.');
107-
108-
$resultCount = $this->queryBuilder->query($this->context->getRootNode())->limit(1)->count();
109-
$this->assertEquals(1, $resultCount, 'Asserting the count query returns a valid count.');
110+
$this->assertEquals(1, $result->getAccessibleCount(), 'Asserting that getAccessibleCount returns the correct number');
110111
}
111-
112+
113+
112114
protected function createNodesForNodeSearchTest() {
113115
$rootNode = $this->context->getRootNode();
114116

0 commit comments

Comments
 (0)