@@ -650,14 +650,13 @@ public function fetch()
650650 $ this ->result = $ response ->getTreatedContent ();
651651
652652 $ this ->result ['nodes ' ] = array ();
653- if (array_key_exists ('hits ' , $ this ->result ) && is_array ($ this ->result ['hits ' ]) && count ($ this ->result ['hits ' ]) > 0 ) {
654- $ this ->result ['nodes ' ] = $ this ->convertHitsToNodes ($ this ->result ['hits ' ]);
655- }
656-
657653 if ($ this ->logThisQuery === true ) {
658654 $ this ->logger ->log (sprintf ('Query Log (%s): %s -- execution time: %s ms -- Limit: %s -- Number of results returned: %s -- Total Results: %s ' ,
659655 $ this ->logMessage , json_encode ($ this ->request ), (($ timeAfterwards - $ timeBefore ) * 1000 ), $ this ->limit , count ($ this ->result ['hits ' ]['hits ' ]), $ this ->result ['hits ' ]['total ' ]), LOG_DEBUG );
660656 }
657+ if (array_key_exists ('hits ' , $ this ->result ) && is_array ($ this ->result ['hits ' ]) && count ($ this ->result ['hits ' ]) > 0 ) {
658+ $ this ->result ['nodes ' ] = $ this ->convertHitsToNodes ($ this ->result ['hits ' ]);
659+ }
661660
662661 return $ this ->result ;
663662 }
@@ -699,7 +698,7 @@ public function count()
699698 $ count = $ treatedContent ['count ' ];
700699
701700 if ($ this ->logThisQuery === true ) {
702- $ this ->logger ->log ('Query Log ( ' . $ this ->logMessage . '): ' . json_encode ($ this ->request ) . ' -- execution time: ' . (($ timeAfterwards - $ timeBefore ) * 1000 ) . ' ms -- Total Results: ' . $ count , LOG_DEBUG );
701+ $ this ->logger ->log ('Count Query Log ( ' . $ this ->logMessage . '): ' . json_encode ($ this ->request ) . ' -- execution time: ' . (($ timeAfterwards - $ timeBefore ) * 1000 ) . ' ms -- Total Results: ' . $ count , LOG_DEBUG );
703702 }
704703
705704 return $ count ;
@@ -773,8 +772,9 @@ public function query(NodeInterface $contextNode)
773772 $ this ->queryFilter ('terms ' , array ('__workspace ' => array_unique (array ('live ' , $ contextNode ->getContext ()->getWorkspace ()->getName ()))));
774773
775774 // match exact dimension values for each dimension, this works because the indexing flattens the node variants for all dimension preset combinations
776- foreach ($ contextNode ->getContext ()->getDimensions () as $ dimensionName => $ dimensionValues ) {
777- $ this ->queryFilter ('terms ' , array ('__dimensionCombinations. ' . $ dimensionName => $ dimensionValues , 'execution ' => 'and ' ));
775+ $ dimensionCombinations = $ contextNode ->getContext ()->getDimensions ();
776+ if (is_array ($ dimensionCombinations )) {
777+ $ this ->queryFilter ('term ' , ['__dimensionCombinationHash ' => md5 (json_encode ($ dimensionCombinations ))]);
778778 }
779779
780780 $ this ->contextNode = $ contextNode ;
@@ -817,15 +817,9 @@ protected function convertHitsToNodes(array $hits)
817817 * we might be able to use https://github.com/elasticsearch/elasticsearch/issues/3300 as soon as it is merged.
818818 */
819819 foreach ($ hits ['hits ' ] as $ hit ) {
820- // with ElasticSearch 1.0 fields always returns an array,
821- // see https://github.com/Flowpack/Flowpack.ElasticSearch.ContentRepositoryAdaptor/issues/17
822- if (is_array ($ hit ['fields ' ]['__path ' ])) {
823- $ nodePath = current ($ hit ['fields ' ]['__path ' ]);
824- } else {
825- $ nodePath = $ hit ['fields ' ]['__path ' ];
826- }
820+ $ nodePath = current ($ hit ['fields ' ]['__path ' ]);
827821 $ node = $ this ->contextNode ->getNode ($ nodePath );
828- if ($ node instanceof NodeInterface) {
822+ if ($ node instanceof NodeInterface && ! isset ( $ nodes [ $ node -> getIdentifier ()]) ) {
829823 $ nodes [$ node ->getIdentifier ()] = $ node ;
830824 $ elasticSearchHitPerNode [$ node ->getIdentifier ()] = $ hit ;
831825 if ($ this ->limit > 0 && count ($ nodes ) >= $ this ->limit ) {
@@ -835,7 +829,7 @@ protected function convertHitsToNodes(array $hits)
835829 }
836830
837831 if ($ this ->logThisQuery === true ) {
838- $ this ->logger ->log ('Query Log ( ' . $ this ->logMessage . ') Number of returned results : ' . count ($ nodes ), LOG_DEBUG );
832+ $ this ->logger ->log ('Returned nodes ( ' . $ this ->logMessage . '): ' . count ($ nodes ), LOG_DEBUG );
839833 }
840834
841835 $ this ->elasticSearchHitsIndexedByNodeFromLastRequest = $ elasticSearchHitPerNode ;
0 commit comments