1

我有一个“文档”的 MySQL 数据库,它被 ElasticSearch 与 Symfony2 的 FOSElasticaBundle 和控制台命令索引:

php app/console fos:elastica:populate

我不希望将列“在线”为 false 的文档编入索引。

我该怎么做才能配置这种需求?

4

2 回答 2

2

可以在索引过程中添加回调以检查对象是否必须被索引。

只需indexable_callback像这样在配置中添加:

types: document: indexable_callback: 'isIndexable'

在这种情况下,您必须isIndexable在关联对象中编写一个方法,例如:

public function isIndexable() { return $this->getOnline() && $this->getPublished(); }

于 2015-02-26T11:38:54.647 回答
1

您必须创建一个自定义文档加载器,您将在其中检查在线是否为真,如果是,则返回一个新的文档实例。

FosElasticaBundle 为每个文档提供者提供了一个名为 ProviderInterface 的接口,您可以创建一个实现该接口的服务,将其标记为“fos_elastica.provider”。

有点像这样:

<service id="service.id" class="Some\Bundle\Some\Class">
    <tag name="fos_elastica.provider" index="<index>" type="<type>" />
    <argument type="service" id="fos_elastica.index.<index>.<type>" />
    <argument type="service" id="logger" />
    <argument type="service" id="op.search.loader.product" />
    <argument>150</argument>
</service>

该服务将负责填充特定的索引类型。该服务将实现填充方法,您可以在其中编写自己的逻辑来填充该类型。

于 2015-02-25T21:31:01.870 回答