• Resolved andersjytzler

    (@andersjytzler)


    Hey guys,

    Great plugin. Looks really good. But we are having trouble with the AWS plugin crashing the entire site when doing a search.

    The query generated is very long:

    Count: 2 Time=335.07s (670s) Lock=0.00s (0s) Rows_sent=10.0 (20), Rows_examined=41089354.0 (82178708), Rows_affected=0.0 (0), wp_m2vr9[wp_m2vr9]@localhost
     SELECT
     distinct ID,
     (SUM( ( case when ( term_source = 'title' AND term = 'lob' ) then 260 * count else 0 end ) + ( case when ( term_source = 'title' AND term LIKE '%lob%' ) then 46 * count else 0 end ) + ( case when ( term_source = 'content' AND term = 'lob' ) then 47 * count else 0 end ) + ( case when ( term_source = 'content' AND term LIKE '%lob%' ) then 38 * count else 0 end ) + ( case when ( term_source = 'sku' AND term = 'lob' ) then 300 else 0 end ) + ( case when ( term_source = 'sku' AND term LIKE '%lob%' ) then 50 else 0 end ) + ( case when ( term_source = 'excerpt' AND term = 'lob' ) then 47 * count else 0 end ) + ( case when ( term_source = 'excerpt' AND term LIKE '%lob%' ) then 38 * count else 0 end ) )) as relevance
     FROM
     wp_aws_index
     WHERE
     1=1
     AND ( ( term LIKE '%lob%' ) )
     AND visibility NOT IN ( 'hidden', 'catalog' )

    And CPU usage as a reason of that spikes incredibly when AWS is activated and being used, so the site crashes. See screenshot: http://imageshack.com/a/img923/1349/YHo7P5.png

    We have had the plugin installed for i think more than a year, and only recently started having these issues 11. february, 2021. We have about 5.500 indexed products, and have had a lot of products for a long time.

    • This topic was modified 3 years, 2 months ago by andersjytzler. Reason: More information

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author ILLID

    (@mihail-barinov)

    Hello,

    We are currently working on a new plugin version that will have performance fixes and also will include special performance options.

    For now there are several steps that can be made to decrease database load and make search queries faster.

    1. Disable search for archive pages from the plugin settings page.
    2. Disable all search sources that you don’t need from the ‘Search in’ option.
    3. Removing from index all search sources that you are not using.

    Please use the following code snippet. You need to add it somewhere outside the plugins folder. For example, inside functions.php file of your theme or use some plugin for adding code snippets like

    https://wordpress.org/plugins/code-snippets/. Also, after adding this code, you need to re-index the plugin table.

    add_filter('aws_indexed_data', 'my_aws_indexed_data');
    function my_aws_indexed_data( $data ) {
        foreach ( $data['terms'] as $source => $all_terms ) {
            if ( strpos( $source, 'meta_' ) === 0 || strpos( $source, 'tax_' ) === 0 || strpos( $source, 'attr_' ) === 0  ) {
                unset( $data['terms'][$source] );
            }
        }
        return $data;
    }

    This code removes custom fields, taxonomies and attributes of products from the index table. If you need sources to remove or want to leave some of them – please write to me.

    4. Do you need to display product variations inside search results? If no than make sure that plugin option ‘Variable products’
    set to  ‘Show only parent products’. 
    Also please add the following code snippet like in the previous example. Don’t forget to re-index the plugin table.  

    add_filter('aws_indexed_data', 'my_aws_indexed_data2');
    function my_aws_indexed_data2( $data ) {
        if ( $data['type'] === 'child' ) {
            return false;
        }
        return $data;
    }

    This can heavily increase search speed and decrease database load.

    5. Last solution – change some search behavior. By default the plugin use partial search match.
    This means that if, for example, you search for rat plugin will also show the results with words like integration.
    So if you don’t turn on ‘Exact match’ search option from the plugin settings page you can use the following snippet.
    By using it when searching for rat you will see results only with these words or words that start with rat ( for example rational ).
    This can heavily decrease database memory usage.

    add_filter( 'aws_search_query_array', 'my_aws_search_query_array' );
    function my_aws_search_query_array( $query ) {
        global $wpdb;
    
        $regex = "/LIKE '%(.*?)%'/is";
    
        $query['relevance'] = preg_replace( $regex, "LIKE '$1%'", $query['relevance'] );
        $query['search'] = preg_replace( $regex, "LIKE '$1%'", $query['search'] );
        $query['having'] = preg_replace( $regex, "LIKE '$1%'", $query['having'] );
    
        $regex = "/LIKE '{.*?}(.*?){.*?}'/is";
    
        $query['relevance'] = preg_replace( $regex, "LIKE '$1%'", $query['relevance'] );
        $query['search'] = preg_replace( $regex, "LIKE '$1%'", $query['search'] );
        $query['having'] = preg_replace( $regex, "LIKE '$1%'", $query['having'] );
    
        return $query;
    }
    Thread Starter andersjytzler

    (@andersjytzler)

    Hey @mihail-barinov thanks for advice.
    I tried all your suggestions and it seemed to have worked.
    But i couldn’t find this: “4. Do you need to display product variations inside search results? If no than make sure that plugin option ‘Variable products’
    set to ‘Show only parent products’.”
    Maybe it is for premium only?

    Very good, thank you! Would be also good to have some options for performance, as you mention.

    //Anders

    Plugin Author ILLID

    (@mihail-barinov)

    But i couldn’t find this: “4. Do you need to display product variations inside search results? If no than make sure that plugin option ‘Variable products’
    set to ‘Show only parent products’.”
    Maybe it is for premium only?

    Yes, this option only for PRO plugin version that has feature to display product variations as search results.

    Thread Starter andersjytzler

    (@andersjytzler)

    @mihail-barinov Thank you ILLID. Search speed still seems to be good and haven’t crashed webshop since optimization. Very good. We should probably buy your premium 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Webshop crashes when doing search’ is closed to new replies.