• Just found out Relevanssi can’t handle nested tax_queries which is frustrating but this thread suggests all is not lost.
    Could you elaborate on how pruning invalid posts during relevanssi_hits_filter would work and how it affects pagination?
    If I have 30 results and have results set to 10 posts per page and then remove 3 posts during relevanssi_hits_filter won’t that page only show 7 results? Or is that not how it works?

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

    (@msaari)

    Replace lib/search.php with this version, which handles nested tax_queries and let me know if that works correctly: https://www.dropbox.com/s/x9rn83jq8zqy99k/search.php?dl=0

    relevanssi_hits_filter won’t affect pagination, as it handles the full result set before the pagination. If you remove 3 posts, you’ll still see 10 posts on the page.

    Thread Starter JoelStransky

    (@joelstransky)

    Ah, I see you’ve been working in it. Thanks for the file. No errors when I run it which is nice but it doesn’t seem to be writing to the SQL correctly.
    Here’s a tax_query example of what I’m doing.

    Array
            (
                [relation] => AND
                [0] => Array
                    (
                        [taxonomy] => document_type
                        [terms] => Array
                            (
                                [0] => 98
                            )
    
                        [field] => term_id
                    )
    
                [1] => Array
                    (
                        [relation] => OR
                        [0] => Array
                            (
                                [taxonomy] => document_topic
                                [terms] => Array
                                    (
                                        [0] => 141
                                        [1] => 102
                                    )
    
                                [field] => term_id
                            )
    
                    )
    
            )

    For those interested, this is saying: “Give me all posts that are in the document_type term id of 98 AND have document_topic’s 141 OR 102.

    I have a search form with checkboxes for filters. This search returns accurate results with native search but in Relevanssi (with your new search.php), the nested query has no effect.

    Plugin Author Mikko Saari

    (@msaari)

    That OR relation in the sub query was causing trouble for Relevanssi. Try this version: I think it should return better results. https://www.dropbox.com/s/x9rn83jq8zqy99k/search.php?dl=0

    Thread Starter JoelStransky

    (@joelstransky)

    Fantastic! This appears to work great! Well done @msaari. I tried to understand what was going on but I don’t know SQL very well so my eyes just glazed over.
    Going to run some more tests but looks good so far.

    Plugin Author Mikko Saari

    (@msaari)

    Good. I’ll use this in the next version of Relevanssi.

    Thread Starter JoelStransky

    (@joelstransky)

    Just one issue so far. When I submit a search without a phrase (?s=&...) I get no results. It should be that I get all posts filtered by whatever tax_query data I sent. An empty search string should not affect that.

    Plugin Author Mikko Saari

    (@msaari)

    Relevanssi is a full text search, and just doesn’t work without a search term. In order to get results without a search term, you need to take extra steps. Without a search term and some filtering data, I guess Relevanssi could return results, but it wouldn’t know how to order them, as relevancy is determined from the search term.

    This is something I may look into the future, but it’s not an immediate concern to fix.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Work around for lack of nested tax_query support?’ is closed to new replies.