Support » Plugin: Relevanssi - A Better Search » Not filtered search by categories of goods (product_cat)

  • Resolved igora100

    (@igora100)


    Hello dear Mikko!
    Not filtered search by categories of goods
    I use the free version of the plugin.
    When restricting the search area, this way: “/? S = camera & product_cat = sistemy-bezopasnosti-i-umnyy-dom & post_type = product” The plugin does not respond to the “& product_cat = sistemy-bezopasnosti-i-umnyy-dom” parameter and still displays search result all products by criterion “? s = camera”
    In the settings included indexing for POST Types = “POST, PRODUCT” && TAXONOMOMOMIES = “PWB-Brand, Product_Cat, Product_Tag, Taxonomy”

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Mikko Saari

    (@msaari)

    What if you try to use the product_cat ID number instead of the slug? Does that work any better?

    Check the MySQL query with the Query Monitor (see here for instructions). Does the taxonomy parameter appear there? If not, it’s possible Relevanssi is not getting it for some reason.

    Does the taxonomy parameter work in the Relevanssi admin search (Dashboard > Admin search)?

    Thread Starter igora100

    (@igora100)

    What if you try to use the product_cat ID number instead of the slug? Does that work any better?

    Does not help.

    SQL Query:

    SELECT DISTINCT(relevanssi.doc), relevanssi.*, relevanssi.title * 5 + relevanssi.content * 1 + relevanssi.comment * 0.75 + relevanssi.tag * 0.75 + relevanssi.link * 0 + relevanssi.author + relevanssi.category * 0.75 + relevanssi.excerpt + relevanssi.taxonomy + relevanssi.customfield + relevanssi.mysqlcolumn AS tf
    FROM wp_relevanssi AS relevanssi
    WHERE relevanssi.term = 'камера'
    AND relevanssi.doc NOT IN (
    SELECT DISTINCT(tr.object_id)
    FROM wp_term_relationships AS tr
    WHERE tr.term_taxonomy_id IN (6))
    AND ( relevanssi.doc IN (
    SELECT DISTINCT(posts.ID)
    FROM wp_posts AS posts
    WHERE posts.post_type IN ('product') ) )
    ORDER BY tf DESC
    LIMIT 500

    Does the taxonomy parameter work in the Relevanssi admin search

    YES!

    Plugin Author Mikko Saari

    (@msaari)

    Is 6 the correct taxonomy ID number? Or is that some other taxonomy (like WooCommerce stock status)? If it’s not the correct taxonomy ID number, looks like Relevanssi is not getting the parameter for some reason.

    Thread Starter igora100

    (@igora100)

    Is 6 the correct taxonomy ID number?

    NO!. Coorect = 23166

    Or is that some other taxonomy (like WooCommerce stock status)?

    Seems to be yes.

    It turns out the plugin does not receive additional selection criteria?
    Tell me which function of which plugin file it happens, I will try to “catch” this moment.

    Thread Starter igora100

    (@igora100)

    I turned off all the plugins except the relavanssi plugin, the search does not take into account categories: (
    I disabled Relevanssi Plugin – the search began to take into account categories.

    Plugin Author Mikko Saari

    (@msaari)

    Here are some tips for debugging: https://www.relevanssi.com/knowledge-base/debugging-relevanssi-searching-issues/

    If you want to dive into the source code, you can look into lib/search-query-restrictions.php, where the query arguments are processed in relevanssi_process_query_args() and taxonomy arguments in particular in relevanssi_process_tax_query(). However, first the tax_query comes in at lib/search.php in relevanssi_compile_search_args(), so start there.

    As you can see in the admin search, the product_cat filter does work with Relevanssi, the question is just about what is blocking the query parameter from reaching Relevanssi. That’s something specific to your site, so I don’t know what is causing it. Toolset, for example, can do that: it stops URL parameters from getting to Relevanssi.

    Thread Starter igora100

    (@igora100)

    Oh….
    At the entrance of the relavanssi_compile_search_args () function, everything is fine!
    Here we have:

    WP_Query Object
    (
        [query] => Array
            (
                [s] => камера
                [post_type] => product
                [product_cat] => bytovaya-tehnika
            )
    
        [query_vars] => Array
            (
                [s] => камера
                [post_type] => product
                [product_cat] => bytovaya-tehnika
    ...
    
                [tax_query] => Array
                    (
                        [relation] => AND
                        [0] => Array
                            (
                                [taxonomy] => product_visibility
                                [field] => term_taxonomy_id
                                [terms] => Array
                                    (
                                        [0] => 6
                                    )
    
                                [operator] => NOT IN
                            )
    
                    )
    .....
                [taxonomy] => product_cat
                [term] => bytovaya-tehnika
            )
    
        [tax_query] => WP_Tax_Query Object
            (
                [queries] => Array
                    (
                        [relation] => AND
                        [0] => Array
                            (
                                [taxonomy] => product_visibility
                                [terms] => Array
                                    (
                                        [0] => 6
                                    )
    
                                [field] => term_taxonomy_id
                                [operator] => NOT IN
                                [include_children] => 1
                            )
    
                        [1] => Array
                            (
                                [taxonomy] => product_cat
                                [terms] => Array
                                    (
                                        [0] => bytovaya-tehnika
                                    )
    
                                [field] => slug
                                [operator] => IN
                                [include_children] => 1
                            )
    
                    )
    
                [relation] => AND
                [table_aliases:protected] => Array
                    (
                        [0] => wp_term_relationships
                    )
    
                [queried_terms] => Array
                    (
                        [product_cat] => Array
                            (
                                [terms] => Array
                                    (
                                        [0] => bytovaya-tehnika
                                    )
    
                                [field] => slug
                            )
    
                    )
    
                [primary_table] => wp_posts
                [primary_id_column] => ID
            )
    
    .....
    )

    But I have in $query->query_vars['tax_query'] something is, I do not know where it is ….. and it affects the result, because Next, in the relavanssi_compile_search_args () functions, it is from $query->query_vars['tax_query'], and not from $query->tax_query, where I’m fine.

    Plugin Author Mikko Saari

    (@msaari)

    Ah, this is an old problem I’ve solved long time ago. Sorry, my memory’s a bit flaky sometimes… The problem is indeed that the WooCommerce in stock parameter overrides the tax query you’re setting. That’s just the way the tax queries work in Relevanssi, the one where the WooCommerce parameter is is usually the one that’s user-generated and that’s why Relevanssi prefers that.

    For a solution, see “Product category parameters do not work?” here: https://www.relevanssi.com/user-manual/woocommerce/

    Thread Starter igora100

    (@igora100)

    Hi, Mikko!

    Sorry, my memory’s

    Nothing wrong.
    Indeed, it works great!
    Have a nice day!

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.