### Install SearchPlugin via Composer
Source: https://github.com/flowpack/flowpack.searchplugin/blob/main/README.md
Use these commands to install the plugin along with your preferred search adaptor.
```bash
composer require flowpack/searchplugin flowpack/elasticsearch-contentrepositoryadaptor
```
```bash
composer require flowpack/searchplugin flowpack/simplesearch-contentrepositoryadaptor
```
--------------------------------
### Implement SuggestionContext
Source: https://context7.com/flowpack/flowpack.searchplugin/llms.txt
Demonstrates the default usage of SuggestionContext and how to implement a custom class by implementing SuggestionContextInterface.
```php
// Default SuggestionContext implementation
use Flowpack\SearchPlugin\Suggestion\SuggestionContext;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
$context = new SuggestionContext();
// Build context for indexing (includes actual node visibility)
$indexContext = $context->buildForIndex($node);
// Returns context like: "mysite_live_hidden" or "mysite_live_visible"
// Build context for searching (always searches visible nodes only)
$searchContext = $context->buildForSearch($node);
// Returns context like: "mysite_live_visible"
$identifier = $searchContext->getContextIdentifier();
// Result: "mysite_live_visible"
// Custom SuggestionContext implementation in Objects.yaml:
Flowpack\SearchPlugin\Suggestion\SuggestionContextInterface:
className: 'Your\Package\Suggestion\CustomSuggestionContext'
// Custom implementation example:
namespace Your\Package\Suggestion;
use Flowpack\SearchPlugin\Suggestion\SuggestionContextInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
class CustomSuggestionContext implements SuggestionContextInterface
{
public function buildForIndex(Node $node): SuggestionContextInterface
{
// Include SEO noindex flag in context
$this->contextValues = [
'siteName' => $this->getSiteName($node),
'workspace' => $node->workspaceName->value,
'isHidden' => $node->tags->contain(NeosSubtreeTag::disabled()) ? 'hidden' : 'visible',
'isIndexable' => $this->getNoIndexProperty($node) ? 'noindex' : 'index',
];
return $this;
}
public function buildForSearch(Node $node): SuggestionContextInterface
{
$this->contextValues = [
'siteName' => $this->getSiteName($node),
'workspace' => $node->workspaceName->value,
'isHidden' => 'visible',
'isIndexable' => 'index',
];
return $this;
}
public function getContextIdentifier(): string
{
return implode('_', $this->contextValues);
}
}
```
--------------------------------
### Implement Autocomplete API
Source: https://context7.com/flowpack/flowpack.searchplugin/llms.txt
Demonstrates the SuggestController usage via curl, Fluid URI generation, and a JavaScript implementation for handling autocomplete suggestions.
```bash
curl -X GET "https://example.com/flowpack/searchplugin?term=prod&contextNode={nodeAddressJson}" \
-H "Accept: application/json"
```
```json
{
"completions": ["product", "production", "productivity"],
"suggestions": [
{
"title": "Product Overview",
"neos_path": "/products/overview"
},
{
"title": "Product Catalog",
"neos_path": "/products/catalog"
}
]
}
```
```html
{f:uri.action(
action: 'index',
controller: 'Suggest',
package: 'Flowpack.SearchPlugin',
format: 'json',
absolute: 1,
arguments: {contextNode: node}
)}
```
```javascript
const searchInput = document.querySelector('[data-autocomplete-source]');
const suggestUrl = searchInput.dataset.autocompleteSource;
searchInput.addEventListener('input', async (e) => {
const term = e.target.value;
if (term.length < 2) return;
const response = await fetch(`${suggestUrl}&term=${encodeURIComponent(term)}`);
const data = await response.json();
// Handle completions (word completions)
console.log('Completions:', data.completions);
// Handle suggestions (document suggestions with metadata)
console.log('Suggestions:', data.suggestions);
});
```
--------------------------------
### Configure Pagination via Fusion
Source: https://github.com/flowpack/flowpack.searchplugin/blob/main/README.md
Adjust pagination settings for search results using the Fusion prototype.
```fusion
prototype(Flowpack.SearchPlugin:Search).configuration {
itemsPerPage = 25
insertAbove = false
insertBelow = true
maximumNumberOfLinks = 10
}
```
--------------------------------
### Configure Search Fusion Prototype
Source: https://context7.com/flowpack/flowpack.searchplugin/llms.txt
Configures the Search prototype for rendering search results, pagination, and sanitizing search terms.
```fusion
// Default Search prototype configuration
prototype(Flowpack.SearchPlugin:Search) < prototype(Neos.Neos:Content) {
templatePath = 'resource://Flowpack.SearchPlugin/Private/Fusion/Content/SearchPlugin/Search/Search.html'
// Get search term from request
searchTerm = ${String.toString(request.arguments.search)}
// Build search query using Content Repository Search
searchQuery = ${this.searchTerm ? Search.query(site).fulltext(this.searchTerm).nodeType('Neos.Neos:Document') : null}
totalSearchResults = ${this.searchQuery.count()}
// Search form component
searchForm = Flowpack.SearchPlugin:Search.Form
// Pagination configuration
configuration = Neos.Fusion:DataStructure {
itemsPerPage = 25
insertAbove = false
insertBelow = true
maximumNumberOfLinks = 10
}
// Result renderer with list wrapper
searchResultRenderer = Neos.Fusion:Tag {
tagName = 'ol'
content = Flowpack.SearchPlugin:SearchResultRenderer
}
prototype(Flowpack.SearchPlugin:SingleResult).@process.wrap = ${'
' + value + ''}
@cache {
mode = 'uncached'
context {
1 = 'site'
2 = 'node'
3 = 'documentNode'
}
}
}
// Customizing pagination settings
prototype(Flowpack.SearchPlugin:Search).configuration {
itemsPerPage = 10
insertAbove = true
insertBelow = true
maximumNumberOfLinks = 5
}
// Using sanitized search term
prototype(Flowpack.SearchPlugin:Search) {
searchTerm = ${Flowpack.SearchPlugin.SearchTerm.sanitize(request.arguments.search)}
}
```
--------------------------------
### Generate Suggest Controller URI
Source: https://github.com/flowpack/flowpack.searchplugin/blob/main/README.md
Use this Fluid view helper to generate the URI for the SuggestController.
```html
{f:uri.action(action: 'index', controller: 'Suggest', package: 'Flowpack.SearchPlugin', format: 'json', absolute: 1, arguments: {contextNodeIdentifier: node.identifier, dimensionCombination: dimensionCombination})}
```
--------------------------------
### Render Custom Search Results with Fusion
Source: https://context7.com/flowpack/flowpack.searchplugin/llms.txt
Defines the default result rendering logic and demonstrates how to create custom templates for specific node types like Products or News.
```fusion
// Default single result renderer (uses nodeType + 'SearchResult' convention)
prototype(Flowpack.SearchPlugin:SingleResult) < prototype(Neos.Fusion:Case) {
default {
condition = Neos.Fusion:CanRender {
type = ${node.nodeTypeName + 'SearchResult'}
}
type = ${node.nodeTypeName + 'SearchResult'}
}
fallback {
condition = true
type = 'Neos.Neos:DocumentSearchResult'
}
}
// Default Document search result template
prototype(Neos.Neos:DocumentSearchResult) < prototype(Neos.Fusion:Template) {
templatePath = 'resource://Flowpack.SearchPlugin/Private/Fusion/Component/DocumentSearchResult/DocumentSearchResult.html'
node = ${node}
highlight = ${Flowpack.SearchPlugin.Array.flatten(searchHit.highlight)}
title = ${q(node).property('title')}
description = ''
parents = ${Array.reverse(q(node).parents('[instanceof Neos.Neos:Document]').get())}
}
// Custom result template for Product node type
prototype(Acme.Site:ProductSearchResult) < prototype(Neos.Neos:DocumentSearchResult) {
templatePath = 'resource://Acme.Site/Private/Templates/SearchResult/ProductSearchResult.html'
// Add product-specific properties
price = ${q(node).property('price')}
sku = ${q(node).property('sku')}
image = ${q(node).property('mainImage')}
}
// Custom result template for News articles
prototype(Acme.Site:NewsSearchResult) < prototype(Neos.Neos:DocumentSearchResult) {
templatePath = 'resource://Acme.Site/Private/Templates/SearchResult/NewsSearchResult.html'
publishDate = ${q(node).property('publishDate')}
author = ${q(node).property('author')}
teaser = ${q(node).property('teaser')}
}
```
--------------------------------
### NodeType Configuration for Suggestion Indexing
Source: https://context7.com/flowpack/flowpack.searchplugin/llms.txt
Configure NodeTypes to integrate suggestion building and context generation using Flowpack Search Plugin helpers for search-as-you-type functionality.
```yaml
'Flowpack.SearchPlugin:SuggestableMixin':
abstract: true
properties:
'neos_suggestion_context':
search:
elasticSearchMapping:
type: keyword
indexing: "${Flowpack.SearchPlugin.Suggestion.buildContext(node)}"
'neos_suggestion':
search:
elasticSearchMapping:
type: completion
contexts:
-
name: 'suggestion_context'
type: category
path: 'neos_suggestion_context'
indexing: "${Flowpack.SearchPlugin.Suggestion.build(q(node).property('title'), 20)}"
```
--------------------------------
### Configure Elasticsearch Analyzer
Source: https://context7.com/flowpack/flowpack.searchplugin/llms.txt
Sets up a custom analyzer in Elasticsearch to support shingle tokenization for partial matching.
```yaml
# Configuration/Settings.yaml for your site package:
Flowpack:
ElasticSearch:
indexes:
default: # client name
yourindexname: # your custom index name
settings:
analysis:
filter:
autocompleteFilter:
max_shingle_size: 5
min_shingle_size: 2
type: 'shingle'
analyzer:
autocomplete:
filter: ['lowercase', 'autocompleteFilter']
char_filter: ['html_strip']
type: 'custom'
tokenizer: 'standard'
```
--------------------------------
### Generate URI for AJAX Search
Source: https://github.com/flowpack/flowpack.searchplugin/blob/main/README.md
Use this Fusion URI helper to generate a link to the AJAX search controller. Ensure the 'q' parameter is empty when initially generating the URI.
```fusion
{f:uri.action(action: 'search', controller: 'AjaxSearch', package: 'Flowpack.SearchPlugin', arguments: {node: node, q: ''}, absolute: 1)}
```
--------------------------------
### Build Suggestion Index Entry with SuggestionIndexHelper
Source: https://context7.com/flowpack/flowpack.searchplugin/llms.txt
Utilize SuggestionIndexHelper to construct entries for Elasticsearch's completion suggester. It can build suggestions from string or array inputs, with an optional weight.
```php
use Flowpack\SearchPlugin\EelHelper\SuggestionIndexHelper;
$helper = new SuggestionIndexHelper();
// Build suggestion from string input
$suggestion = $helper->build('Product Overview Page', 20);
// Result: ['input' => ['Product', 'Overview', 'Page'], 'weight' => 20]
// Build suggestion from array input
$suggestion = $helper->build(['Product', 'Overview', 'Page Title'], 15);
// Result: ['input' => ['Product', 'Overview', 'Page', 'Title'], 'weight' => 15]
```
--------------------------------
### Configure Autocomplete and Suggestion Mixins
Source: https://context7.com/flowpack/flowpack.searchplugin/llms.txt
Applies search mixins to NodeTypes and defines the indexing properties for autocomplete and suggestion features.
```yaml
# Enable suggestions and autocomplete for Document nodes
# In your site package's NodeTypes.yaml:
'Neos.Neos:Document':
superTypes:
'Flowpack.SearchPlugin:SuggestableMixin': true
'Flowpack.SearchPlugin:AutocompletableMixin': true
# Disable for Shortcut nodes (shouldn't appear in suggestions)
'Neos.Neos:Shortcut':
superTypes:
'Flowpack.SearchPlugin:SuggestableMixin': false
'Flowpack.SearchPlugin:AutocompletableMixin': false
# Enable for content with titles
'Neos.NodeTypes:TitleMixin':
superTypes:
'Flowpack.SearchPlugin:SuggestableMixin': true
'Flowpack.SearchPlugin:AutocompletableMixin': true
# AutocompletableMixin configuration (NodeTypes.Mixin.Autocompletable.yaml):
'Flowpack.SearchPlugin:AutocompletableMixin':
abstract: true
properties:
'neos_completion':
search:
elasticSearchMapping:
type: text
analyzer: autocomplete
fielddata: true
indexing: "${String.stripTags(q(node).property('title'))}"
# SuggestableMixin configuration (NodeTypes.Mixin.Suggestable.yaml):
'Flowpack.SearchPlugin:SuggestableMixin':
abstract: true
properties:
'neos_suggestion_context':
search:
elasticSearchMapping:
type: keyword
indexing: "${Flowpack.SearchPlugin.Suggestion.buildContext(node)}"
'neos_suggestion':
search:
elasticSearchMapping:
type: completion
contexts:
-
name: 'suggestion_context'
type: category
path: 'neos_suggestion_context'
indexing: "${Flowpack.SearchPlugin.Suggestion.build(q(node).property('title') ? q(node).property('title') : '', 20)}"
```
--------------------------------
### Configure Plugin Settings
Source: https://context7.com/flowpack/flowpack.searchplugin/llms.txt
Set the number of autocomplete and suggestion results, and enable/disable these features. You can also specify custom fields to be included in suggestion responses.
```yaml
Flowpack:
SearchPlugin:
searchAsYouType:
autocomplete:
size: 10
enabled: true
suggestions:
size: 10
enabled: true
sourceFields:
- neos_path
- title
- __myCustomProperty
```
--------------------------------
### Sanitize Search Terms
Source: https://context7.com/flowpack/flowpack.searchplugin/llms.txt
Shows how to use the SearchTerm utility in PHP, Fusion templates, and the required configuration in Settings.Neos.yaml.
```php
use Flowpack\SearchPlugin\Utility\SearchTerm;
$sanitized = SearchTerm::sanitize('user input "with" special* chars?');
```
```fusion
prototype(Flowpack.SearchPlugin:Search) {
searchTerm = ${Flowpack.SearchPlugin.SearchTerm.sanitize(request.arguments.search)}
// Sanitized term used in query
searchQuery = ${this.searchTerm ? Search.query(site).fulltext(this.searchTerm) : null}
}
```
```yaml
Neos:
Fusion:
defaultContext:
Flowpack.SearchPlugin.SearchTerm: Flowpack\SearchPlugin\EelHelper\SearchTermHelper
```
--------------------------------
### Configure Node Types for Suggestions
Source: https://github.com/flowpack/flowpack.searchplugin/blob/main/README.md
Enable or disable suggestion and autocomplete mixins for specific node types.
```yaml
'Neos.Neos:Document':
superTypes:
'Flowpack.SearchPlugin:SuggestableMixin': true
'Flowpack.SearchPlugin:AutocompletableMixin': true
'Neos.Neos:Shortcut':
superTypes:
'Flowpack.SearchPlugin:SuggestableMixin': false
'Flowpack.SearchPlugin:AutocompletableMixin': false
'Neos.NodeTypes:TitleMixin':
superTypes:
'Flowpack.SearchPlugin:SuggestableMixin': true
'Flowpack.SearchPlugin:AutocompletableMixin': true
```
--------------------------------
### Autocomplete API (Suggest Controller)
Source: https://context7.com/flowpack/flowpack.searchplugin/llms.txt
Provides JSON-formatted autocomplete completions and document suggestions based on partial search terms.
```APIDOC
## GET /flowpack/searchplugin
### Description
This endpoint provides autocomplete suggestions and document suggestions based on a partial search term, utilizing Elasticsearch's completion suggester.
### Method
GET
### Endpoint
/flowpack/searchplugin
### Query Parameters
- **term** (string) - Required - The partial search term for autocomplete.
- **contextNode** (string) - Optional - The address of the context node for the search.
### Request Example
```bash
curl -X GET "https://example.com/flowpack/searchplugin?term=prod&contextNode={nodeAddressJson}" -H "Accept: application/json"
```
### Response
#### Success Response (200)
- **completions** (array of strings) - An array of word completions.
- **suggestions** (array of objects) - An array of document suggestions, each with a `title` and `neos_path`.
#### Response Example
```json
{
"completions": ["product", "production", "productivity"],
"suggestions": [
{
"title": "Product Overview",
"neos_path": "/products/overview"
},
{
"title": "Product Catalog",
"neos_path": "/products/catalog"
}
]
}
```
```
--------------------------------
### Configure AJAX Search Controller
Source: https://context7.com/flowpack/flowpack.searchplugin/llms.txt
Defines the route for the AjaxSearchController in Routes.yaml and provides a JavaScript implementation for fetching search results.
```yaml
-
name: 'flowpack/searchplugin - AjaxSearchController->search'
uriPattern: 'flowpack/ajaxsearch'
defaults:
'@package': 'Flowpack.SearchPlugin'
'@controller': 'AjaxSearch'
'@action': 'search'
'@format': 'html'
appendExceedingArguments: true
httpMethods: ['GET']
```
```javascript
const searchInput = document.querySelector('input[name="search"]');
const resultsContainer = document.querySelector('.search-results');
searchInput.addEventListener('input', async (e) => {
const query = e.target.value;
if (query.length < 2) return;
const response = await fetch(
`/flowpack/ajaxsearch?node=${nodeIdentifier}&q=${encodeURIComponent(query)}`
);
const html = await response.text();
resultsContainer.innerHTML = html;
});
```
--------------------------------
### Build Context Identifier with SuggestionIndexHelper
Source: https://context7.com/flowpack/flowpack.searchplugin/llms.txt
Generate a context identifier for a node using SuggestionIndexHelper, which is typically used to scope search suggestions.
```php
use Flowpack\SearchPlugin\EelHelper\SuggestionIndexHelper;
$helper = new SuggestionIndexHelper();
// Build context identifier for a node
$context = $helper->buildContext($node);
// Result: "siteName_workspace_visible" (e.g., "mysite_live_visible")
```
--------------------------------
### Configure Custom Index Name
Source: https://github.com/flowpack/flowpack.searchplugin/blob/main/README.md
Define a custom index name in your YAML configuration to avoid conflicts.
```yaml
Neos:
ContentRepository:
Search:
elasticSearch:
indexName: acmecom
```
--------------------------------
### Customize Result Rendering
Source: https://github.com/flowpack/flowpack.searchplugin/blob/main/README.md
Override the default rendering for specific node types by defining a custom Fusion prototype.
```fusion
prototype(Acme.AcmeCom:ProductSearchResult) < prototype(Neos.Neos:DocumentSearchResult) {
templatePath = 'resource://Acme.AcmeCom/Private/Templates/SearchResult/ProductSearchResult.html'
}
```
--------------------------------
### Configure ElasticSearch Analyzer
Source: https://github.com/flowpack/flowpack.searchplugin/blob/main/README.md
Define custom analysis settings for autocomplete functionality in your ElasticSearch configuration.
```yaml
Flowpack:
ElasticSearch:
indexes:
default: # client name used to connect (see Flowpack.ElasticSearch.clients)
acmecom: # your (custom) index name
settings:
analysis:
filter:
autocompleteFilter:
max_shingle_size: 5
min_shingle_size: 2
type: 'shingle'
analyzer:
autocomplete:
filter: [ 'lowercase', 'autocompleteFilter' ]
char_filter: [ 'html_strip' ]
type: 'custom'
tokenizer: 'standard'
```
--------------------------------
### Fusion Usage for Search Result Highlighting
Source: https://context7.com/flowpack/flowpack.searchplugin/llms.txt
Integrate the SearchArrayHelper's flatten functionality within Fusion templates to process Elasticsearch highlight results for display.
```fusion
prototype(Neos.Neos:DocumentSearchResult) < prototype(Neos.Fusion:Template) {
templatePath = 'resource://Flowpack.SearchPlugin/Private/Fusion/Component/DocumentSearchResult/DocumentSearchResult.html'
node = ${node}
// Flatten Elasticsearch highlight results into a simple array
highlight = ${Flowpack.SearchPlugin.Array.flatten(searchHit.highlight)}
title = ${q(node).property('title')}
description = ''
parents = ${Array.reverse(q(node).parents('[instanceof Neos.Neos:Document]').get())}
}
```
--------------------------------
### Search Term Sanitization (Eel Helper)
Source: https://context7.com/flowpack/flowpack.searchplugin/llms.txt
Details on the Eel helper for sanitizing search terms to prevent query issues and security vulnerabilities.
```APIDOC
## Eel Helper: Flowpack.SearchPlugin.SearchTerm.sanitize
### Description
This Eel helper function sanitizes search terms by removing Lucene/Elasticsearch reserved characters, ensuring query safety and validity.
### Usage
```php
use Flowpack\SearchPlugin\Utility\SearchTerm;
$sanitized = SearchTerm::sanitize('user input "with" special* chars?');
// Result: "user input with special chars"
```
### Fusion Template Usage
```fusion
prototype(Flowpack.SearchPlugin:Search) {
searchTerm = ${Flowpack.SearchPlugin.SearchTerm.sanitize(request.arguments.search)}
// Sanitized term used in query
searchQuery = ${this.searchTerm ? Search.query(site).fulltext(this.searchTerm) : null}
}
```
### Configuration
Register the Eel helper in `Settings.Neos.yaml`:
```yaml
Neos:
Fusion:
defaultContext:
Flowpack.SearchPlugin.SearchTerm: Flowpack\SearchPlugin\EelHelper\SearchTermHelper
```
```
--------------------------------
### Flatten Nested Arrays with SearchArrayHelper
Source: https://context7.com/flowpack/flowpack.searchplugin/llms.txt
Use SearchArrayHelper to recursively flatten nested arrays, useful for Elasticsearch highlight results. Import the helper class before instantiation.
```php
use Flowpack\SearchPlugin\EelHelper\SearchArrayHelper;
$helper = new SearchArrayHelper();
$nested = [
'title' => ['highlighted term'],
'body' => ['another match', 'and more']
];
$flattened = $helper->flatten($nested);
// Result: ['highlighted term', 'another match', 'and more']
```
--------------------------------
### AJAX Search API
Source: https://context7.com/flowpack/flowpack.searchplugin/llms.txt
Provides a REST endpoint for performing search queries via AJAX requests, returning HTML-rendered search results.
```APIDOC
## GET /flowpack/ajaxsearch
### Description
This endpoint performs a search query and returns HTML-rendered search results suitable for AJAX interfaces.
### Method
GET
### Endpoint
/flowpack/ajaxsearch
### Query Parameters
- **node** (string) - Required - The identifier of the node to search within.
- **q** (string) - Required - The search term.
### Request Example
```
GET /flowpack/ajaxsearch?node=some-node-identifier&q=search+term
```
### Response
#### Success Response (200)
- **HTML Fragment** - The HTML content of the search results.
#### Response Example
```html
```
```
--------------------------------
### Configure Custom Elasticsearch Index Name
Source: https://context7.com/flowpack/flowpack.searchplugin/llms.txt
Specify a custom index name for Elasticsearch integration within the Neos Content Repository search settings.
```yaml
Neos:
ContentRepository:
Search:
elasticSearch:
indexName: yourindexname
```
--------------------------------
### Sanitize Search Term with EEL Helper
Source: https://github.com/flowpack/flowpack.searchplugin/blob/main/README.md
Apply this EEL helper to sanitize search terms by removing characters reserved in Elasticsearch. This prevents errors but may disable wildcard and phrase search functionality for users.
```eel
prototype(Flowpack.SearchPlugin:Search) {
searchTerm = ${Flowpack.SearchPlugin.SearchTerm.sanitize(request.arguments.search)}
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.