• Resolved ahordii

    (@ahordii)


    Hello there!

    We have some problems with the relevance of the search suggestions. When I searched “Silver ring” here https://prnt.sc/Myp5IrSSx9lQ, it show unrelevant products at the bottom. I checked these products – they don’t have “silver” or “ring” inside their title or description.

    However, what I noticed, they have a “silver” product tag. Could that be the reason they appear? And if so, can we exclude such matching, since it’s not relevant to the search query “Silver ring”?

    Thanks in advance!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter ahordii

    (@ahordii)

    ok, even if I remove the “silver” tag https://prnt.sc/pvyKGeaHTmc1, the product is still appears on the search suggestions https://prnt.sc/-8pTvbbJT58w

    Plugin Support Kris

    (@c0nst)

    Hi @ahordii

    I think it will be a good idea to increase the scoring of products whose names will contain exactly the same phrase as the searched one. This should move the relevant results higher in the autocomplete list and on the search results page. Here’s how:

    // Add extra score if product title shares exact phrase with search phrase
    add_filter( 'dgwt/wcas/search_results/product/score', function( $score, $keyword, $product_id ) {
    	$woo_product      = wc_get_product( $product_id );
    	$product_title    = strtolower( $woo_product->get_title() );
    	$search_phrase    = rtrim( $keyword, 'es' );
    	$search_phrase    = rtrim( $search_phrase, 's' );
    	$phrase_words     = explode( ' ', $search_phrase );
    	$product_words    = explode( ' ', $product_title );
    
    	foreach ( $phrase_words as $phrase_word ) {
    		foreach ( $product_words as $product_word ) {
    			if ( $phrase_word === $product_word ) {
    				$score += 200;
    				break 2;
    			}
    		}
    	}
    
    	return $score;
    }, 10, 3 );
    

    You have two ways to add this code to your theme:

    1. Open the functions.php in your child theme and add the code at the end.
    2. or install the Code Snippets plugin and apply this code as a snippet.

    Regards,
    Kris

    Thread Starter ahordii

    (@ahordii)

    Hey Kris, thanks for your answer.

    I added the code snippet you provided, but doesn’t seem it is working correctly as well.

    Here are the new instant search results https://prnt.sc/ds2470icA6Qq, which again contains not related products for some reason. Also, please check the search page here https://chromeworld.jp/?s=silver+ring&post_type=product&dgwt_wcas=1. It contains only 16 products as a result, with the random not related product there https://prnt.sc/DAjEL4CYov4i.

    Thread Starter ahordii

    (@ahordii)

    Hello there!

    Any updates on the search suggestions logic issue?

    Thanks!

    Thread Starter ahordii

    (@ahordii)

    Sorry, any news here?

    Unfortunately, the search results are not related at all. See the suggestions here https://prnt.sc/gr9o_GkE3CUu, it shows only 2 products with the search “heart”. However, we have a lot of “heart” products https://prnt.sc/LXrtppGrvgYy

    How can we show products, related to the request via your plugin? Is it even possible? I feel a bit lost on the results it shows and the real related products…

    Thanks.

    • This reply was modified 1 year, 2 months ago by ahordii.
    • This reply was modified 1 year, 2 months ago by ahordii.
    Plugin Support Kris

    (@c0nst)

    Hi @ahordii

    Sorry for the late reply. I was looking for the optimal solution. From what I see, almost every product description contains the word “silver”. So it is very possible that disabling search in the product description (you can leave the search in the short description) will be a good solution. Go to WP Admin -> WooCommerce -> Search config (tab) to do it.

    Additionally, you can try to enter a value greater than 200 in the snippet I sent you. Replace $score += 200; with $score += 500;

    Regards,
    Kris

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Products from search suggestions problem’ is closed to new replies.