SlideShare a Scribd company logo
Magento IndexersIvan ChepurnyiMagento Trainer / Lead Developer
AgendaMagento Developers MeetupOverview of Indexes FunctionalityCreation of own indexes
Let Imagine…Magento Developers Meetup… that Magento doesn’t have indexes:The prices in product list are calculated on the fly depending on catalog rules, tier prices for customer groupsStock availability for configurable and bundle products can be calculated only after loading the product collectionLayered navigation data is build in real-time for product attributes informationAnchor categories recursively collects subcategories for filtering product list
It’s all about performance…Magento Developers MeetupThe main goal is minimizing amount of operations to display products to a customer
DefinitionsMagento Developers MeetupIndexed DataAggregated data for entity representation on the frontend lists.Indexer	Generates index data on event or manual by process.Index EventThe moment when entity or related to it information is changed and that affects its index data.Index ProcessWrapper for indexer and contains information about its mode and statusMain Controller	Forwards events to Index Process
Index WorkflowMagento Developers MeetupEventMain ControllerEventEventsProcessManualInvokeIndexerIndexed Data
Event TypesMagento Developers MeetupSave	When indexed entity or related to it information was changedDeleteWhen indexed entity or related to it one was deletedMass UpdateWhen batch of entities was updated. (Update Attributes on Product Grid)
Observed Entities Magento Developers MeetupIndexed EntitiesProductProduct InventoryCategoryTagEntities ScopeCustomer GroupWebsiteStore GroupStore View
Index ProcessMagento Developers MeetupAvailable StatusesPending	Indicates that indexer is up to dateRunning	Index currently in process of full rebuilding index data.Require ReindexStatus for notifying admin user, that index is not up to date and should be rebuild.
Index ProcessMagento Developers MeetupIndexing ModesReal-timeManualUpdate Index DataEventEventRequire Reindex
Indexer Flow Magento Developers MeetupMatch EventMain ControllerIndex ProcessRegister Event DataReindex Data
Mage_Index ModuleMagento Developers MeetupMain ControllerMage_Index_Model_IndexerProcessMage_Index_Model_ProcessIndexer BaseMage_Index_Model_Indexer_Abstract
Index ModuleIndexers ModularityMagento Developers MeetupMage_Index_Model_Indexer_AbstractCatalog ModuleMage_Catalog_Model_Product_Indexer_EavMage_Catalog_Model_Product_Indexer_FlatMage_Catalog_Model_Product_Indexer_PriceInventory ModuleMage_CatalogIndex_Model_Indexer_Stock…
ModelMage_Index_Model_Indexer_AbstractIndexer StructureMagento Developers MeetupResource ModelMage_Index_Model_Mysql4_AbstractMatches event data and runs appropriate method in resource model for re-indexingWorks directly with database for generation of the indexed data. Usually all the data operated via MySQL queries.
What can you use?Magento Developers MeetupMage_Index_Model_IndexergetProcessByCode($indexerCode)getProcessCollection()processEntityAction($entity, $entityType, $eventType)Mage_Index_Model_ProcessreindexAll()reindexEverything()setMode($mode)
What you shouldn’t do…Magento Developers MeetupInvoke reindexAll method from index model/resource model, because it is better to let admin user know when the index was rebuild.Process entity events directly with indexer, instead of passing data through the main controller. You never know which index may depend on this event.
Creating own indexerMagento Developers MeetupDefining indexer in configurationDesigning index data tableImplementing model Implementing resource modelApplying index on the frontend
Featured ProductsMagento Developers MeetupThere is easier way to create featured products functionality, but it is a simple example on what should be done for creation own indexer.
Defining index in configurationMagento Developers Meetup<config><!-- …. module configurtaions -->   <global>   <!-- …. module configurtaions -->        <index><indexer>                <featured_products>                    <model>your_module/indexer_featured</model>                 </featured_products>            </indexer>        </index>    </global></config>etc/config.xmlIndexer Code Indexer Model
Designing index data tableMagento Developers MeetupAdding new attribute to catalog product entity called is_featuredCreating table that will contain product ids of products that are marked as featured products.
Designing index data tableMagento Developers Meetup$this->addAttribute('catalog_product', 'is_featured', array(    'type' => 'int',    'label' => 'Is featured',    'input' => 'select',    'source' => 'eav/entity_attribute_source_boolean',    'user_defined' => false,    'required' => false));Setup ScriptAttribute Code Yes/No Dropdown
Designing index data tableMagento Developers Meetup$table = new Varien_Db_Ddl_Table();$table->setName($this->getTable(‘module/featured'));$table->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 11, array(    'unsigned' => true,    'nullable' => false,    'primary' => true));$this->getConnection()->createTable($table);Setup ScriptTable AliasTable Column
Designing index data tableMagento Developers Meetup$table = new Varien_Db_Ddl_Table();$table->setName($this->getTable(‘module/featured'));$table->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 11, array(    'unsigned' => true,    'nullable' => false,    'primary' => true));$this->getConnection()->createTable($table);Setup ScriptTable AliasTable Column
Implementing ModelMagento Developers Meetupclass Your_Module_Model_Indexer_Featuredextends Mage_Index_Model_Indexer_Abstract{   protected $_matchedEntities = array(Mage_Catalog_Model_Product::ENTITY => array(Mage_Index_Model_Event::TYPE_SAVE, Mage_Index_Model_Event::TYPE_MASS_ACTION        ));}Defining Matching EventsEntity TypeEvent TypeEvent Types
Implementing ModelMagento Developers Meetupclass Your_Module_Model_Indexer_Featuredextends Mage_Index_Model_Indexer_Abstract{// … other codeprotected function _construct()    {        $this->_init(‘your_module/indexer_featured');    }}Defining Indexer Resource ModelResource model
Implementing ModelMagento Developers Meetupclass Your_Module_Model_Indexer_Featuredextends Mage_Index_Model_Indexer_Abstract{  // … other codepublic function getName()    {        return Mage::helper(‘your_module')->__('Featured Product');    }    public function getDescription()    {        return Mage::helper(‘‘your_module')->__('Indexes something');}}Defining Indexer InformationIndexer Name in the adminIndexer Description in the admin
Implementing ModelMagento Developers Meetupclass Your_Module_Model_Indexer_Featuredextends Mage_Index_Model_Indexer_Abstract{  // … other codeprotected function _registerEvent(Mage_Index_Model_Event $event)    {        /* @var $entity Mage_Catalog_Model_Product */        $entity = $event->getDataObject();        if ($entity->dataHasChangedFor('is_featured')) {            $event->setData('product_id', $entity->getId());        } elseif ($entity->getAttributesData()) {            $attributeData = $entity->getAttributesData();            if (isset($attributeData['is_featured'])) {                $event->setData('product_ids', $entity->getProductIds());            }}}}Register Event for ProcessingProduct Save RegisteringMass Action Registering
Implementing ModelMagento Developers Meetupclass Your_Module_Model_Indexer_Featuredextends Mage_Index_Model_Indexer_Abstract{  // … other code    protected function _processEvent(Mage_Index_Model_Event $event)    {        if ($event->getData('product_id') || $event->getData('product_ids')) {            $this->callEventHandler($event);        }}}Processing EventCalling processor in resource modelEntity TypeEvent TypecatalogProductSave($event)catalogProductMassAction($event)
Implementing Resource ModelMagento Developers Meetupclass Your_Module_Model_Mysql4_Indexer_Featured extends Mage_Index_Model_Mysql4_Abstract{   protected function _construct()    {        $this->_setResource(‘your_module');   }}Define resource connectionYour module resource prefix
Implementing Resource ModelMagento Developers Meetupclass Your_Module_Model_Mysql4_Indexer_Featured extends Mage_Index_Model_Mysql4_Abstract{    // … other code    protected function _reindexEntity($productId = null)    {        $select = $this->_getReadAdapter()->select();        /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */        $attribute = Mage::getSingleton('eav/config')                                   ->getAttribute('catalog_product', 'is_featured');        $select->from($attribute->getBackendTable(), 'entity_id')            ->where('value = ?', 1)            ->where('attribute_id = ?', $attribute->getId());Indexing MethodRetrieving only featured product ids
Implementing Resource ModelMagento Developers Meetupif ($productId !== null) {            if (!is_array($productId)) {                $productId = array($productId);            }            $select->where('entity_id IN(?)', $productId);            $this->_getWriteAdapter()->delete(                $this->getTable(‘your_module/featured'),                array(                    'product_id IN(?)' => $productId                )            );        } else {            $this->_getWriteAdapter()->truncate($this->getTable(‘your_module/featured'));        }Indexing MethodIf it is partial re-index, then delete only related indexed dataOtherwise clear all indexed data
Implementing Resource ModelMagento Developers Meetup$sqlStatement = $select->insertIgnoreFromSelect(            $this->getTable(‘your_module/featured'),            array('product_id')        );        $this->_getWriteAdapter()->query($sqlStatement);    }}Fulfill index data from select we created beforeIndexing Method
Implementing Resource ModelMagento Developers Meetupclass Your_Module_Model_Mysql4_Indexer_Featured extends Mage_Index_Model_Mysql4_Abstract{    // … other code    public function reindexAll()    {        $this->_reindexEntity();    }}Handling EventsFull index re-build
Implementing Resource ModelMagento Developers Meetupclass Your_Module_Model_Mysql4_Indexer_Featured extends Mage_Index_Model_Mysql4_Abstract{    // … other codepublic function catalogProductSave($event)    {        $this->_reindexEntity($event->getData('product_id'));    }public function catalogProductMassAction($event)    {        $this->_reindexEntity($event->getData('product_ids'));    }}Reindexing EventsSingle Save Product EventMass Save Product Event
Applying Index for the frontendMagento Developers MeetupObserving and event catalog_product_collection_apply_limitations_afterJoining index table to product collection selectCreate sub-select filter for collection
Liked it?Magento Developers MeetupCheckout our advanced training programs:http://www.ecomdev.org/magento-development-training-programs/advancedFollow our blog posts:http://www.ecomdev.org/blog
Questions?
Ad

More Related Content

What's hot (20)

Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
Rami Sayar
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
Nitin Tyagi
 
Spring GraphQL
Spring GraphQLSpring GraphQL
Spring GraphQL
VMware Tanzu
 
Spring Boot on Amazon Web Services with Spring Cloud AWS
Spring Boot on Amazon Web Services with Spring Cloud AWSSpring Boot on Amazon Web Services with Spring Cloud AWS
Spring Boot on Amazon Web Services with Spring Cloud AWS
VMware Tanzu
 
Angular Advanced Routing
Angular Advanced RoutingAngular Advanced Routing
Angular Advanced Routing
Laurent Duveau
 
Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)
Rafael Wilber Kerr
 
Magento2.3 API Functional Testing
Magento2.3 API Functional TestingMagento2.3 API Functional Testing
Magento2.3 API Functional Testing
Vishwas Bhatnagar
 
Next.js vs React | what to choose for frontend development_
Next.js vs React | what to choose for frontend development_Next.js vs React | what to choose for frontend development_
Next.js vs React | what to choose for frontend development_
ForceBolt
 
GraphQL in Magento 2
GraphQL in Magento 2GraphQL in Magento 2
GraphQL in Magento 2
Sergii Ivashchenko
 
React workshop
React workshopReact workshop
React workshop
Imran Sayed
 
Vue.js for beginners
Vue.js for beginnersVue.js for beginners
Vue.js for beginners
Julio Bitencourt
 
Webpack Introduction
Webpack IntroductionWebpack Introduction
Webpack Introduction
Anjali Chawla
 
Introduction to GraphQL Presentation.pptx
Introduction to GraphQL Presentation.pptxIntroduction to GraphQL Presentation.pptx
Introduction to GraphQL Presentation.pptx
Knoldus Inc.
 
Magento 2 Database Tables, Schema, Main tables for main features of Magento 2...
Magento 2 Database Tables, Schema, Main tables for main features of Magento 2...Magento 2 Database Tables, Schema, Main tables for main features of Magento 2...
Magento 2 Database Tables, Schema, Main tables for main features of Magento 2...
gideonvbabu
 
Spring Security 5
Spring Security 5Spring Security 5
Spring Security 5
Jesus Perez Franco
 
Token Authentication in ASP.NET Core
Token Authentication in ASP.NET CoreToken Authentication in ASP.NET Core
Token Authentication in ASP.NET Core
Stormpath
 
Spring Boot
Spring BootSpring Boot
Spring Boot
Jiayun Zhou
 
To SDK or not to SDK?
To SDK or not to SDK?To SDK or not to SDK?
To SDK or not to SDK?
Lukas Leander Rosenstock
 
ReactJs
ReactJsReactJs
ReactJs
Sahana Banerjee
 
Getting started with Next.js
Getting started with Next.jsGetting started with Next.js
Getting started with Next.js
Gökhan Sarı
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
Rami Sayar
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
Nitin Tyagi
 
Spring Boot on Amazon Web Services with Spring Cloud AWS
Spring Boot on Amazon Web Services with Spring Cloud AWSSpring Boot on Amazon Web Services with Spring Cloud AWS
Spring Boot on Amazon Web Services with Spring Cloud AWS
VMware Tanzu
 
Angular Advanced Routing
Angular Advanced RoutingAngular Advanced Routing
Angular Advanced Routing
Laurent Duveau
 
Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)
Rafael Wilber Kerr
 
Magento2.3 API Functional Testing
Magento2.3 API Functional TestingMagento2.3 API Functional Testing
Magento2.3 API Functional Testing
Vishwas Bhatnagar
 
Next.js vs React | what to choose for frontend development_
Next.js vs React | what to choose for frontend development_Next.js vs React | what to choose for frontend development_
Next.js vs React | what to choose for frontend development_
ForceBolt
 
Webpack Introduction
Webpack IntroductionWebpack Introduction
Webpack Introduction
Anjali Chawla
 
Introduction to GraphQL Presentation.pptx
Introduction to GraphQL Presentation.pptxIntroduction to GraphQL Presentation.pptx
Introduction to GraphQL Presentation.pptx
Knoldus Inc.
 
Magento 2 Database Tables, Schema, Main tables for main features of Magento 2...
Magento 2 Database Tables, Schema, Main tables for main features of Magento 2...Magento 2 Database Tables, Schema, Main tables for main features of Magento 2...
Magento 2 Database Tables, Schema, Main tables for main features of Magento 2...
gideonvbabu
 
Token Authentication in ASP.NET Core
Token Authentication in ASP.NET CoreToken Authentication in ASP.NET Core
Token Authentication in ASP.NET Core
Stormpath
 
Getting started with Next.js
Getting started with Next.jsGetting started with Next.js
Getting started with Next.js
Gökhan Sarı
 

Viewers also liked (7)

Mage Titans USA 2016 M2 deployment
Mage Titans USA 2016  M2 deploymentMage Titans USA 2016  M2 deployment
Mage Titans USA 2016 M2 deployment
Olga Kopylova
 
Magento 2.0: Prepare yourself for a new way of module development
Magento 2.0: Prepare yourself for a new way of module developmentMagento 2.0: Prepare yourself for a new way of module development
Magento 2.0: Prepare yourself for a new way of module development
Ivan Chepurnyi
 
Varnish Cache and its usage in the real world!
Varnish Cache and its usage in the real world!Varnish Cache and its usage in the real world!
Varnish Cache and its usage in the real world!
Ivan Chepurnyi
 
Using of TDD practices for Magento
Using of TDD practices for MagentoUsing of TDD practices for Magento
Using of TDD practices for Magento
Ivan Chepurnyi
 
Hidden Secrets of Magento Price Rules
Hidden Secrets of Magento Price RulesHidden Secrets of Magento Price Rules
Hidden Secrets of Magento Price Rules
Ivan Chepurnyi
 
Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)
Ivan Chepurnyi
 
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for PerformanceMeet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Ivan Chepurnyi
 
Mage Titans USA 2016 M2 deployment
Mage Titans USA 2016  M2 deploymentMage Titans USA 2016  M2 deployment
Mage Titans USA 2016 M2 deployment
Olga Kopylova
 
Magento 2.0: Prepare yourself for a new way of module development
Magento 2.0: Prepare yourself for a new way of module developmentMagento 2.0: Prepare yourself for a new way of module development
Magento 2.0: Prepare yourself for a new way of module development
Ivan Chepurnyi
 
Varnish Cache and its usage in the real world!
Varnish Cache and its usage in the real world!Varnish Cache and its usage in the real world!
Varnish Cache and its usage in the real world!
Ivan Chepurnyi
 
Using of TDD practices for Magento
Using of TDD practices for MagentoUsing of TDD practices for Magento
Using of TDD practices for Magento
Ivan Chepurnyi
 
Hidden Secrets of Magento Price Rules
Hidden Secrets of Magento Price RulesHidden Secrets of Magento Price Rules
Hidden Secrets of Magento Price Rules
Ivan Chepurnyi
 
Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)
Ivan Chepurnyi
 
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for PerformanceMeet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Ivan Chepurnyi
 
Ad

Similar to Magento Indexes (20)

Magento Performance Toolkit
Magento Performance ToolkitMagento Performance Toolkit
Magento Performance Toolkit
Sergii Shymko
 
Utilization of zend an ultimate alternate for intense data processing
Utilization of zend  an ultimate alternate for intense data processingUtilization of zend  an ultimate alternate for intense data processing
Utilization of zend an ultimate alternate for intense data processing
Career at Elsner
 
Framework
FrameworkFramework
Framework
Nguyen Linh
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
funkatron
 
WooCommerce CRUD and Data Store by Akeda Bagus
WooCommerce CRUD and Data Store by Akeda BagusWooCommerce CRUD and Data Store by Akeda Bagus
WooCommerce CRUD and Data Store by Akeda Bagus
WordCamp Indonesia
 
Extend sdk
Extend sdkExtend sdk
Extend sdk
Harsha Nagaraj
 
How to Create Module to Track Affiliate Conversions?
How to Create Module to Track Affiliate Conversions?How to Create Module to Track Affiliate Conversions?
How to Create Module to Track Affiliate Conversions?
damienwoods
 
Intro Open Social and Dashboards
Intro Open Social and DashboardsIntro Open Social and Dashboards
Intro Open Social and Dashboards
Atlassian
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVC
Richard Paul
 
Effective Android Data Binding
Effective Android Data BindingEffective Android Data Binding
Effective Android Data Binding
Eric Maxwell
 
Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)
Pavel Novitsky
 
Hacking Movable Type
Hacking Movable TypeHacking Movable Type
Hacking Movable Type
Stefano Rodighiero
 
Zend framework 04 - forms
Zend framework 04 - formsZend framework 04 - forms
Zend framework 04 - forms
Tricode (part of Dept)
 
70562 (1)
70562 (1)70562 (1)
70562 (1)
Pragya Rastogi
 
Relevance trilogy may dream be with you! (dec17)
Relevance trilogy  may dream be with you! (dec17)Relevance trilogy  may dream be with you! (dec17)
Relevance trilogy may dream be with you! (dec17)
Woonsan Ko
 
Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php framework
Bo-Yi Wu
 
Ruby on rails
Ruby on rails Ruby on rails
Ruby on rails
Mohit Jain
 
Abstracting functionality with centralised content
Abstracting functionality with centralised contentAbstracting functionality with centralised content
Abstracting functionality with centralised content
Michael Peacock
 
07 Php Mysql Update Delete
07 Php Mysql Update Delete07 Php Mysql Update Delete
07 Php Mysql Update Delete
Geshan Manandhar
 
Growing up with Magento
Growing up with MagentoGrowing up with Magento
Growing up with Magento
Kristof Ringleff
 
Magento Performance Toolkit
Magento Performance ToolkitMagento Performance Toolkit
Magento Performance Toolkit
Sergii Shymko
 
Utilization of zend an ultimate alternate for intense data processing
Utilization of zend  an ultimate alternate for intense data processingUtilization of zend  an ultimate alternate for intense data processing
Utilization of zend an ultimate alternate for intense data processing
Career at Elsner
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
funkatron
 
WooCommerce CRUD and Data Store by Akeda Bagus
WooCommerce CRUD and Data Store by Akeda BagusWooCommerce CRUD and Data Store by Akeda Bagus
WooCommerce CRUD and Data Store by Akeda Bagus
WordCamp Indonesia
 
How to Create Module to Track Affiliate Conversions?
How to Create Module to Track Affiliate Conversions?How to Create Module to Track Affiliate Conversions?
How to Create Module to Track Affiliate Conversions?
damienwoods
 
Intro Open Social and Dashboards
Intro Open Social and DashboardsIntro Open Social and Dashboards
Intro Open Social and Dashboards
Atlassian
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVC
Richard Paul
 
Effective Android Data Binding
Effective Android Data BindingEffective Android Data Binding
Effective Android Data Binding
Eric Maxwell
 
Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)
Pavel Novitsky
 
Relevance trilogy may dream be with you! (dec17)
Relevance trilogy  may dream be with you! (dec17)Relevance trilogy  may dream be with you! (dec17)
Relevance trilogy may dream be with you! (dec17)
Woonsan Ko
 
Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php framework
Bo-Yi Wu
 
Ruby on rails
Ruby on rails Ruby on rails
Ruby on rails
Mohit Jain
 
Abstracting functionality with centralised content
Abstracting functionality with centralised contentAbstracting functionality with centralised content
Abstracting functionality with centralised content
Michael Peacock
 
07 Php Mysql Update Delete
07 Php Mysql Update Delete07 Php Mysql Update Delete
07 Php Mysql Update Delete
Geshan Manandhar
 
Ad

Recently uploaded (20)

Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 

Magento Indexes

  • 1. Magento IndexersIvan ChepurnyiMagento Trainer / Lead Developer
  • 2. AgendaMagento Developers MeetupOverview of Indexes FunctionalityCreation of own indexes
  • 3. Let Imagine…Magento Developers Meetup… that Magento doesn’t have indexes:The prices in product list are calculated on the fly depending on catalog rules, tier prices for customer groupsStock availability for configurable and bundle products can be calculated only after loading the product collectionLayered navigation data is build in real-time for product attributes informationAnchor categories recursively collects subcategories for filtering product list
  • 4. It’s all about performance…Magento Developers MeetupThe main goal is minimizing amount of operations to display products to a customer
  • 5. DefinitionsMagento Developers MeetupIndexed DataAggregated data for entity representation on the frontend lists.Indexer Generates index data on event or manual by process.Index EventThe moment when entity or related to it information is changed and that affects its index data.Index ProcessWrapper for indexer and contains information about its mode and statusMain Controller Forwards events to Index Process
  • 6. Index WorkflowMagento Developers MeetupEventMain ControllerEventEventsProcessManualInvokeIndexerIndexed Data
  • 7. Event TypesMagento Developers MeetupSave When indexed entity or related to it information was changedDeleteWhen indexed entity or related to it one was deletedMass UpdateWhen batch of entities was updated. (Update Attributes on Product Grid)
  • 8. Observed Entities Magento Developers MeetupIndexed EntitiesProductProduct InventoryCategoryTagEntities ScopeCustomer GroupWebsiteStore GroupStore View
  • 9. Index ProcessMagento Developers MeetupAvailable StatusesPending Indicates that indexer is up to dateRunning Index currently in process of full rebuilding index data.Require ReindexStatus for notifying admin user, that index is not up to date and should be rebuild.
  • 10. Index ProcessMagento Developers MeetupIndexing ModesReal-timeManualUpdate Index DataEventEventRequire Reindex
  • 11. Indexer Flow Magento Developers MeetupMatch EventMain ControllerIndex ProcessRegister Event DataReindex Data
  • 12. Mage_Index ModuleMagento Developers MeetupMain ControllerMage_Index_Model_IndexerProcessMage_Index_Model_ProcessIndexer BaseMage_Index_Model_Indexer_Abstract
  • 13. Index ModuleIndexers ModularityMagento Developers MeetupMage_Index_Model_Indexer_AbstractCatalog ModuleMage_Catalog_Model_Product_Indexer_EavMage_Catalog_Model_Product_Indexer_FlatMage_Catalog_Model_Product_Indexer_PriceInventory ModuleMage_CatalogIndex_Model_Indexer_Stock…
  • 14. ModelMage_Index_Model_Indexer_AbstractIndexer StructureMagento Developers MeetupResource ModelMage_Index_Model_Mysql4_AbstractMatches event data and runs appropriate method in resource model for re-indexingWorks directly with database for generation of the indexed data. Usually all the data operated via MySQL queries.
  • 15. What can you use?Magento Developers MeetupMage_Index_Model_IndexergetProcessByCode($indexerCode)getProcessCollection()processEntityAction($entity, $entityType, $eventType)Mage_Index_Model_ProcessreindexAll()reindexEverything()setMode($mode)
  • 16. What you shouldn’t do…Magento Developers MeetupInvoke reindexAll method from index model/resource model, because it is better to let admin user know when the index was rebuild.Process entity events directly with indexer, instead of passing data through the main controller. You never know which index may depend on this event.
  • 17. Creating own indexerMagento Developers MeetupDefining indexer in configurationDesigning index data tableImplementing model Implementing resource modelApplying index on the frontend
  • 18. Featured ProductsMagento Developers MeetupThere is easier way to create featured products functionality, but it is a simple example on what should be done for creation own indexer.
  • 19. Defining index in configurationMagento Developers Meetup<config><!-- …. module configurtaions --> <global> <!-- …. module configurtaions --> <index><indexer> <featured_products> <model>your_module/indexer_featured</model> </featured_products> </indexer> </index> </global></config>etc/config.xmlIndexer Code Indexer Model
  • 20. Designing index data tableMagento Developers MeetupAdding new attribute to catalog product entity called is_featuredCreating table that will contain product ids of products that are marked as featured products.
  • 21. Designing index data tableMagento Developers Meetup$this->addAttribute('catalog_product', 'is_featured', array( 'type' => 'int', 'label' => 'Is featured', 'input' => 'select', 'source' => 'eav/entity_attribute_source_boolean', 'user_defined' => false, 'required' => false));Setup ScriptAttribute Code Yes/No Dropdown
  • 22. Designing index data tableMagento Developers Meetup$table = new Varien_Db_Ddl_Table();$table->setName($this->getTable(‘module/featured'));$table->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 11, array( 'unsigned' => true, 'nullable' => false, 'primary' => true));$this->getConnection()->createTable($table);Setup ScriptTable AliasTable Column
  • 23. Designing index data tableMagento Developers Meetup$table = new Varien_Db_Ddl_Table();$table->setName($this->getTable(‘module/featured'));$table->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 11, array( 'unsigned' => true, 'nullable' => false, 'primary' => true));$this->getConnection()->createTable($table);Setup ScriptTable AliasTable Column
  • 24. Implementing ModelMagento Developers Meetupclass Your_Module_Model_Indexer_Featuredextends Mage_Index_Model_Indexer_Abstract{ protected $_matchedEntities = array(Mage_Catalog_Model_Product::ENTITY => array(Mage_Index_Model_Event::TYPE_SAVE, Mage_Index_Model_Event::TYPE_MASS_ACTION ));}Defining Matching EventsEntity TypeEvent TypeEvent Types
  • 25. Implementing ModelMagento Developers Meetupclass Your_Module_Model_Indexer_Featuredextends Mage_Index_Model_Indexer_Abstract{// … other codeprotected function _construct() { $this->_init(‘your_module/indexer_featured'); }}Defining Indexer Resource ModelResource model
  • 26. Implementing ModelMagento Developers Meetupclass Your_Module_Model_Indexer_Featuredextends Mage_Index_Model_Indexer_Abstract{ // … other codepublic function getName() { return Mage::helper(‘your_module')->__('Featured Product'); } public function getDescription() { return Mage::helper(‘‘your_module')->__('Indexes something');}}Defining Indexer InformationIndexer Name in the adminIndexer Description in the admin
  • 27. Implementing ModelMagento Developers Meetupclass Your_Module_Model_Indexer_Featuredextends Mage_Index_Model_Indexer_Abstract{ // … other codeprotected function _registerEvent(Mage_Index_Model_Event $event) { /* @var $entity Mage_Catalog_Model_Product */ $entity = $event->getDataObject(); if ($entity->dataHasChangedFor('is_featured')) { $event->setData('product_id', $entity->getId()); } elseif ($entity->getAttributesData()) { $attributeData = $entity->getAttributesData(); if (isset($attributeData['is_featured'])) { $event->setData('product_ids', $entity->getProductIds()); }}}}Register Event for ProcessingProduct Save RegisteringMass Action Registering
  • 28. Implementing ModelMagento Developers Meetupclass Your_Module_Model_Indexer_Featuredextends Mage_Index_Model_Indexer_Abstract{ // … other code protected function _processEvent(Mage_Index_Model_Event $event) { if ($event->getData('product_id') || $event->getData('product_ids')) { $this->callEventHandler($event); }}}Processing EventCalling processor in resource modelEntity TypeEvent TypecatalogProductSave($event)catalogProductMassAction($event)
  • 29. Implementing Resource ModelMagento Developers Meetupclass Your_Module_Model_Mysql4_Indexer_Featured extends Mage_Index_Model_Mysql4_Abstract{ protected function _construct() { $this->_setResource(‘your_module'); }}Define resource connectionYour module resource prefix
  • 30. Implementing Resource ModelMagento Developers Meetupclass Your_Module_Model_Mysql4_Indexer_Featured extends Mage_Index_Model_Mysql4_Abstract{ // … other code protected function _reindexEntity($productId = null) { $select = $this->_getReadAdapter()->select(); /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */ $attribute = Mage::getSingleton('eav/config') ->getAttribute('catalog_product', 'is_featured'); $select->from($attribute->getBackendTable(), 'entity_id') ->where('value = ?', 1) ->where('attribute_id = ?', $attribute->getId());Indexing MethodRetrieving only featured product ids
  • 31. Implementing Resource ModelMagento Developers Meetupif ($productId !== null) { if (!is_array($productId)) { $productId = array($productId); } $select->where('entity_id IN(?)', $productId); $this->_getWriteAdapter()->delete( $this->getTable(‘your_module/featured'), array( 'product_id IN(?)' => $productId ) ); } else { $this->_getWriteAdapter()->truncate($this->getTable(‘your_module/featured')); }Indexing MethodIf it is partial re-index, then delete only related indexed dataOtherwise clear all indexed data
  • 32. Implementing Resource ModelMagento Developers Meetup$sqlStatement = $select->insertIgnoreFromSelect( $this->getTable(‘your_module/featured'), array('product_id') ); $this->_getWriteAdapter()->query($sqlStatement); }}Fulfill index data from select we created beforeIndexing Method
  • 33. Implementing Resource ModelMagento Developers Meetupclass Your_Module_Model_Mysql4_Indexer_Featured extends Mage_Index_Model_Mysql4_Abstract{ // … other code public function reindexAll() { $this->_reindexEntity(); }}Handling EventsFull index re-build
  • 34. Implementing Resource ModelMagento Developers Meetupclass Your_Module_Model_Mysql4_Indexer_Featured extends Mage_Index_Model_Mysql4_Abstract{ // … other codepublic function catalogProductSave($event) { $this->_reindexEntity($event->getData('product_id')); }public function catalogProductMassAction($event) { $this->_reindexEntity($event->getData('product_ids')); }}Reindexing EventsSingle Save Product EventMass Save Product Event
  • 35. Applying Index for the frontendMagento Developers MeetupObserving and event catalog_product_collection_apply_limitations_afterJoining index table to product collection selectCreate sub-select filter for collection
  • 36. Liked it?Magento Developers MeetupCheckout our advanced training programs:http://www.ecomdev.org/magento-development-training-programs/advancedFollow our blog posts:http://www.ecomdev.org/blog