7

I'm trying to create a custom indexer on Magento2.

I defined a mview.xml and one indexer.xml as follows:

indexer.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Indexer/etc/indexer.xsd">
    <indexer id="my_indexer" view_id="my_indexer" class="My\Indexer\Model\Indexer\Fulltext">
        <title translate="true">My Indexer</title>
        <description translate="true">My Indexer</description>
    </indexer>
</config>

mview.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Mview/etc/mview.xsd">
    <view id="my_indexer" class="My\Module\Model\Indexer\Fulltext" group="indexer">
        <subscriptions>
            <table name="catalog_product_entity" entity_column="entity_id" />
            <table name="catalog_product_entity_int" entity_column="entity_id" />
            <table name="catalog_product_entity_decimal" entity_column="entity_id" />
            <table name="catalog_product_entity_text" entity_column="entity_id" />
            <table name="catalog_product_entity_varchar" entity_column="entity_id" />
            <table name="catalog_product_entity_datetime" entity_column="entity_id" />
            <table name="catalog_product_website" entity_column="product_id" />
            <table name="cataloginventory_stock_item" entity_column="product_id" />
            <table name="catalog_product_bundle_selection" entity_column="parent_product_id" />
            <table name="catalog_product_super_link" entity_column="product_id" />
            <table name="catalog_product_link" entity_column="product_id" />
        </subscriptions>
    </view>
</config>

I can see the new indexer in the Magento backend and I can run a reindex from the command line, but when I try to modify a product from backend it does not trigger the mview as I would expect.

It does not call the execute method in the Mview or Indexer class, but it works correctly if called from command line.

Any idea?

4

2 Answers 2

0

Answer: https://github.com/magento/magento2/issues/8866

Generally, you should put your index in "Update by Schedule" state to make it works using mview.xml configurations.
Check this diagram: https://devdocs.magento.com/guides/v2.0/extension-dev-guide/indexing.html

-4

You are missing a crontab.xml file. Specifics of each field can be found here

<config>
<group id="<group_name>">
    <job name="<job_name>" instance="<classpath>" method="<method>">
        <schedule><time></schedule>
    </job>
</group>

As an example see Customer moudule's crontab.xml

1
  • 1
    Why crontab is needed for mview? Shouldn't the execute method of mview class called for each modified row? Feb 25, 2016 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.