2626use Neos \Flow \Cli \CommandController ;
2727use Neos \Flow \Persistence \Exception \IllegalObjectTypeException ;
2828use Neos \Media \Domain \Model \ResourceBasedInterface ;
29+ use Neos \Utility \Arrays ;
2930
3031/**
3132 * @Flow\Scope("singleton")
@@ -54,6 +55,7 @@ class SearchCommandController extends CommandController
5455 * @throws Exception
5556 * @throws QueryBuildingException
5657 * @throws IllegalObjectTypeException
58+ * @throws Exception\ConfigurationException
5759 */
5860 public function fulltextCommand (string $ searchWord , string $ path = '/ ' , ?string $ dimensions = null ): void
5961 {
@@ -68,7 +70,7 @@ public function fulltextCommand(string $searchWord, string $path = '/', ?string
6870 $ queryBuilder = new ElasticSearchQueryBuilder ();
6971 $ queryBuilder = $ queryBuilder ->query ($ contextNode )
7072 ->fulltext ($ searchWord )
71- ->limit (100 )
73+ ->limit (10 )
7274 ->termSuggestions ($ searchWord )
7375 ->log (__CLASS__ );
7476
@@ -93,15 +95,16 @@ public function fulltextCommand(string $searchWord, string $path = '/', ?string
9395 *
9496 * @param string $identifier The node identifier
9597 * @param string|null $dimensions Dimensions, specified in JSON format, like '{"language":["de"]}'
98+ * @param string $field Name or path to a source field to display. Eg. "__fulltext.h1"
9699 * @throws Exception
97100 * @throws IllegalObjectTypeException
98101 * @throws QueryBuildingException
99102 * @throws \Flowpack\ElasticSearch\Exception
100103 * @throws \Neos\Flow\Http\Exception
101104 */
102- public function viewNodeCommand (string $ identifier , ?string $ dimensions = null ): void
105+ public function viewNodeCommand (string $ identifier , ?string $ dimensions = null , string $ field = '' ): void
103106 {
104- if ($ dimensions !== null && is_array (json_decode ($ dimensions , true )) === false ) {
107+ if ($ dimensions !== null && is_array (json_decode ($ dimensions , true , 512 , JSON_THROW_ON_ERROR )) === false ) {
105108 $ this ->outputLine ('<error>Error: </error>The Dimensions must be given as a JSON array like \'{"language":["de"]} \'' );
106109 $ this ->sendAndExit (1 );
107110 }
@@ -112,10 +115,23 @@ public function viewNodeCommand(string $identifier, ?string $dimensions = null):
112115 $ queryBuilder ->query ($ context ->getRootNode ());
113116 $ queryBuilder ->exactMatch ('__identifier ' , $ identifier );
114117
118+ $ queryBuilder ->getRequest ()->setValueByPath ('_source ' , []);
119+
115120 if ($ queryBuilder ->count () > 0 ) {
116121 $ this ->outputLine ();
117122 $ this ->outputLine ('<info>Results</info> ' );
118- $ this ->outputResults ($ queryBuilder ->execute ());
123+
124+ foreach ($ queryBuilder ->execute () as $ node ) {
125+ $ this ->outputLine ('<b>%s</b> ' , [(string )$ node ]);
126+ $ data = $ queryBuilder ->getFullElasticSearchHitForNode ($ node );
127+
128+ if ($ field !== '' ) {
129+ $ data = Arrays::getValueByPath ($ data , '_source. ' . $ field );
130+ }
131+
132+ $ this ->outputLine (print_r ($ data , true ));
133+ $ this ->outputLine ();
134+ }
119135 } else {
120136 $ this ->outputLine ();
121137 $ this ->outputLine ('No document matching the given node identifier ' );
@@ -135,6 +151,10 @@ private function outputResults(ElasticSearchQueryResult $result): void
135151 $ properties [$ propertyName ] = '<b> ' . $ propertyName . '</b>: ' . (string )$ propertyValue ->getResource ()->getFilename ();
136152 } elseif ($ propertyValue instanceof \DateTime) {
137153 $ properties [$ propertyName ] = '<b> ' . $ propertyName . '</b>: ' . $ propertyValue ->format ('Y-m-d H:i ' );
154+ } elseif (is_array ($ propertyValue )) {
155+ $ properties [$ propertyName ] = '<b> ' . $ propertyName . '</b>: ' . 'array ' ;
156+ } elseif ($ propertyValue instanceof NodeInterface) {
157+ $ properties [$ propertyName ] = '<b> ' . $ propertyName . '</b>: ' . $ propertyValue ->getIdentifier ();
138158 } else {
139159 $ properties [$ propertyName ] = '<b> ' . $ propertyName . '</b>: ' . (string )$ propertyValue ;
140160 }
@@ -144,12 +164,11 @@ private function outputResults(ElasticSearchQueryResult $result): void
144164 'identifier ' => $ node ->getIdentifier (),
145165 'label ' => $ node ->getLabel (),
146166 'nodeType ' => $ node ->getNodeType ()->getName (),
147- 'contextPath ' => implode (PHP_EOL , explode ('@ ' , $ node ->getContextPath ())),
148167 'properties ' => implode (PHP_EOL , $ properties ),
149168 ];
150169 }, $ result ->toArray ());
151170
152- $ this ->output ->outputTable ($ results , ['Identifier ' , 'Label ' , 'Node Type ' , 'Context ' , ' Properties ' ]);
171+ $ this ->output ->outputTable ($ results , ['Identifier ' , 'Label ' , 'Node Type ' , 'Properties ' ]);
153172 }
154173
155174 /**
@@ -163,7 +182,7 @@ private function createContext(string $dimensions = null): Context
163182 ];
164183
165184 if ($ dimensions !== null ) {
166- $ contextConfiguration ['dimensions ' ] = json_decode ($ dimensions , true );
185+ $ contextConfiguration ['dimensions ' ] = json_decode ($ dimensions , true , 512 , JSON_THROW_ON_ERROR );
167186 }
168187
169188 return $ this ->contextFactory ->create ($ contextConfiguration );
0 commit comments