• Resolved Yavor Simeonov

    (@simeonovy)


    Hello, I have installed and configured the plugin. It works, but because of another app that allows manual reordering of posts, the search results are loaded by recency from back to front. That is, the first results are the most irrelevant, and the last ones are the most accurate. It turned out that when searching the search admin page, Relevanssi reads the post from back to front. That’s probably why it shows the results like that. I suspect the “and” function doesn’t work either for the same reason. Would you be helpful in this interesting case study?

    The page I need help with: [log in to see the link]

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

    (@msaari)

    Try this in your theme functions.php:

    add_filter( 'relevanssi_orderby', 'rlv_fix_order' );
    function rlv_fix_order( $orderby ) {
      return array( 'relevance' => 'desc' );
    }

    This tells Relevanssi to return the results in descending order of relevance.

    Thread Starter Yavor Simeonov

    (@simeonovy)

    Hello, thank you for your quick and accurate reply. I delayed my feedback as it was necessary to do further testing of my search results. It turned out that this was not the described search problem. I changed the settings and removed a conflicting app. Now a challenge is these search queries that I try in Admin Search to visualize them in the front end as well. For example – a search for “отец Иван” doesn’t work for me like in the Admin search. Is it a setup issue or am I looking for a conflict somewhere? With similar searches, for example, “екзарх Йосиф” I get correct results, and for “отец Иван” the first result with both words is my tenth and eleventh result. I am attaching screenshots. I neglected to mention that both of these different searches are of the same type – they are made up of church rank and name.

    Plugin Author Mikko Saari

    (@msaari)

    Did you add the snippet I gave you to your site? Your problem is still that the results are not sorted by relevance. If I tell Relevanssi to sort them by relevance by setting the orderby parameter to relevance, I get the results you get from the admin search. See these results.

    Thread Starter Yavor Simeonov

    (@simeonovy)

    Hello again. I added the code as the search is relatively more relevant now. But that’s how it was set up – order by – relevance. However, another problem appeared – some elements break when previewing the search. Attach photos. When I remove the code, no such breaks are shown. I’ve also captured the error the console gives me for convenience if you think that would be helpful.

    Plugin Author Mikko Saari

    (@msaari)

    Yes, that’s how Relevanssi works by default, but something on your site overrides the orderby parameter to change the order. That happens sometimes.

    The error in the console is not related to the code; it’s a problem with how your search form HTML code is formulated, and that function has nothing to do with that. To get rid of the error, you need to fix the label tag in your form. That’s coming from your theme. I can’t tell what else is wrong in the first screenshot.

    Is the problem in the second screenshot the empty space after the post title? When I visit the page, the space doesn’t appear; everything is laid out right.

    The most common cause for broken search results page layouts with Elementor is the Conditional and Inline CSS Loading Experiment in Elementor; you can’t use that with Relevanssi.

    Thread Starter Yavor Simeonov

    (@simeonovy)

    I understand that you are recommending not to use Elementor template for search results as it does not provide relevant results, instead of Relevanssi? Now, do you think the search results are satisfactory with the added code?

    Plugin Author Mikko Saari

    (@msaari)

    No, I’m not saying that at all. This is not caused by the Elementor template; Elementor does not change the orderby value in itself. This problem is likely caused by a third party, not Elementor or Relevanssi.

    You’re the best judge of the result quality, but if the front-end search matches what you see in the Relevanssi admin search, you’re getting unfiltered Relevanssi results and that’s what you can get with Relevanssi.

    Thread Starter Yavor Simeonov

    (@simeonovy)

    Thank you for the detailed information. I’ll share my doubts with you – the only application that can have an impact over “orderby” I think is “Simple Custom Post Order”, which allows to reorder posts /first, second, third, etc./. If I am right, is there an option for compatibility with Relevanssi?

    Plugin Author Mikko Saari

    (@msaari)

    Yes, that’s it. The post order plugins do this. The compatibility option is the filter function I gave you: you can’t change how Simple Custom Post Order works, but you can override it for Relevanssi searches with that filter. That’s the easy solution for this problem.

    Thread Starter Yavor Simeonov

    (@simeonovy)

    Thank you for your time. You were very helpful. Be healthy!

    Thread Starter Yavor Simeonov

    (@simeonovy)

    Hello again. I added a hook for exact_match_bonus and the search seems to improve. If there is a way to show more exact match results, please share. We also need to group these results by date, starting with the most recently added. I looked through the hooks on your site but couldn’t figure out which one would work in this case.

    Plugin Author Mikko Saari

    (@msaari)

    The relevanssi_hits_filter is the best tool for grouping results. See under the “Sorting” heading: there’s an example of sorting posts into buckets. You could create buckets based on date ranges and sort the results into those.

    Thread Starter Yavor Simeonov

    (@simeonovy)

    If I understand you correctly, even though I don’t have deep PHP knowledge I should add this code:

    add_filter( ‘relevanssi_hits_filter’, ‘rlv_bucket_sorting’ );
    function rlv_bucket_sorting( $hits ) {
    $rest_of_the_posts = array();
    foreach ( $hits[0] as $_post ) {
    $post_object = relevanssi_get_an_object( $_post )[‘object’];

    if 
    } elseif ( date( 'Y' ) === date( 'Y', strtotime( $post_object->post_date_gmt ) ) ) {
    } else {
      $rest_of_the_posts[] = $_post;
    }

    }
    $hits[30] = array_merge( $rest_of_the_posts );
    return $hits;
    }

    Plugin Author Mikko Saari

    (@msaari)

    Let’s start from the beginning: what exactly are you trying achieve?

    Thread Starter Yavor Simeonov

    (@simeonovy)

    Only exact search hits, sorted from most recently added posts to older. I hope I expressed myself correctly.

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Display back-to-back search results by relevance’ is closed to new replies.