Skip to content

Commit 1a7bd8b

Browse files
committed
Merge pull request #9 from beheist/master
[FEATURE] Add support for search via AJAX
2 parents f694508 + c8a74cc commit 1a7bd8b

7 files changed

Lines changed: 83 additions & 9 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
namespace Flowpack\SearchPlugin\Controller;
3+
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+
* */
13+
14+
use TYPO3\Flow\Annotations as Flow;
15+
use TYPO3\Flow\Mvc\Controller\ActionController;
16+
use TYPO3\TYPO3CR\Domain\Model\NodeInterface;
17+
18+
/**
19+
* Class AjaxSearchController
20+
*
21+
* @author Sebastian Kurfürst <sk@sandstorm.de>
22+
* @author Bastian Heist <bh@sandstorm.de>
23+
* @package Flowpack\SearchPlugin\Controller
24+
*/
25+
class AjaxSearchController extends ActionController {
26+
27+
/**
28+
* Override the default view from the ActionController to output TypoScript directly
29+
*
30+
* @var string
31+
* @api
32+
*/
33+
protected $defaultViewObjectName = \TYPO3\Neos\View\TypoScriptView::class;
34+
35+
/**
36+
* @param NodeInterface $node
37+
*/
38+
public function searchAction(NodeInterface $node) {
39+
/* @var $view \TYPO3\Neos\View\TypoScriptView */
40+
$view = $this->view;
41+
$view->setTypoScriptPath('ajaxSearch');
42+
$view->assign('value', $node);
43+
}
44+
45+
}

Configuration/Policy.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ privilegeTargets:
22
TYPO3\Flow\Security\Authorization\Privilege\Method\MethodPrivilege:
33
Flowpack_SearchPlugin_Controller_SuggestController:
44
matcher: method(Flowpack\SearchPlugin\Controller\SuggestController->indexAction())
5+
Flowpack_SearchPlugin_Controller_AjaxSearchController:
6+
matcher: method(Flowpack\SearchPlugin\Controller\AjaxSearchController->searchAction())
57

68
roles:
79
'TYPO3.Flow:Everybody':
810
privileges:
911
-
1012
privilegeTarget: Flowpack_SearchPlugin_Controller_SuggestController
13+
permission: GRANT
14+
-
15+
privilegeTarget: Flowpack_SearchPlugin_Controller_AjaxSearchController
1116
permission: GRANT

Configuration/Routes.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,14 @@
88
'@action': 'index'
99
'@format': 'json'
1010
appendExceedingArguments: TRUE
11+
httpMethods: ['GET']
12+
-
13+
name: 'flowpack/searchplugin - SuggestController->ajax'
14+
uriPattern: 'flowpack/ajaxsearch'
15+
defaults:
16+
'@package': 'Flowpack.SearchPlugin'
17+
'@controller': 'AjaxSearch'
18+
'@action': 'search'
19+
'@format': 'html'
20+
appendExceedingArguments: TRUE
1121
httpMethods: ['GET']
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div{attributes -> f:format.raw()}>
2+
{searchResultRenderer -> f:format.raw()}
3+
</div>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
prototype(Flowpack.SearchPlugin:AjaxSearch) < prototype(TYPO3.TypoScript:Template) {
2+
templatePath = 'resource://Flowpack.SearchPlugin/Private/Templates/NodeTypes/AjaxSearch.html'
3+
searchResultRenderer = Flowpack.SearchPlugin:SearchResultRenderer {
4+
@override.searchResults = ${Search.query(site).fulltext(request.arguments.q).execute()}
5+
}
6+
}

Resources/Private/TypoScript/Root.ts2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ prototype(Flowpack.SearchPlugin:CanRender).@class = 'Flowpack\\SearchPlugin\\Typ
22

33
include: SearchPlugin.ts2
44
include: ResultRendering.ts2
5+
include: AjaxSearch.ts2
6+
7+
ajaxSearch = Flowpack.SearchPlugin:AjaxSearch

Resources/Private/TypoScript/SearchPlugin.ts2

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,9 @@ prototype(Flowpack.SearchPlugin:Search) {
77

88
searchForm = Flowpack.SearchPlugin:Search.Form
99

10-
searchResultRenderer = TYPO3.TypoScript:Collection {
11-
// the "searchResults" are filled from the <search:widget.paginate> ViewHelper.
12-
collection = ${searchResults}
13-
itemRenderer = Flowpack.SearchPlugin:SingleResult
14-
itemName = 'node'
15-
// we also make the full ElasticSearch hit available to nested rendering, if possible
16-
itemRenderer.@override.searchHit = ${searchResults.searchHitForNode(node)}
17-
}
10+
searchResultRenderer = Flowpack.SearchPlugin:SearchResultRenderer
1811

19-
searchResultRenderer.@process.wrap = ${'<ol>' + value + '</ol>'}
12+
searchResultRenderer.@process.wrap = ${'<ol>' + value + '</ol>'}
2013
prototype(Flowpack.SearchPlugin:SingleResult).@process.wrap = ${'<li>' + value + '</li>'}
2114

2215
@cache {
@@ -33,4 +26,13 @@ prototype(Flowpack.SearchPlugin:Search.Form) < prototype(TYPO3.TypoScript:Templa
3326
node = ${site}
3427
templatePath = 'resource://Flowpack.SearchPlugin/Private/Templates/NodeTypes/Search.Form.html'
3528
searchWord = ${request.arguments.search}
29+
}
30+
31+
prototype(Flowpack.SearchPlugin:SearchResultRenderer) < prototype(TYPO3.TypoScript:Collection) {
32+
// the "searchResults" are filled from the <search:widget.paginate> ViewHelper.
33+
collection = ${searchResults}
34+
itemRenderer = Flowpack.SearchPlugin:SingleResult
35+
itemName = 'node'
36+
// we also make the full ElasticSearch hit available to nested rendering, if possible
37+
itemRenderer.@override.searchHit = ${searchResults.searchHitForNode(node)}
3638
}

0 commit comments

Comments
 (0)