HUSKY - WooCommerce Products Filter Professional

How to Speed Up WOOF Text Filter Searches

If your site has a large number of products (3000+) and you’re experiencing slow search performance with [woof_text_filter], this guide will help you optimize it.

The Problem

By default, HUSKY uses SQL JOIN method for searches, which can become slow on large databases. Text searches taking 10+ seconds and category filtering causing delays are common symptoms.

Solution 1: Enable Fast Search Method (post__in)

The plugin has a built-in faster search method that uses post__in instead of SQL JOINs. This is much more efficient for large product catalogs.

Implementation

Add this single line to your theme’s functions.php file:

add_filter('woof_husky_query_post__in', '__return_true');

Expected Results

  • Text search speed: From 10+ seconds to 1-3 seconds
  • Works immediately after adding the code
  • No database changes required

Solution 2: Optimize Category Filtering

If category filtering is still slow after enabling fast search, you have two options:

Option A: Add Database Indexes (Recommended)

Database indexes dramatically speed up category queries by optimizing the term_relationships and term_taxonomy tables.

Add this code to your functions.php:

add_action('admin_init', 'add_woof_category_indexes', 999);

function add_woof_category_indexes() {
    global $wpdb;

    // Run only once
    if (get_option('woof_category_indexes_added')) {
        return;
    }

    // Add index to term_relationships table
    $wpdb->query("
        ALTER TABLE {$wpdb->term_relationships}
        ADD INDEX woof_cat_idx (object_id, term_taxonomy_id)
    ");

    // Add index to term_taxonomy table
    $wpdb->query("
        ALTER TABLE {$wpdb->term_taxonomy}
        ADD INDEX woof_tax_idx (taxonomy, term_id)
    ");

    // Mark as completed
    update_option('woof_category_indexes_added', true);
}

How it works:

  • Runs once on first admin page load
  • Creates optimized database indexes
  • Stores completion flag to prevent re-running

Expected Results:

  • Category filtering: From several seconds to < 1 second
  • Permanent solution (indexes remain after code removal)

Option B: Cache Category Queries

If you can’t modify database structure or want a different approach, caching provides good performance improvement.

Add this code to your functions.php:

add_filter('woof_get_query_args', 'cache_woof_category_queries', 10, 1);

function cache_woof_category_queries($args) {
    // Only cache when category filter is used
    if (empty($_GET['product_cat'])) {
        return $args;
    }

    // Generate cache key based on current filters
    $cache_key = 'woof_cat_' . md5(serialize($_GET));
    $cached_ids = get_transient($cache_key);

    // Return cached results if available
    if ($cached_ids !== false) {
        $args['post__in'] = $cached_ids;
        return $args;
    }

    return $args;
}

add_action('pre_get_posts', 'store_woof_category_cache', 999);

function store_woof_category_cache($query) {
    // Store query results in cache
    if (!empty($_GET['product_cat']) && !empty($query->posts)) {
        $cache_key = 'woof_cat_' . md5(serialize($_GET));
        $post_ids = wp_list_pluck($query->posts, 'ID');
        set_transient($cache_key, $post_ids, HOUR_IN_SECONDS);
    }
}

How it works:

  • Caches category filter results for 1 hour
  • Generates unique cache key per filter combination
  • Returns cached product IDs on subsequent identical searches

Expected Results:

  • First search: Normal speed
  • Subsequent identical searches: Near-instant results
  • Cache auto-expires after 1 hour

Which Solution to Use?

For Text Search Speed Issues:

Use Solution 1 (post__in filter) – this is the easiest and most effective fix.

For Category Filtering Speed Issues:

Use Solution 2A (Database Indexes) if:

  • You have database access
  • You want permanent optimization
  • You need consistent speed for all queries

Use Solution 2B (Caching) if:

  • You can’t modify database structure
  • Your users often repeat the same searches
  • You have variable search patterns

Combining Solutions:

You can safely use all solutions together for maximum performance:

  1. Enable post__in method (Solution 1)
  2. Add database indexes (Solution 2A)
  3. Add caching (Solution 2B) – optional for extra boost

Important Notes

  • Child Theme Required: Always add code to a child theme’s functions.php to prevent loss during theme updates
  • Backup First: Before adding database indexes, backup your database
  • Test Environment: Test solutions on staging site first if possible
  • Cache Clearing: If using caching solution, remember cached results update hourly

Testing Your Changes

  1. Add the code to your functions.php
  2. Clear all caches (browser, WordPress, server)
  3. Test a search that was previously slow
  4. Monitor search time improvement

Server-Side Optimization

If these solutions don’t provide enough improvement, consider:

  • Upgrading to faster hosting
  • Enabling object caching (Redis/Memcached)
  • Optimizing your database server configuration
  • Reducing number of active plugins

Source: https://pluginus.net/support/topic/very-slow-woof_text_filter-searches/

 


Troubles? Ask for Support!