• Hi, I am using relevanssi to search a page with a small product catalogue.

    I have some products that are combinations of other products.
    Title is for example: “2x Product 12-78 TD”
    While the basics products title is “Product 12 – 78 TD” (please note the spaces around the dash).
    The different spaces are coming through an API so I can’t change it, because it is updated regularly.

    My problem is: When someone is searching “Product 12-78”, the “2x …” products are shown first, which is technically correct, because the title is exactly matched. Is there a way to downgrade search results with “2x” in the product title through a filter? I went through the filter hooks but couldn’t find it.

    The basic product should be first in list.

    Thank you for any help!

    • This topic was modified 9 months, 3 weeks ago by mhmuc.
Viewing 1 replies (of 1 total)
  • Plugin Author Mikko Saari

    (@msaari)

    I would start with fixing the product titles. You can change them for Relevanssi.

    add_filter( 'relevanssi_post_title_before_tokenize', function( $title ) {
    $title = str_replace( array( ' - ', ' – ' ), '-', $title );
    return $title;
    } );

    Add this to your site and rebuild the index. Now “Product 12 – 78 TD” is indexed as “Product 12-78 TD”. Does that help? (And by the way, what is your “Hyphens and dashes” setting in the advanced indexing settings? It should probably be “remove”.)

    If that doesn’t help, then you can use the relevanssi_results hook. Go through the posts, get the post with relevanssi_get_post() for maximum performance, and check the title from $post->post_title (don’t use get_the_title()). If the title has “2x” in it, adjust the weight.

Viewing 1 replies (of 1 total)
  • The topic ‘Change the weight for some product titles in search’ is closed to new replies.