1. Go to this page and download the library: Download wieni/wmsearch 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/ */
wieni / wmsearch example snippets
class Article extends Node implements WmModelInterface, ElasticEntityInterface
{
use EntityPageTrait;
public function getElasticTypes()
{
return ['page'];
}
public function getElasticDocumentCollection($type)
{
return 'mymodule.elastic.article.collection';
}
}
namespace Drupal\mymodule\Service\Elastic\Collection;
use Drupal\wmsearch\Entity\Document\EntityDocumentCollection;
use Drupal\wmsearch\Exception\NotIndexableException;
class ArticleCollection extends EntityDocumentCollection
{
/** @var \Drupal\mymodule\Entity\Node\Article */
protected $entity;
public function toElasticArray($elasticId)
{
if (!$this->entity->isPublished()) {
throw new NotIndexableException();
}
return [
'id' => $this->entity->id(), // this isn't the elasticId
'title' => $this->entity->getTitle(),
'url' => $this->entity->toUrl()->toString(),
'language' => $this->entity->language()->getId(),
// ...
];
}
}