将Neos Fusion渲染的标记片段添加到Elasticsearch索引中,可以使用Neos的Elasticsearch包来实现。以下是一个简单的示例:
use Neos\Eel\FlowQuery\FlowQuery;
use Neos\Fusion\Core\Cache\ContentCache;
use Neos\Flow\Annotations as Flow;
/**
* @Flow\Scope("singleton")
*/
class ElasticsearchIndexer
{
/**
* @Flow\Inject
* @var Elasticsearch
*/
protected $elasticsearch;
/**
* @Flow\Inject
* @var ContentCache
*/
protected $contentCache;
/**
* @param NodeInterface $node
* @throws Exception
*/
public function index(NodeInterface $node): void
{
$contentCacheIdentifier = $node->getNodeData()->getContentCacheIdentifier();
$cachedRenderedMarkup = $this->contentCache->get($contentCacheIdentifier);
if ($cachedRenderedMarkup !== null) {
$documentId = $node->getIdentifier();
$document = [
'markup' => $cachedRenderedMarkup
];
$this->elasticsearch->index([
'index' => 'my_index',
'type' => 'my_type',
'id' => $documentId,
'body' => $document
]);
}
else {
// ...
}
}
}
此方法可以将节点渲染为标记片段,将其添加到Elasticsearch索引,并在查询时使用。
上一篇:Addnantolist