Skip to content

Commit 40f7c4d

Browse files
committed
TASK: Adjust search completions and suggestions to ES 5.x
1 parent 139db78 commit 40f7c4d

4 files changed

Lines changed: 64 additions & 30 deletions

File tree

Classes/Controller/SuggestController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ protected function buildRequestForTerm($term, $contextNodeIdentifier, $dimension
132132
]
133133
])
134134
->suggestions('suggestions', [
135-
'text' => $termPlaceholder,
135+
'prefix' => $termPlaceholder,
136136
'completion' => [
137137
'field' => '__suggestions',
138138
'fuzzy' => true,

Classes/EelHelper/SuggestionIndexHelper.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ class SuggestionIndexHelper implements ProtectedContextAwareInterface
2929
* @param int $weight A positive integer or a string containing a positive integer, which defines a weight and allows you to rank your suggestions.
3030
* @return array
3131
*/
32-
public function build($input, $output = '', array $payload = [], $weight = 1)
32+
public function build($input, $weight = 1)
3333
{
3434
return [
3535
'input' => $this->prepareInput($input),
36-
'output' => $this->prepareOutput($output),
37-
'payload' => json_encode($payload),
3836
'weight' => $weight
3937
];
4038
}
@@ -66,15 +64,6 @@ protected function prepareInput($input)
6664
}
6765
}
6866

69-
/**
70-
* @param string $input
71-
* @return array
72-
*/
73-
protected function prepareOutput($input)
74-
{
75-
return strip_tags($input);
76-
}
77-
7867
/**
7968
* All methods are considered safe
8069
*

Configuration/NodeTypes.Mixins.yaml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,28 @@
55
search:
66
elasticSearchMapping:
77
type: completion
8-
payloads: true
9-
context:
10-
workspace:
8+
contexts:
9+
-
10+
name: 'workspace'
1111
type: category
1212
path: '__workspace'
13-
parentPath:
13+
-
14+
name: 'parentPath'
1415
type: category
1516
path: '__parentPath'
16-
dimensionCombinationHash:
17+
-
18+
name: 'dimensionCombinationHash'
1719
type: category
1820
path: '__dimensionCombinationHash'
19-
indexing: "${Flowpack.SearchPlugin.Suggestion.build(q(node).property('title') ? q(node).property('title') : '', q(node).is('[instanceof Neos.Neos:Document]') ? node.identifier : q(node).parents('[instanceof Neos.Neos:Document]').get(0).identifier, {nodeIdentifier: node.identifier}, 20)}"
21+
indexing: "${Flowpack.SearchPlugin.Suggestion.build(q(node).property('title') ? q(node).property('title') : '', 20)}"
2022

2123
'Flowpack.SearchPlugin:AutocompletableMixin':
2224
abstract: true
2325
properties:
2426
'__completion':
2527
search:
2628
elasticSearchMapping:
27-
type: string
29+
type: text
2830
analyzer: autocomplete
31+
fielddata: true
2932
indexing: "${String.stripTags(q(node).property('title'))}"

README.md

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This plugin is a Search Plugin, to be used together with
44

5-
* [Flowpack.ElasticSearch.ContentRepositoryAdaptor](https://github.com/Flowpack/Flowpack.ElasticSearch.ContentRepositoryAdaptor) or
5+
* [Flowpack.ElasticSearch.ContentRepositoryAdaptor](https://github.com/Flowpack/Flowpack.ElasticSearch.ContentRepositoryAdaptor) or
66
* [Flowpack.SimpleSearch.ContentRepositoryAdaptor](https://github.com/Flowpack/Flowpack.SimpleSearch.ContentRepositoryAdaptor).
77

88
## Installation
@@ -34,7 +34,7 @@ To specify a custom index name, the following is needed:
3434
elasticSearch:
3535
indexName: acmecom
3636

37-
### Pagination
37+
### Pagination
3838

3939
The pagination search results can be configured via Fusion. The following shows the defaults:
4040

@@ -58,7 +58,7 @@ Feel free to use the `DocumentSearchResult.html` in the Flowpack.SearchPlugin as
5858

5959
## Search completions and suggestions
6060

61-
The default search form template comes with a `data-autocomplete-source` attribute pointing to the
61+
The default search form template comes with a `data-autocomplete-source` attribute pointing to the
6262
`SuggestController` of this package.
6363

6464
To use this term suggester, you need to configure the indexing like this, to define a custom
@@ -89,12 +89,12 @@ done like this:
8989
superTypes:
9090
'Flowpack.SearchPlugin:SuggestableMixin': true
9191
'Flowpack.SearchPlugin:AutocompletableMixin': true
92-
92+
9393
'Neos.Neos:Shortcut':
9494
superTypes:
9595
'Flowpack.SearchPlugin:SuggestableMixin': false
9696
'Flowpack.SearchPlugin:AutocompletableMixin': false
97-
97+
9898
'Neos.NodeTypes:TitleMixin':
9999
superTypes:
100100
'Flowpack.SearchPlugin:SuggestableMixin': true
@@ -124,23 +124,65 @@ The returned JSON looks like this (with a `term` of "content" after indexing the
124124
"suggestions": [
125125
{
126126
"text": "995c9174-ddd6-4d5c-cfc0-1ffc82184677",
127-
"score": 20,
127+
"_index": "acmecom-1536833562",
128+
"_type": "Neos-Neos:Page",
129+
"_id": "03da089f6495852dc9e7b796adde85f21093b3c7",
130+
"score": 40,
128131
"payload": {
129-
"nodeIdentifier": "d17caff2-f50c-d30b-b735-9b9216de02e9"
132+
"__path": "/sites/acmecom/node-2"
133+
},
134+
"contexts": {
135+
"workspace": {
136+
0: "live"
137+
},
138+
"parentPath": {
139+
0: "/sites/acmecom"
140+
},
141+
"dimensionCombinationHash": {
142+
0: "d751713988987e9331980363e24189ce"
143+
},
130144
}
131145
},
132146
{
133147
"text": "a66ec7db-3459-b67b-7bcb-16e2508a89f0",
148+
"_index": "acmecom-1536833562",
149+
"_type": "Neos-Neos:Page",
150+
"_id": "151a1d0531f1ac5c1a267a3d6a3af84967e0c35f",
134151
"score": 20,
135152
"payload": {
136-
"nodeIdentifier": "fd283257-9b12-8412-f922-6643ac818294"
153+
"__path": "/sites/acmecom/node-1"
154+
},
155+
"contexts": {
156+
"workspace": {
157+
0: "live"
158+
},
159+
"parentPath": {
160+
0: "/sites/acmecom"
161+
},
162+
"dimensionCombinationHash": {
163+
0: "d751713988987e9331980363e24189ce"
164+
},
137165
}
138166
},
139167
{
140168
"text": "a3474e1d-dd60-4a84-82b1-18d2f21891a3",
169+
"_index": "acmecom-1536833562",
170+
"_id": "c443d53c76de1af2438b8af0bf33dc7befe291f5",
171+
"_type": "Neos-Neos:Page",
141172
"score": 20,
142-
"payload": {
143-
"nodeIdentifier": "7eee2ee6-2a4e-5240-3674-2fb84a51900b"
173+
"_source": {
174+
"__path": "/sites/acmecom/node-3"
175+
},
176+
"contexts": {
177+
"workspace": {
178+
0: "live"
179+
},
180+
"parentPath": {
181+
0: "/sites/acmecom"
182+
},
183+
"dimensionCombinationHash": {
184+
0: "d751713988987e9331980363e24189ce"
185+
},
144186
}
145187
}
146188
]

0 commit comments

Comments
 (0)