Novactive eZ Algolia Search Engine is an eZ Platform bundle to provide Algolia search integration, enabling you to use the Algolia Search Engine to index the data and to search.
Thanks to these 3 main features:
Content
or Location
if needed.Add the following to your composer.json and run composer update novactive/ezalgoliasearchengine
to install dependencies:
# composer.json
"require": {
"novactive/ezalgoliasearchengine": "^1.0.0"
}
cd ezplatform
yarn add --dev algoliasearch react react-collapsible react-dom react-instantsearch-dom
If Symfony Flex did not do it already, activate the bundle in config\bundles.php
file.
// config\bundles.php
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
...
Novactive\Bundle\eZAlgoliaSearchEngine\NovaEzAlgoliaSearchEngine::class => ['all' => true],
];
_novaezalgoliasearchengine_routes:
resource: '@NovaEzAlgoliaSearchEngine/Resources/config/routing.yaml'
The SEARCH_ENGINE
environment variable should be set to algolia
nova_ezalgoliasearchengine:
system:
default:
index_name_prefix: PREFIX
app_id: APPLICATION_ID
api_secret_key: ADMIN_API_KEY
api_search_only_key: SEARCH_ONLY_PAI_KEY
license_key: "CONTACT NOVACTIVE: direction.technique@novactive.com to get your trial"
webpack_encore:
builds:
nova_ezalgolia: "%kernel.project_dir%/public/assets/nova_ezalgolia/build"
framework:
assets:
packages:
nova_ezalgolia:
json_manifest_path: '%kernel.project_dir%/public/assets/nova_ezalgolia/build/manifest.json'
The Algolia Application should be created on https://www.algolia.com/ to retrieve the Application ID and the API secret keys. They can be found on the API Keys page of the Algolia dashboard.
After having installed the package the following command should be run to init the Indexes on Algolia and set up the search attributes, sort indexes and facets:
bin/console nova:ez:algolia:indexes:setup
All the Criterions created inside the eZ Queries as a filter or query field are transformed into the Algolia filter string like
doc_type_s:content AND (content_type_identifier_s:"article")
A few of the main Criterions are not implemented yet:
The User related criterions are not implemented yet because most of them are either included in the UserMetaData Criterion.
The MapLocationDistance Criterion is not implemented because the Algolia geo location filter option doesn't allow uss to manage multiple fields of this type within the same document. Filtering by location can be done using the specific request options of the Algolia Search method. Here is the example:
$query->setRequestOption('aroundLatLng', '37.7512306, -122.4584587');
$query->setRequestOption('aroundRadius', 3000);
The documentation on this subject can be found here.
The _geoloc attribute is already included in the Algolia document by default for the contents that have the Map Location fields.
Another constraints are inside the Logical operators. They are:
You can find more info on the specific boolean filters on Algolia documentation here.
The full Algolia information about how the filtering works can be found here.
Sorting with Algolia is based on top of Replicas. Each Replica is a duplicated index with specific configuration on attributes on which the documents are sorted.
The attributes that are used to generate the Replicas can be set in the attributes_for_replicas
config parameter.
When using the eZ Query the sortClauses field assigned to the Query instance is converted into the Replica key.
All the data (Content and Location items) are pushed to the Algolia Index using the bin/console ezplatform:reindex
command.
All of them (except those specified in _exclude_contenttypes parameter or only those included in _include_contenttypes parameter)
are converted to a specific format and sent to Algolia via saveObjects method.
Also each particular Content of allowed Content Type (included or not excluded) is pushed to the Index once published on Ez Platform admin dashboard.
The Search page with /search
url is overridden with custom Search controller implemented in the Bundle.
The specific routing configuration is used for that:
ezplatform.search:
path: /search
methods: ['GET']
defaults:
_controller: 'Novactive\Bundle\eZAlgoliaSearchEngine\Controller\SearchController::searchAction'
The source code of the Front End implementation with React components can be found in the search.jsx
file.
All the main widgets are included there and can be used as examples of their implementation.
The information on React InstantSearch component basic installation and widgets showcases can be also found in the docs:
To restrict the scope of an API key the Secured API keys are used. The Secured API key can be only generated from Search-only API key from the Algolia API keys list. This kind of API key is used when performing the Search method and to prevent possible malicious request tweaks to impersonate another user, so it's done on the Back End side.
In other words, based on the currernt User Permissions, this bundle queries Algolia including permission-related implicit filters to avoid data leaks.
More info here.
When performing the saveObjects method to create, update or delete the entries of the Ined the Admin API key is used.
You can select which Content Types to include or exclude from the Index. Use the following config parameters to exclude or include the specific content types:
nova_ezalgoliasearchengine.default.exclude_content_types
nova_ezalgoliasearchengine.default.include_content_types
The include
parameter is checked first and hence has the priority.
By default all the content types are saved to the Index except User and User Group.
There are also the following parameters:
You can see the default list of the attributes that are sent to Algolia in the Deafult Settings.
To send all those setting to Algolia use the bin/console nova:ez:algolia:indexes:setup
command.
If you want to create more specific custom request that can be achieved with the Search Query Factory service
Novactive\Bundle\eZAlgoliaSearchEngine\Core\Search\SearchQueryFactory
.
When using it all the request parameters should be specified manually, i.e search term, filters, facets etc. like in the following example:
$query = $this->searchQueryFactory->create(
'term',
'content_type_identifier_s:"article"',
['doc_type_s']
);
$query->setRequestOption('attributesToRetrieve', ['content_name_s']);
The Replica can be also specified manually:
$query = $this->searchQueryFactory->create(
'',
'content_language_codes_ms:"eng-GB"',
);
$query->setReplicaByAttribute('location_id_i');
Then the created Query instance should be passed to one of the methods of
Novactive\Bundle\eZAlgoliaSearchEngine\Core\Search\Search
service depending on the type of search:
There is also an event that enables you to tweak the
Query
created by the factory.Novactive\Bundle\eZAlgoliaSearchEngine\Event\QueryCreateEvent