punktde / elastic-nodesearchservice
Implementation of the Neos NodeSearchServiceInterface using the Elasticsearch index
Installs: 19 906
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 6
Forks: 3
Open Issues: 1
Type:neos-package
Requires
- flowpack/elasticsearch-contentrepositoryadaptor: ^7.0 || ^8.0 || dev-master
- neos/flow: *
- neos/neos: ^5.0 || ^7.0 || ^8.0
README
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.
Installation
The installation is done with composer:
composer require punktde/elastic-nodesearchservice
Compatibility to Flowpack.ElasticSearch.ContentRepositoryAdaptor:
Configuration
Example
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.
These following parameters can be used in the search request to parametrice the query:
Tip: Use a marker nodeType to determine the best search strategy
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}'
...