Skip to content

Commit aa86f1c

Browse files
committed
FEATURE: Add a eel helper for searchterm processing
1 parent 2bfbb20 commit aa86f1c

7 files changed

Lines changed: 42 additions & 6 deletions

File tree

Classes/Controller/SuggestController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ protected function buildRequestForTerm(string $term, string $contextNodeIdentifi
116116

117117
// The suggest function only works well with one word
118118
// special search characters are escaped
119-
$suggestTerm = SearchTerm::sanitizeSearchInput(explode(' ', $term)[0]);
119+
$suggestTerm = SearchTerm::sanitize(explode(' ', $term)[0]);
120120

121121
if (!$this->elasticSearchQueryTemplateCache->has($cacheKey)) {
122122
$contentContext = $this->createContentContext('live', $dimensionCombination ? json_decode($dimensionCombination, true) : []);

Classes/EelHelper/SearchArrayHelper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace Flowpack\SearchPlugin\EelHelper;
35

46
/*
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Flowpack\SearchPlugin\EelHelper;
5+
6+
/*
7+
* This file is part of the Flowpack.SearchPlugin package.
8+
*
9+
* (c) Contributors of the Flowpack Team - flowpack.org
10+
*
11+
* This package is Open Source Software. For the full copyright and license
12+
* information, please view the LICENSE file which was distributed with this
13+
* source code.
14+
*/
15+
16+
use Flowpack\SearchPlugin\Utility\SearchTerm;
17+
use Neos\Eel\ProtectedContextAwareInterface;
18+
19+
class SearchTermHelper implements ProtectedContextAwareInterface
20+
{
21+
22+
public function sanitize(string $term): string
23+
{
24+
return SearchTerm::sanitize($term);
25+
}
26+
27+
public function allowsCallOfMethod($methodName)
28+
{
29+
return true;
30+
}
31+
}

Classes/EelHelper/SuggestionIndexHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected function prepareInput($input): ?array
4848
{
4949
$process = static function (?string $input) {
5050
$input = preg_replace("/\r|\n/", '', $input);
51-
return array_values(array_filter(explode(' ', SearchTerm::sanitizeSearchInput(strip_tags($input)))));
51+
return array_values(array_filter(explode(' ', SearchTerm::sanitize(strip_tags($input)))));
5252
};
5353

5454
if (\is_string($input)) {

Classes/Utility/SearchTerm.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515

1616
class SearchTerm
1717
{
18-
19-
public static function sanitizeSearchInput(string $input): string
18+
public static function sanitize(string $input): string
2019
{
2120
return str_replace(['=', '>', '<', '(', ')', '{', '}', '[', ']', '^', '"', '~', '*', '?', ':', '\\', '/'], ['', '', '', '(', '\)', '\{', '\}', '\[', '\]', '\^', '\"', '\~', '\*', '\?', '\:', '\\\\', '\/'], $input);
2221
}
23-
2422
}

Configuration/NodeTypes.Mixin.Suggestable.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@
1313
-
1414
name: 'parent_path'
1515
type: category
16-
path: 'neos_parent_path '
16+
path: 'neos_parent_path'
17+
-
18+
name: 'hidden'
19+
type: category
20+
path: 'neos_hidden'
1721
indexing: "${Flowpack.SearchPlugin.Suggestion.build(q(node).property('title') ? q(node).property('title') : '', 20)}"

Configuration/Settings.Neos.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Neos:
77
Fusion:
88
defaultContext:
99
Flowpack.SearchPlugin.Array: Flowpack\SearchPlugin\EelHelper\SearchArrayHelper
10+
Flowpack.SearchPlugin.SearchTerm: Flowpack\SearchPlugin\EelHelper\SearchTermHelper
1011
Neos:
1112
fusion:
1213
autoInclude:

0 commit comments

Comments
 (0)