GET FREE VERSION GET THE PRO VERSION

Index Table

For the faster search speed plugin scrap all product contents and store content words inside its index table. Index process must be run only once and after this index table will be synchronized automatically.

In this article

Overview

To perform the search plugin use a special index table. This table contains normalized words of all your products from all available product fields. With the index table it is possible to increase search speed and provide more accurate search results.

After installing and activating the plugin you need to go to the plugin settings page and create an index table. This needs to be done only one time. After this all changes that you have made for your WooCommerce products will be synchronized with the index table automatically.

Index button

Index button

Index table options

If your shop has many products inside ( 100.000+ ) the index table can become quite large. In this case you can use special index table options from the Performance settings page tab.

Index table settings

Index table settings

The idea is to exclude from the index table all product fields that are not used for searching and in this case not needed inside the index table.

For example, if you are searching only inside product title, sku and id then it is possible to disable all other fields from the index table. This can heavily decrease table size and increase search speed.

After making any changes you need to re-index the table.

Code snippets for index

Sometimes automatic synchronization may break. For example, when you import products directly to WordPress table bypassing standard hooks like wp_insert_post.

For this case you have several options for how to add these products to the index table:

  • 1. Manually click re-index table button after each import.
  • 2. Re-index table from the code.
    Just call this method after importing products

    do_action( 'aws_reindex_table' );
  • 3. Create cron job and re-index table every desired interval.
    Following code will run re-index cron job every hour.

    add_action( 'wp', 'aws_set_cron' );
    function aws_set_cron() {
        if ( ! wp_next_scheduled ( 'aws_reindex_table' ) ) {
            wp_schedule_event(time(), 'hourly', 'aws_reindex_table');
        }
    }
    

    Available intervals: 'hourly', 'twicedaily', 'daily'. It is also possible to create custom intervals.

Described hook will force the plugin to reindex the full index table. If you need to re-index only certain products it is possible to use aws_reindex_product hook.

do_action( 'aws_reindex_product', {PRODUCT_ID} );

{PRODUCT_ID} - (int)(array) Product ID ( or array of products IDs ) that needs to be reindexed.

WP-CLI commands

Another way to perform index/reindex action is to use WP-CLI. Plugin has several built-in commands for such a case.

wp awssearch index --type=all

Index/reindex whole plugin table.

wp awssearch index --type=update --id=123

Index/reindex only specific products with ID 123.

Please check this article to find the whole list of available WP-CLI commands.