PHP code example of fork / craft-elastica
1. Go to this page and download the library: Download fork/craft-elastica library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fork / craft-elastica example snippets
// initialize elasticsearch indexer
Event::on(
Indexer::class,
Indexer::EVENT_INDEXER_INIT,
function (IndexerInitEvent $event) {
$event->addSectionHandles([
'articles',
]);
$event->addCategoryGroupHandles([
'topics',
]);
$event->addVolumeHandles([
'images',
]);
}
);
// build elasticsearch index data
Event::on(
Indexer::class,
Indexer::EVENT_BEFORE_INDEX_DATA,
function (IndexEvent $event) {
// build your custom data structure to index
$indexData = MyCustomPlugin::$plugin->mySearchService->getIndexData($event->sender);
$event->indexData = $indexData;
}
);