How FacetWP’s Indexer Works

Indexing is the process of storing facet data into a custom database table. It allows FacetWP to retrieve data very quickly and efficiently.

How is the indexer triggered?

If facets are added, we ask that users press the Re-index button within FacetWP’s admin UI. This completely rebuilds the index table.

When you save settings in FacetWP’s admin that require a re-index of your content, the re-index button will be highlighted to remind you to run the re-index.

FacetWP automatically indexes changes when posts or taxonomy terms are updated.

The facetwp_index table

FacetWP adds one database table: facetwp_index. This table contains all the information needed to generate the facets.

How does the indexer work?

When the Re-index button is clicked, FacetWP first retrieves all post IDs that should be indexed. It uses WP_Query, and the query arguments are customizable.

FacetWP then loops through the array of post IDs. For each, it loops through all available facets and saves applicable values. Below is a pseudocode example:

foreach ( $post_ids as $post_id ) {
    foreach ( $facets as $facet ) {
        index_values( $post_id, $facet );

The values for each row can be modified using the facetwp_index_row filter.

Indexing progress

When indexing, you’ll see a progress bar. This serves two purposes: it keeps you informed, while also pinging the server to check for a stalled indexer.

While the indexer is running, the re-index button text changes to Stop indexer. This will stop any progress, but remember that the index will remain incomplete until you re-index again.

Keep the FacetWP settings page open until you see the Indexing complete message.

Built-in resuming

The indexer can stall for various reasons: the server ran out of memory, power outage, etc. The important part is that the indexer usually picks up where it left off.

When the indexer stalls, it’s usually something server-related (beyond the control of FacetWP). That’s why it’s super important to check your web server’s PHP error log for any clues.

Other index actions

Show indexable post types lists all post types that will be indexed. If a desired post type is not in the list, make sure that exclude_from_search = FALSE (re-index afterwards). Alternatively, you could use the facetwp_indexer_query_args filter to force the post type to be indexed.

Purge the index table deletes and re-creates the facetwp_index database table. This can be helpful in resolving database migration issues.

See Also