Mugo Web main content.

Re-indexing specific pages and subtrees in eZ Publish

By: Peter Keung | October 4, 2012 | eZ Publish development tips

There a few cases when you want to trigger a re-index parts of your site; for example, you might make an existing attribute searchable or you might change some index boosting settings. However, default eZ Publish indexing tools only allow you to re-index the entire site. This is not particularly efficient if you have a very large site and/or if you're just trying to test a small change in your development environment. Here are a couple of tools that you can use to re-index specific parts of a site.

The quick way to re-index a specific page is to re-publish it, since the publishing process triggers a re-index. This is not always a suitable solution, however, because it changes the modified date on the page and triggers whatever publishing workflows you have. This also doesn't work if you want to re-index more than just a page, such as an entire subtree, or all of the objects that are of the same content class.

Using a Mugo Queue task

Mugo Queue is a framework for queuing a wide variety of eZ Publish tasks, and re-indexing is a perfect example of such a task. By default, Mugo Queue enables you to fetch a specific subtree and re-index all of its nodes. First, you configure the subtree to fetch in your PHP code, and then you add the objects to the queue and re-index them:

php extension/mugo_queue/bin/run.php -a create -k MugoSearchIndex
php extension/mugo_queue/bin/run.php -a execute -k MugoSearchIndex

Mugo Queue is publicly available -- and forkable! -- on GitHub, and you can see the code for the MugoSearchIndex task and use it as a starting point to re-index any grouping of objects.

Using the command line tool "eep"

eep is also publicly available on GitHub. The process to re-index a subtree can start with a command to list all of the nodes in a subtree and one to re-index a specific object:

eep list subtree <node_id>
eep ezfind indexobject <object id>

With eep, the more comfortable you are on the command line, the more control you can have over running eZ Publish tasks; these two simple commands are joined together into one command to actually do the re-indexing:

eep list subtree 245 | awk '$1=="|" {print $2}' | xargs -IOID eep ezfind indexobject OID

eep comes with a large set of eZ Publish operations, and is fully extensible, so you can also set it up to re-index any grouping of objects.

Note that the examples above are specific to sites that use the enterprise search extension eZ Find, but you can certainly adapt the code if you are using the native eZ Publish search engine.