-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
Classes/Flowpack/SearchPlugin/Controller/SuggestController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
namespace Flowpack\SearchPlugin\Controller; | ||
|
||
/* * | ||
* This script belongs to the TYPO3 Flow package "Flowpack.SearchPlugin". * | ||
* * | ||
* It is free software; you can redistribute it and/or modify it under * | ||
* the terms of the GNU Lesser General Public License, either version 3 * | ||
* of the License, or (at your option) any later version. * | ||
* * | ||
* The TYPO3 project - inspiring people to share! * | ||
* */ | ||
|
||
use TYPO3\Flow\Annotations as Flow; | ||
use TYPO3\Flow\Mvc\Controller\ActionController; | ||
use TYPO3\TYPO3CR\Domain\Model\NodeInterface; | ||
|
||
/** | ||
* Class SuggestController | ||
* | ||
* @author Jon Klixbüll Langeland <jon@moc.net> | ||
* @package Flowpack\SearchPlugin\Controller | ||
*/ | ||
class SuggestController extends ActionController { | ||
|
||
/** | ||
* @Flow\Inject | ||
* @var \Flowpack\ElasticSearch\ContentRepositoryAdaptor\ElasticSearchClient | ||
*/ | ||
protected $elasticSearchClient; | ||
|
||
/** | ||
* The node inside which searching should happen | ||
* | ||
* @var NodeInterface | ||
*/ | ||
protected $contextNode; | ||
|
||
/** | ||
* @Flow\Inject | ||
* @var \Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface | ||
*/ | ||
protected $logger; | ||
|
||
/** | ||
* @var boolean | ||
*/ | ||
protected $logThisQuery = FALSE; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $logMessage; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $viewFormatToObjectNameMap = array( | ||
'json' => 'TYPO3\Flow\Mvc\View\JsonView' | ||
); | ||
|
||
/** | ||
* @param NodeInterface $node | ||
* @param string $term | ||
*/ | ||
public function indexAction(NodeInterface $node, $term) { | ||
$request = array( | ||
'suggests' => array( | ||
'text' => $term, | ||
'term' => array( | ||
'field' => '_all' | ||
) | ||
) | ||
); | ||
|
||
$response = $this->elasticSearchClient->getIndex()->request('GET', '/_suggest', array(), json_encode($request))->getTreatedContent(); | ||
$suggestions = array_map(function($option) { | ||
return $option['text']; | ||
}, $response['suggests'][0]['options']); | ||
|
||
$this->view->assign('value', $suggestions); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
privilegeTargets: | ||
TYPO3\Flow\Security\Authorization\Privilege\Method\MethodPrivilege: | ||
Flowpack_SearchPlugin_Controller_SuggestController: | ||
matcher: method(Flowpack\SearchPlugin\Controller\SuggestController->indexAction()) | ||
|
||
roles: | ||
'TYPO3.Flow:Everybody': | ||
privileges: | ||
- | ||
privilegeTarget: Flowpack_SearchPlugin_Controller_SuggestController | ||
permission: GRANT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# DataSourceController routes | ||
- | ||
name: 'flowpack/searchplugin - SuggestController->index' | ||
uriPattern: 'flowpack/searchplugin' | ||
defaults: | ||
'@package': 'Flowpack.SearchPlugin' | ||
'@controller': 'Suggest' | ||
'@action': 'index' | ||
'@format': 'json' | ||
appendExceedingArguments: TRUE | ||
httpMethods: ['GET'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<form action="" method="GET"> | ||
<input type="text" name="search" value="{searchWord}" /> | ||
<button type="submit">Send</button> | ||
<form method="GET"> | ||
<input type="search" name="search" value="{searchWord}" placeholder="Search" data-autocomplete-source="{f:uri.action(action: 'index', controller: 'Suggest', package: 'Flowpack.SearchPlugin', format: 'json' absolute: 1, arguments: {node: node})}" /> | ||
<button type="submit">Search</button> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters