【问题标题】:FOSElasticaBundle: How to not index offline document?FOSElasticaBundle:如何不索引离线文档?
【发布时间】:2015-02-25 17:26:03
【问题描述】:

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

php app/console fos:elastica:populate

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

我需要做什么来配置这个需求?

【问题讨论】:

    标签: symfony elasticsearch foselasticabundle


    【解决方案1】:

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

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

    types: document: indexable_callback: 'isIndexable'

    这样的话,你必须在关联对象中写一个isIndexable方法,例如:

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

    【讨论】:

      【解决方案2】:

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

      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>
      

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

      【讨论】:

      • 我认为它比问题/用例更适合复杂的需求,而且我找到了最简单的解决方案。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-18
      • 2018-11-10
      • 1970-01-01
      • 2012-06-10
      • 2018-12-19
      相关资源
      最近更新 更多