• Resolved tflight

    (@tflight)


    I’ve encountered a weird issue recently where the search results are duplicated when this plugin is enabled. For example if I search for “hello search”, the first match is duplicated a dozen or so times in the search results. Disabling the plugin resolves the issue.

    This only started happening recently and isn’t happening on my local or staging sites, only the production site. The few differences in the production site are things like object caching. Of course debugging the live site without access to a step debugger, etc is a bit tricky. Likewise disabling plugins on a busy live site isn’t fun either.

    I’ve worked around the issue with this:

    function cc_search_distinct($where)
    {
        if (is_search()) {
            return "DISTINCT";
        }
        return $where;
    }
    add_filter('posts_distinct', 'cc_search_distinct');

    That fixes the issue for me, but I’m not certain what changed in my setup where I suddenly need this. I suspect it has something to do with the sql_distinct function in act-better-search/src/Search/Request.php but inspecting those conditions on the live site isn’t easy.

Viewing 9 replies - 16 through 24 (of 24 total)
  • Thread Starter tflight

    (@tflight)

    10.5.16-MariaDB – MariaDB Server

    #1 – 6963 total, Query took 0.0007 seconds.
    #2 – 182499 total, Query took 0.0007 seconds.
    #3 – 8010410 total, Query took 0.0007 seconds.
    #4 – 182500 total, Query took 0.0563 seconds.
    #5 – 6963 total, Query took 0.0012 seconds.
    #6 – 6963 total, Query took 0.0962 seconds.
    #7 – 8010503 total, Query took 1.8671 seconds.
    #8 – 6852 total, Query took 0.0013 seconds.
    #9 – 6852 total, Query took 0.1182 seconds.

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Thank you @tflight!

    Can I ask you to run a little test? Download and install this version of the plugin. Then do some test searches. An acf-better-search.log file should be created in the root directory of your WordPress. Please send me its contents.

    Thread Starter tflight

    (@tflight)

    2023-09-07 15:06:41 : SELECT DISTINCT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts INNER JOIN wp_postmeta AS a ON ( a.post_id = wp_posts.ID ) LEFT JOIN wp_postmeta AS b ON ( (( b.post_id = a.post_id )) AND (( b.meta_key LIKE CONCAT( '_', a.meta_key ) )) ) WHERE 1=1 AND ( ( ( b.meta_id IS NOT NULL ) AND ( a.meta_value LIKE '%dark%' ) ) OR ( ( wp_posts.post_title LIKE '%dark%' ) OR ( wp_posts.post_content LIKE '%dark%' ) OR ( wp_posts.post_excerpt LIKE '%dark%' ) ) ) AND ((wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'acf-disabled')) OR (wp_posts.post_type = 'page' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'acf-disabled')) OR (wp_posts.post_type = 'attachment' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'acf-disabled')) OR (wp_posts.post_type = 'product' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'acf-disabled')) OR (wp_posts.post_type = 'alerts' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'acf-disabled')) OR (wp_posts.post_type = 'staff' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'acf-disabled'))) ORDER BY wp_posts.post_title LIKE '{e2ae4afcb0d00f85a894569b16c2fa9550df0cdfdbb31d98cca597c9fb840f32}dark{e2ae4afcb0d00f85a894569b16c2fa9550df0cdfdbb31d98cca597c9fb840f32}' DESC, wp_posts.post_date DESC LIMIT 0, 24

    Hey there,

    I’m joining the fun here – we have the same issue with tens or even hundreds of duplicate results on some searches (not all) when the plugin is active.

    Here’s a screenshot from Query Monitor, hope that helps a bit: https://a.cl.ly/P8uDvyW0

    ACF Pro version 6.2.1.1

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @zinja Thank you for your report. Could you do the same test in Query Monitor, but with our plugin not active?

    @mateuszgbiorczyk There you go: https://a.cl.ly/8Lu6mnkJ

    Thanks for looking into this ??
    Let me know if we can do more to help.

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Thank you @zinja!

    Could you go to phpMyAdmin, to the Variables tab? Please send me a screenshot of the entire configuration – I will compare it with myself and try to find the source of the problem. Due to the fact that there may be confidential information there, please send this message to the following e-mail address: hello(at)mattplugins.com.

    I will check it and get back to you with information.

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @zinja This error has nothing to do with your database configuration. Later, I noticed in your screenshots (from the Query Monitor plugin) that the problem is that my plugin adds the “SELECT DISTINCT” statement to the SQL query, and the “DISTINCT” statement then disappears. In a strange way, because it shouldn’t be happening. This causes duplicate search results.

    @tflight, @tonyko, @swb1192 and @zinja – I have changed the way the “DISTINCT” statement is added in the plugin. Now everything should work. Thank you for your patience and cooperation. Your efforts helped me solve the problem. Please update the plugin to the latest version (4.2.0) and let me know if everything works properly now.

    Updated the plugin and everything works perfectly! Thank you very much for your commitment and the fast reaction. ??

Viewing 9 replies - 16 through 24 (of 24 total)
  • The topic ‘Posts in Results Duplicated Dozens of Times’ is closed to new replies.