Relevance sorting on variables

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Relevance sorting on variables

This topic contains 8 replies, has 2 voices, and was last updated by greenmind87 greenmind87 3 years, 6 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #27455
    greenmind87
    greenmind87
    Participant

    We have relevance problems in searches,

    example.

    search “iphone 8” should show the product “iphone 8” and the variables of that product with the product first (most relevant) and variants next.

    search “iphone 8 64GB” should show the variants of iphone 8 with 64GB first (most relevant) and the product next (if even)

    however when that search is performed the result is nowhere close to that result I have tried all i can think of using your documentation and have no clue how to go from here…

    #27458
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    I suggest trying this configuration: https://i.imgur.com/8BCPGbJ.png
    By default, the single word keywords are ignored for better relevance. It works for most cases, but in your case it is actually a disatvantage. The configuration above should make the results much more relevant.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #27459
    greenmind87
    greenmind87
    Participant

    Hi,

    That was fast!

    Your suggestion solved half the problem!

    – the next part is relevance visible if you search “iPhone 11” it shows “iPhone 11 pro max” first – isn’t the “iPhone 11” more relevant when its an exact match. ?

    and the above search shows no variants but fills the rest with “cover for iPhone 11” products – is there a way to remedy that?

    if we have to rename products to get correct searches, we will, i just want to make sure its required.

    I should mention that we only truly care about the fast live search, the results page is secondary.

    #27465
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Yes, it should be more likely the first one. I tried to log-in to check your configuration, but the password seems to be incorrect.
    I would suggest trying to change the relevance as following: https://i.imgur.com/rGtPYHy.png

    If you are using WooCommerce, then make sure that product variations are selected as well, if you are using them: https://i.imgur.com/haO8amY.png

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #27466
    greenmind87
    greenmind87
    Participant

    Hi,

    I created a new password just in case: weonlyneedthisonce1234

    We use the index table engine and title is set to 300 the rest to 0 (for testing) and the variation are selected as in your second image.

    #27467
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Thanks!

    The main issue was the ordering. The primary order was “Title Descending”, so the “Pro” was the first one, instead of the last. I have changed that to the following: https://i.imgur.com/Mq3J3Rc.png

    I guess you also want to display variations most of the time, but since there were more relevant products, variations were not considered. I have changed the following option to enforce that: https://i.imgur.com/gE1uml4.png
    The plugin will try to enforce variations each time, as well as products.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #27468
    greenmind87
    greenmind87
    Participant

    Hi,

    You do not waste time!

    Were are almost there – the last part is – when I search “iPhone 8 64GB” or any other -what is it called: taxonomy? aka variant-attribute nothing is found.

    #27482
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    I checked the configuration, and selected all missing atrributes on the index table panel I could find. Still, the problem is, that the storage string is stored as “64 GB” and not “64GB”. So searching “64GB” will never match the string “64 GB” due to the whitespace chararcter.

    I think that the best option would be to detect these search strings, and ditch the “GB” part, and only keep the number. For that the only way is to use a custom code. Based on this tutorial, I would recommend this modified version of the code:

    Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!

    add_filter( 'asp_query_args', 'asp_replace_search_keywords', 10, 2 );
    function asp_replace_search_keywords( $args, $id ) {
      /**
       * Add as many words as you want. On the left side place the
       * word or words separated by comma to replace.
       * To the right side, place the single word to replace it with.
       */
      $replace = array(
        '8GB,16GB,32GB,64GB,128GB,256GB,512GB,1024GB' => '8,16,32,64,128,256,512,1024'
      );
    
      // ----------------------------------------
      // Do not change anything below this line
      // ----------------------------------------
      foreach ( $replace as $k => $w ) {
        $kr = explode(',', $k);
    	$wr = explode(',', $w);
        foreach ($kr as $krk => &$krv) {
          $krv = trim($krv);
          if ( $krv == '' ) {
            unset($kr[$krk]);
          } else {
    		$krv = '/\b' . $krv . '\b/u';
    	  }
        }
        foreach ($wr as $wrk => &$wrv) {
          $wrv = trim($wrv);
          if ( $wrv == '' ) {
            unset($wr[$wrk]);
          }
        }
        if ( count($kr) > 0 ) {
          $args['s'] = preg_replace($kr, $wr, $args['s']);
        }
      }
      return $args;
    }

    Please be very careful, I have not been able to test this code!

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #27483
    greenmind87
    greenmind87
    Participant

    Hi,

    Today is a national holyday in Denmark so i am unable to test untill monday.

    The problem with whitespace and methode of replacing make perfect sence and i will go through your code and make corrections if required and test on our staging site to be safe.

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.