• I wanted to use Relevassi on my oxygen site but have run into a problem. It will only provide results on a default search template. I use an advanced query on a repeater to provide categorised results in several sections. I would normally pass get_search_query to the S argument on the query for results, but this will not work with Relevassi. Is there a pre_get_post filter I need to add before each advanced query or can I populate the S argument with a custom function from Relevassi?

    Thus far I have not been able to find an elegant solution, but will happily pass on such a solution to the Oxygen community at large if one is available.

    Thanks for any help you can provide.

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

    (@msaari)

    Try adding the parameter relevanssi to your query and set it to true. Does that help?

    Thread Starter damienlee

    (@damienlee)

    I don’t seem to have the option to add a custom parameter to an advanced query in oxygen. It is not a default query parameter that can be set. I did consider using pre_get_posts to modify the query without success.

    Plugin Author Mikko Saari

    (@msaari)

    Please ask Oxygen support if there’s a filter hook or something else you can use to add custom parameters to the advanced query.

    Thread Starter damienlee

    (@damienlee)

    Okay I will try asking them but I think the pre_get_posts is the only way. I have been trying this:

    add_action( ‘pre_get_posts’, ‘custom_search_query’ );

    function custom_search_query( $query ) {
    if ( ! is_admin() && $query->is_search() && $query->is_main_query() ) {
    $query->set( ‘relevanssi’, true );
    // Output the query parameters for debugging
    var_dump( $query->query_vars );
    }
    }

    Thread Starter damienlee

    (@damienlee)

    Actually I think Im having a much more fundamental issue with the plugins compatibility that might be the problem. For instance if I use the Oxygen PHP return value function with relevanssi_the_title, it works on the frontend but seems to lock up the oxygen editor in some kind of loading loop. Also if I run the following it tells me that Relevanssi doesnt even exist, though it seems to be working in some aspects.

    function check_relevanssi_status() { if (class_exists(‘Relevanssi\Index’)) { $status = Relevanssi\Index::status(); if ($status[‘ready’]) { return ‘Relevanssi index is complete.’; } else { return ‘Relevanssi index is incomplete.’; } } else { return ‘Relevanssi plugin is not active.’; } }

    Plugin Author Mikko Saari

    (@msaari)

    I don’t know where you got that check_relevanssi_status() function, but it definitely doesn’t check anything about Relevanssi. Relevanssi doesn’t use any classes, so that check looks for non-existing features.

    Try removing all those conditionals from the pre_get_posts query and instead just set relevanssi to always true. Does that work? If it does, you can then start figuring out a way to restrict it to the correct queries by looking at $query. It’s possible $query->is_main_query isn’t true, for example.

    Thread Starter damienlee

    (@damienlee)

    That actually helped a lot thanks. There must be a problem with one of the conditions though they are not really needed in my case anyway. And the above was a suggestion made to me, thanks for the correction.

    So I have it working at last which is great, but now for some reason, relevanssi is overriding my no_found_rows parameter on the query. Given PHP is not my strong suit I’m not sure why. I can set this from either the query directly or pre_get_posts but neither work. I’m assuming that Relevanssi is doing this as it creates its own new query?

    Plugin Author Mikko Saari

    (@msaari)

    Relevanssi doesn’t do anything with no_found_rows. It’s a WP_Query parameter, and one that doesn’t apply to Relevanssi, so Relevanssi simply ignores it.

    Thread Starter damienlee

    (@damienlee)

    In that case, how do you limit the number of returned results with Relevanssi, and without pagination?

    Is there not a simple method to leverage Relevanssi to return results with all of the same function as wp_query while using Relevanssi to replace the search query results? Perhaps i need flexibility Relevanssi is simply not designed for. Though it has been great in past non-oxygen projects where I didnt need to customise the output quite so much.

    Plugin Author Mikko Saari

    (@msaari)

    Using posts_per_page. That variable controls how many results Relevanssi returns per page. I’m not sure in what scenario that would not be sufficient. Also, no_found_rows has no effect on the number of posts returned; it just optimizes the performance of WP_Query by making it not count the total number of found rows. As I said, this simply does not affect Relevanssi in any way, and doesn’t do much in WP_Query either.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Oxygen Advanced Query missing search results’ is closed to new replies.