Skip to content

Commit 75473a3

Browse files
Merge pull request #65 from daniellienert/bugfix/fix-suggestion-context
!!! BUGFIX: Contexts are respected in a multi-site environment.
2 parents 74d9af0 + 0e0951c commit 75473a3

3 files changed

Lines changed: 37 additions & 13 deletions

File tree

Classes/Controller/SuggestController.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Eel\ElasticSearchQueryBuilder;
1515
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\ElasticSearchClient;
1616
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception\QueryBuildingException;
17+
use Flowpack\SearchPlugin\EelHelper\SuggestionIndexHelper;
1718
use Flowpack\SearchPlugin\Utility\SearchTerm;
1819
use Neos\Cache\Frontend\VariableFrontend;
1920
use Neos\Flow\Annotations as Flow;
@@ -41,6 +42,12 @@ class SuggestController extends ActionController
4142
*/
4243
protected $elasticSearchQueryTemplateCache;
4344

45+
/**
46+
* @Flow\Inject
47+
* @var SuggestionIndexHelper
48+
*/
49+
protected $suggestionIndexHelper;
50+
4451
/**
4552
* @var array
4653
*/
@@ -153,8 +160,7 @@ protected function buildRequestForTerm(string $term, string $contextNodeIdentifi
153160
'fuzzy' => true,
154161
'size' => $this->searchAsYouTypeSettings['suggestions']['size'] ?? 10,
155162
'contexts' => [
156-
'parent_path' => $contextNode->getPath(),
157-
'workspace' => 'live',
163+
'suggestion_context' => $this->suggestionIndexHelper->buildContext($contextNode)
158164
]
159165
]
160166
]);

Classes/EelHelper/SuggestionIndexHelper.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use Flowpack\SearchPlugin\Exception;
1717
use Flowpack\SearchPlugin\Utility\SearchTerm;
18+
use Neos\ContentRepository\Domain\Model\NodeInterface;
1819
use Neos\Eel\ProtectedContextAwareInterface;
1920
use Neos\Flow\Annotations as Flow;
2021

@@ -25,20 +26,38 @@
2526
*/
2627
class SuggestionIndexHelper implements ProtectedContextAwareInterface
2728
{
29+
30+
/**
31+
* Rhe length of '/sites/'
32+
* @var int
33+
*/
34+
protected const SITES_OFFSET = 7;
35+
2836
/**
2937
* @param string|array $input The input to store, this can be a an array of strings or just a string. This field is mandatory.
3038
* @param int $weight A positive integer or a string containing a positive integer, which defines a weight and allows you to rank your suggestions.
3139
* @return array
3240
* @throws Exception
3341
*/
34-
public function build($input, $weight = 1)
42+
public function build($input, $weight = 1): array
3543
{
3644
return [
3745
'input' => $this->prepareInput($input),
3846
'weight' => $weight
3947
];
4048
}
4149

50+
public function buildContext(NodeInterface $node): string
51+
{
52+
$siteName = substr($node->getPath(), self::SITES_OFFSET, strpos($node->getPath() . '/', '/', self::SITES_OFFSET) - self::SITES_OFFSET);
53+
return sprintf(
54+
'%s-%s-%s',
55+
$siteName,
56+
$node->getWorkspace()->getName(),
57+
$node->isHidden() ? 'hidden' : 'visible'
58+
);
59+
}
60+
4261
/**
4362
* @param string|array $input
4463
* @return array
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
'Flowpack.SearchPlugin:SuggestableMixin':
22
abstract: true
33
properties:
4+
'neos_suggestion_context':
5+
search:
6+
elasticSearchMapping:
7+
type: keyword
8+
indexing: "${Flowpack.SearchPlugin.Suggestion.buildContext(node)}"
9+
410
'neos_suggestion':
511
search:
612
elasticSearchMapping:
713
type: completion
814
contexts:
915
-
10-
name: 'workspace'
11-
type: category
12-
path: 'neos_workspace'
13-
-
14-
name: 'parent_path'
15-
type: category
16-
path: 'neos_parent_path'
17-
-
18-
name: 'hidden'
16+
name: 'suggestion_context'
1917
type: category
20-
path: 'neos_hidden'
18+
path: 'neos_suggestion_context'
19+
2120
indexing: "${Flowpack.SearchPlugin.Suggestion.build(q(node).property('title') ? q(node).property('title') : '', 20)}"

0 commit comments

Comments
 (0)