This is an implementation of the Neos NodeSearchService using the Elasticsearch index of the content repository. This vastly reduces the query time for Search-As-You-Type fields in the backend if you have lots of nodes in your project. Additionally it is highly customizable in order to get the best search experience for the project.
Multiple search strategies can be defined which are then selected according to the SearchNodeType, StartingPoint and the term. With this feature you are able to sort news documents returned in a reference selector by publish date while other documents are sorted alphabetically.
Note: While the original database search does a like search in all properties of the document, the default strategy of this package only does a prefix search in the title field. Replace it with the search strategy that fit your needs.
The following example shows a reference selector for news articles with 23 000 Documents.
The installation is done with composer:
composer require punktde/elastic-nodesearchservice
Compatibility to Flowpack.ElasticSearch.ContentRepositoryAdaptor:
Elastic.NodeSearchService | ElasticSearch.ContentRepositoryAdaptor |
---|---|
1 | 5.x, 6.x |
2 | 7.x |
This example uses a multi_match prefix query to search in the punktde_node_search
field indexed for documents.
PunktDe:
Elastic:
NodeSearchService:
logRequests: true
searchStrategies:
position: end
titlePrefix:
condition: '${Array.indexOf(searchNodeTypes, "Neos.Neos:Document")}'
request:
query:
bool:
filter:
bool:
minimum_should_match: 1
should:
- multi_match:
query: ARGUMENT_TERM
type: bool_prefix
fields: ['punktde_node_search', 'punktde_node_search._2gram', 'punktde_node_search._3gram']
must:
- terms:
neos_type_and_supertypes: ARGUMENT_SEARCHNODETYPES
- term:
neos_parent_path : ARGUMENT_STARTINGPOINT
must_not:
- term:
neos_hidden: true
_source:
- __path
size: 20
The position
determines in which order the strategy conditions are evaluated.
The condition
is an Eel query, which can be parametrized by the following values. It is used to determine the search strategy to be used.
If no search strategy could be found, it falls back to database search.
ParameterName | Description |
---|---|
string term |
The search term |
array searchNodeTypes |
Array of the search nodetypes |
Context context |
The given node context |
NodeInterface startingPoint |
The defined starting point |
These following parameters can be used in the search request to parametrice the query:
ParameterName | Description |
---|---|
ARGUMENT_SEARCHNODETYPES | Array_Values of the filter NodeTypes. |
ARGUMENT_TERM | The Searchterm |
ARGUMENT_STARTINGPOINT | The startingPoint path |
Sometimes reference editors for certain nodeTypes profit from custom search strategies. Eg. Only list document nodes that are visible and have a certain property set. We have limited options to determine a search strategy, thus we use the following trick:
- Define a marker nodeType
'Vendor:SearchStrategyMarker.ListableEventSearch':
abstract: true
- Use this marker nodeType in your referenceEditor
events:
type: references
ui:
inspector:
editorOptions:
nodeTypes: ['Vendor:Documents.Event', 'Vendor:SearchStrategyMarker.ListableEventSearch']
- Use this nodeType within the search strategy condition
...
eventSearchTitlePrefix:
condition: '${Array.indexOf(searchNodeTypes, "Vendor:SearchStrategyMarker.ListableEventSearch") != -1}'
...