Custom search Fields and tags in Wordpress with slow results

Asked

Viewed 51 times

1

I have a Wordpress site that holds custom Fields related to "Photo Albuns", I am now creating a search engine for such.

The problem is that because he uses Tags in his albums and custom_fields in the photos, when I do a search where all the search must be between one, another or both, the search delay for the results varies from 30 to 40 seconds.

Tables: wp_terms with 688 records wp_term_taxonomy with 752 records wp_term_realtionships with 4511 records wp_postmeta with 629459 records wp_post with 9929 records

I would like help to optimize this my subquery, that in it occurs the delay in return.

SELECT
        t1.post_id,
        t1.meta_value,
        t1.meta_id,
        CONCAT(
            t1.meta_value,
            GROUP_CONCAT(wt. NAME SEPARATOR ',')
        ) AS conc_value,
        REPLACE (
            t1.meta_key,
            'image',
            'details'
        ) AS details,
        REPLACE (
            t1.meta_key,
            'type',
            'details'
        ) AS details2,
        REPLACE (
            t1.meta_key,
            'details',
            'image'
        ) AS details3,
        REPLACE (t1.meta_key, 'image', 'type') AS type,
        REPLACE (
            t1.meta_key,
            'details',
            'type'
        ) AS type2,
        REPLACE (t1.meta_key, 'type', 'image') AS type3
    FROM
        wp_postmeta t1
    INNER JOIN wp_posts t2 ON t1.post_id = t2.ID
    AND t2.post_type = 'post'
    INNER JOIN wp_term_relationships wtr ON t2.id = wtr.object_id
    INNER JOIN wp_term_taxonomy wtt ON wtt.term_taxonomy_id = wtr.term_taxonomy_id
    AND wtt.taxonomy = 'post_tag'
    INNER JOIN wp_terms wt ON wt.term_id = wtt.term_id
    GROUP BY
        t1.meta_id
    HAVING /*OS CAMPOS AQUI SÃO VARIAVEIS, ESTE CONTEM 3 POREM NO MEU CODIGO PHP EU PERMITO ATE 6 POR CONTA DA REGRA DE NEGOCIO ESTABELECIDA*/
        (
            (
                BINARY CONVERT (
                    UCASE(conc_value) USING utf8
                ) LIKE BINARY UCASE(_utf8 '%religião%')
            )
            AND
            (
                BINARY CONVERT (
                    UCASE(conc_value) USING utf8
                ) LIKE BINARY UCASE(_utf8 '%pontos%')
            )
            AND(
                BINARY CONVERT (
                    UCASE(conc_value) USING utf8
                ) LIKE BINARY UCASE(_utf8 '%centro%')
            )
            AND(
                BINARY CONVERT (
                    UCASE(conc_value) USING utf8
                ) LIKE BINARY UCASE(_utf8 '%corrente%')
            )

        )
  • Your query will clearly be time consuming, it is giant. Can you describe the problem a little more in terms of the architecture of WP? I learned (in the worst possible way), that it is almost always possible to search for things using WP’s own methods, without interacting with the bank

  • Well, as said above the site is a binder of photo albums, the post is the Album and inside it insert the photos, where the descriptions are custom Fields. <I am unintentionally editing uploaded> My current need is to: get the photos that are inside the album through a search that will check whether: All fields entered are within the description (meta_value of custom field) and/or within the tags of the Post photo holder (wp_term). This system was not to have been done in Wordpress, I know, but as I am giving maintenance in it I am seeking the best solution.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.