Skip to content

Commit b61bb0a

Browse files
committed
MERGE: Merge branch 'master' into instructions-custom-index-name
2 parents dcd71cf + 6418f59 commit b61bb0a

4 files changed

Lines changed: 65 additions & 13 deletions

File tree

Classes/Controller/SuggestController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,8 @@ protected function extractCompletions($response)
178178
*/
179179
protected function extractSuggestions($response)
180180
{
181-
if ($this->elasticSearchClient === null) {
182-
throw new \RuntimeException('The SuggestController needs an ElasticSearchClient, it seems you run without the flowpack/elasticsearch-contentrepositoryadaptor package, though.', 1487189823);
183-
}
184181
$suggestionOptions = isset($response['suggest']) ? $response['suggest'] : [];
182+
185183
if (count($suggestionOptions['suggestions'][0]['options']) > 0) {
186184
return $suggestionOptions['suggestions'][0]['options'];
187185
}

Configuration/NodeTypes.Mixins.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
dimensionCombinationHash:
1717
type: category
1818
path: '__dimensionCombinationHash'
19-
indexing: "${Flowpack.SearchPlugin.Suggestion.build(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)}"
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)}"
2020

2121
'Flowpack.SearchPlugin:AutocompletableMixin':
2222
abstract: true

README.md

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Flowpack.SearchPlugin
22

33
This plugin is a Search Plugin, to be used together with
4+
45
* [Flowpack.ElasticSearch.ContentRepositoryAdaptor](https://github.com/Flowpack/Flowpack.ElasticSearch.ContentRepositoryAdaptor) or
56
* [Flowpack.SimpleSearch.ContentRepositoryAdaptor](https://github.com/Flowpack/Flowpack.SimpleSearch.ContentRepositoryAdaptor).
67

@@ -76,7 +77,7 @@ Thus you can easily adjust the rendering per type like this for an imaginary `Ac
7677

7778
Feel free to use the `DocumentSearchResult.html` in the Flowpack.SearchPlugin as an example.
7879

79-
## Search suggestions
80+
## Search completions and suggestions
8081

8182
The default search form template comes with a `data-autocomplete-source` attribute pointing to the
8283
`SuggestController` of this package. Fed with a `term` parameter via a `GET` request, it returns a
@@ -86,14 +87,67 @@ the `_all` field, i.e. "the fulltext index".
8687
These can be used to provide autocompletion on the search input using a JS library of your choice.
8788
In case you need to build the URI to the suggest controller yourself, this is what the form uses:
8889

89-
{f:uri.action(action: 'index', controller: 'Suggest', package: 'Flowpack.SearchPlugin', format: 'json', absolute: 1)}
90+
{f:uri.action(action: 'index', controller: 'Suggest', package: 'Flowpack.SearchPlugin', format: 'json', absolute: 1, arguments: {contextNodeIdentifier: node.identifier, dimensionCombination: dimensionCombination})}
91+
92+
The returned JSON looks like this (with a `term` of "content" after indexing the Neos demo site):
93+
94+
{
95+
"completions": [
96+
"content",
97+
"content element",
98+
"content in",
99+
"content in neos",
100+
"content in neos because",
101+
"content in neos because you",
102+
"content repository"
103+
],
104+
"suggestions": [
105+
{
106+
"text": "995c9174-ddd6-4d5c-cfc0-1ffc82184677",
107+
"score": 20,
108+
"payload": {
109+
"nodeIdentifier": "d17caff2-f50c-d30b-b735-9b9216de02e9"
110+
}
111+
},
112+
{
113+
"text": "a66ec7db-3459-b67b-7bcb-16e2508a89f0",
114+
"score": 20,
115+
"payload": {
116+
"nodeIdentifier": "fd283257-9b12-8412-f922-6643ac818294"
117+
}
118+
},
119+
{
120+
"text": "a3474e1d-dd60-4a84-82b1-18d2f21891a3",
121+
"score": 20,
122+
"payload": {
123+
"nodeIdentifier": "7eee2ee6-2a4e-5240-3674-2fb84a51900b"
124+
}
125+
}
126+
]
127+
}
128+
129+
The `completions` can be used to suggest search terms to the user. The `suggestions` contains
130+
"top search results" for the given term, the document they refer to is given in the `payload`.
90131

91132
## AJAX search
92133

93134
The plugin comes with a controller that can be reached like this per default, using `GET`:
94135

95-
{f:uri.action(action: 'index', controller: 'AjaxSearch', package: 'Flowpack.SearchPlugin', absolute: 1)}
136+
{f:uri.action(action: 'search', controller: 'AjaxSearch', package: 'Flowpack.SearchPlugin', arguments: {node: node, q: ''}, absolute: 1)}
96137

97138
It expects the search term as a parameter named `q` (as defined in `AjaxSearch.fusion`). This controller
98139
renders the search results and returns them as HTML without any of the page template. It can therefore
99140
be used to request search results via AJAX and display the result by adding it to the DOM as needed.
141+
142+
## Removing special chars from search term
143+
144+
You might need to remove special chars to prevent search errors. Some chars are reserved in Elasticsearch
145+
and you can replace them before submitting the search like this:
146+
147+
prototype(Flowpack.SearchPlugin:Search) {
148+
searchTerm = ${request.arguments.search}
149+
searchTerm.@process.removeSpecialChars = ${String.pregReplace(value, "/[^a-zA-Z0-9äöüÄÖÜß]/", "")}
150+
}
151+
152+
Keep in mind, that this blocks the explicit use of wildcards (`*`) and phrase search (`"search exactly this"`)
153+
for your users, in case you want to support that.

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"type": "neos-package",
55
"description": "Plugin for search integration via content node",
66
"require": {
7-
"neos/content-repository": "^3.0",
8-
"neos/content-repository-search": "^3.0",
9-
"neos/eel": "^4.0",
10-
"neos/flow": "^4.0",
11-
"neos/fusion": "^3.0",
12-
"neos/neos": "^3.0"
7+
"neos/content-repository": "^3.0 || ^4.0 || dev-master",
8+
"neos/content-repository-search": "^3.0 || ^4.0 || dev-master",
9+
"neos/eel": "^4.0 || ^5.0 || dev-master",
10+
"neos/flow": "^4.0 || ^5.0 || dev-master",
11+
"neos/fusion": "^3.0 || ^4.0 || dev-master",
12+
"neos/neos": "^3.0 || ^4.0 || dev-master"
1313
},
1414
"suggest": {
1515
"flowpack/elasticsearch-contentrepositoryadaptor": "Provides search using Elasticsearch",

0 commit comments

Comments
 (0)