11<?php
22namespace Flowpack \SearchPlugin \Controller ;
33
4- /* *
5- * This script belongs to the TYPO3 Flow package " Flowpack.SearchPlugin". *
6- * *
7- * It is free software; you can redistribute it and/or modify it under *
8- * the terms of the GNU Lesser General Public License, either version 3 *
9- * of the License, or (at your option) any later version. *
10- * *
11- * The TYPO3 project - inspiring people to share! *
12- * * /
4+ /*
5+ * This file is part of the Flowpack.SearchPlugin package.
6+ *
7+ * (c) Contributors of the Flowpack Team - flowpack.org
8+ *
9+ * This package is Open Source Software. For the full copyright and license
10+ * information, please view the LICENSE file which was distributed with this
11+ * source code.
12+ */
1313
1414use TYPO3 \Flow \Annotations as Flow ;
1515use TYPO3 \Flow \Mvc \Controller \ActionController ;
16- use TYPO3 \TYPO3CR \Domain \Model \NodeInterface ;
1716
1817/**
1918 * Class SuggestController
20- *
21- * @author Jon Klixbüll Langeland <jon@moc.net>
22- * @package Flowpack\SearchPlugin\Controller
2319 */
24- class SuggestController extends ActionController {
25-
26- /**
27- * @Flow\Inject
28- * @var \Flowpack\ElasticSearch\ContentRepositoryAdaptor\ElasticSearchClient
29- */
30- protected $ elasticSearchClient ;
31-
32- /**
33- * The node inside which searching should happen
34- *
35- * @var NodeInterface
36- */
37- protected $ contextNode ;
38-
39- /**
40- * @Flow\Inject
41- * @var \Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface
42- */
43- protected $ logger ;
44-
45- /**
46- * @var boolean
47- */
48- protected $ logThisQuery = FALSE ;
49-
50- /**
51- * @var string
52- */
53- protected $ logMessage ;
54-
55- /**
56- * @var array
57- */
58- protected $ viewFormatToObjectNameMap = array (
59- 'json ' => 'TYPO3\Flow\Mvc\View\JsonView '
60- );
61-
62- /**
63- * @param NodeInterface $node
64- * @param string $term
65- */
66- public function indexAction (NodeInterface $ node , $ term ) {
67- $ request = array (
68- 'suggests ' => array (
69- 'text ' => $ term ,
70- 'term ' => array (
71- 'field ' => '_all '
72- )
73- )
74- );
75-
76- $ response = $ this ->elasticSearchClient ->getIndex ()->request ('GET ' , '/_suggest ' , array (), json_encode ($ request ))->getTreatedContent ();
77- $ suggestions = array_map (function ($ option ) {
78- return $ option ['text ' ];
79- }, $ response ['suggests ' ][0 ]['options ' ]);
80-
81- $ this ->view ->assign ('value ' , $ suggestions );
82- }
83-
84- }
20+ class SuggestController extends ActionController
21+ {
22+ /**
23+ * @Flow\Inject
24+ * @var \Flowpack\ElasticSearch\ContentRepositoryAdaptor\ElasticSearchClient
25+ */
26+ protected $ elasticSearchClient ;
27+
28+ /**
29+ * @var array
30+ */
31+ protected $ viewFormatToObjectNameMap = [
32+ 'json ' => 'TYPO3\Flow\Mvc\View\JsonView '
33+ ];
34+
35+ /**
36+ * @param string $term
37+ * @return void
38+ */
39+ public function indexAction ($ term )
40+ {
41+ $ request = [
42+ 'suggests ' => [
43+ 'text ' => $ term ,
44+ 'term ' => [
45+ 'field ' => '_all '
46+ ]
47+ ]
48+ ];
49+
50+ $ response = $ this ->elasticSearchClient ->getIndex ()->request ('POST ' , '/_suggest ' , [], json_encode ($ request ))->getTreatedContent ();
51+ $ suggestions = array_map (function ($ option ) {
52+ return $ option ['text ' ];
53+ }, $ response ['suggests ' ][0 ]['options ' ]);
54+
55+ $ this ->view ->assign ('value ' , $ suggestions );
56+ }
57+ }
0 commit comments