11# Flowpack.SearchPlugin
22
33This 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
7778Feel free to use the ` DocumentSearchResult.html ` in the Flowpack.SearchPlugin as an example.
7879
79- ## Search suggestions
80+ ## Search completions and suggestions
8081
8182The 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".
8687These can be used to provide autocompletion on the search input using a JS library of your choice.
8788In 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
93134The 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
97138It expects the search term as a parameter named ` q ` (as defined in ` AjaxSearch.fusion ` ). This controller
98139renders the search results and returns them as HTML without any of the page template. It can therefore
99140be 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.
0 commit comments