• Resolved stoelwinder

    (@stoelwinder)


    My products have the Yoast SEO parameters for UPC and MPN configured and when I search the website, it shows me the product as the first entry, however when I search from the admin interface, I get no results. This happens for any product I try and search by MPN.

    Also, although I dont think this is related to Relevanssi, when I try to search on the website, I have an AJAX popup return the results visually first. Relevanssi is not integrated with this search either (so when I search something, it first says no results but once I press Enter, the results show up).

    Any suggestions on what I might be doing wrong?

Viewing 15 replies - 16 through 30 (of 34 total)
  • Plugin Author Mikko Saari

    (@msaari)

    WooCommerce is also mentioned there. Yoast SEO is a possible explanation; Relevanssi cannot know why the post is excluded. In this case, it must be WooCommerce.

    You can disable the Yoast SEO exclusion completely from the Relevanssi indexing settings if you want to rule that out for sure.

    Thread Starter stoelwinder

    (@stoelwinder)

    After disabling the option under Indexing > Advanced for Use Yoast SEO noindex., I still get the same error under Debugging “WooCommerce Yoast SEO Relevanssi index exclude”. However, when I remove the hidden tag, it shows the data from the post successfully.

    Plugin Author Mikko Saari

    (@msaari)

    Did you try removing the Relevanssi WooCommerce restriction filter this way?

    add_action( 'init', function() {
      remove_filter( 'relevanssi_indexing_restriction', 'relevanssi_woocommerce_restriction' );
    }, 999 );

    I suggested this a few posts ago, but you didn’t respond to this.

    Thread Starter stoelwinder

    (@stoelwinder)

    I actually did, but realise what I did wrong:

    I put it as:

    remove_filter( 'relevanssi_indexing_restriction', 'relevanssi_woocommerce_restriction' );

    instead of

    add_action( 'init', function() {
      remove_filter( 'relevanssi_indexing_restriction', 'relevanssi_woocommerce_restriction' );
    }, 999 );

    Which still stopped it from working.

    So, now with the following:

    add_action( 'init', function() {
      remove_filter( 'relevanssi_indexing_restriction', 'relevanssi_woocommerce_restriction' );
    }, 999 );

    – (didnt have to include the portion of excluding hidden from public searches)
    – Yoast Exclusion enabled
    – And a rebuild of unindexed posts

    It is now working as intended!

    Thank you so much for sticking with me!

    One last minor question:
    Is it possible to sort results by putting “out of stock” items at the bottom of the search results, unless it is an exact match?

    Plugin Author Mikko Saari

    (@msaari)

    Yes, you can do that kind of sorting. It needs a filter function on relevanssi_hits_filter. You can use that filter hook to reorder the results any way you want. Put “out of stock” items at the bottom, unless they’re an exact match.

    Thread Starter stoelwinder

    (@stoelwinder)

    Thank you for the suggestion! That looks a bit complicated for my skillset, but I’ll try to mess around with it.

    • This reply was modified 2 years, 1 month ago by stoelwinder.
    Thread Starter stoelwinder

    (@stoelwinder)

    So to confirm, I would do something like this?

    add_filter( 'relevanssi_hits_filter', 'rlv_bucket_sorting' );
    function rlv_bucket_sorting ( $hits )  {
      $out_of_stock	= array();
      $everything_else = array();
      foreach ( $hits[0] as $_post ) {
         // Check here to see if item is out of stock and put it in $out_of_stock unless relevanssi.term == $term, else put it in $everything_else
      }
      $hits[0] = array_merge( $everything_else, $out_of_stock);
      return $hits;
    }
    Plugin Author Mikko Saari

    (@msaari)

    That’s for the out-of-stock stuff, yes.

    $hits[1] has the search query; you can compare that to the post title from $_post->post_title, for example, to see if it’s an exact match.

    Thread Starter stoelwinder

    (@stoelwinder)

    Like this?

    add_filter( 'relevanssi_hits_filter', 'rlv_bucket_sorting' );
    function rlv_bucket_sorting ( $hits )  {
      $out_of_stock	= array();
      $everything_else = array();
      foreach ( $hits[0] as $_post ) {
         if ((! $_post->is_in_stock) && ($_post->post_title == $hits[1]) {
            array_unshift($everything_else, $_post);
         } elseif ($_post->is_in_stock) {
            array_push($everything_else, $_post);
         } else {
            array_push($out_of_stock, $_post);
         }
      }
      $hits[0] = array_merge( $everything_else, $out_of_stock);
      return $hits;
    }
    Plugin Author Mikko Saari

    (@msaari)

    That looks good, yes, if $_post->is_in_stock is true for the in-stock products.

    Thread Starter stoelwinder

    (@stoelwinder)

    Thank you very much. I realise that is_in_stock wont work because I’m dealing with $_post and not $product

    Plugin Author Mikko Saari

    (@msaari)

    I’m not an expert on WooCommerce. Perhaps you can ask on the WooCommerce support forum? I’m sure there’s someone there who can you tell you how to get the product stock status based on post ID.

    Thread Starter stoelwinder

    (@stoelwinder)

    Actually I managed to fix that part.

    Basically, I use relevanssi_get_an_object to put $_post in $post_object. Next I use wc_get_product to take the $post_object and put it in $product and now I can access the product parameters such as is_in_stock() and get_name().

    add_filter( 'relevanssi_hits_filter', 'rlv_bucket_sorting' );
    function rlv_bucket_sorting ( $hits )  {
      $out_of_stock	= array();
      $everything_else = array();
    
      foreach ( $hits[0] as $_post ) {
        $post_object = relevanssi_get_an_object( $_post )['object'];
        $product = wc_get_product( $post_object );
        if ((!$product->is_in_stock()) && ($product->get_name() == $hits[1])) {
          array_unshift($everything_else, $_post);
        } elseif ($product->is_in_stock()) {
    	array_push($everything_else, $_post);
        } else {
          array_push($out_of_stock, $_post);
        }
      }
      $hits[0] = array_merge( $everything_else, $out_of_stock );
      return $hits;
    }

    However, now I have a few weird cases I’m trying to address:

    1. When I search for a term that matches the product title (exact match), then rather than putting the result as the first entry, it puts it as the first entry of out of stock (or the last entry in the $everything_else array as it shows as the first out of stock item all the way at the back of the results).
    2. When I search <search term> and the product title is <search term> 123, it no longer matches as its not an exact match. I’ll use strstr to check for that.
    3. Is there a way to account for <search> 123 <term>? Like if the search terms show up as individual words anywhere in the product title?

    Plugin Author Mikko Saari

    (@msaari)

    1. Why not do this with three arrays? One for the exact matches, one for the out-of-stock stuff, and one for the rest of the posts? That way, you get full control over what goes where.

    3. You can do explode( ' ', $hits[1] ) to get the individual search terms and then check with stristr() for each word and check if all are found in the title.

    Thread Starter stoelwinder

    (@stoelwinder)

    1. Thats a good suggestion! I tried that just now, but I get the same results:

    add_filter( 'relevanssi_hits_filter', 'rlv_bucket_sorting' );
    function rlv_bucket_sorting ( $hits )  {
      $out_of_stock	= array();
      $everything_else = array();
      $exact_match = array();
      foreach ( $hits[0] as $_post ) {
        $post_object = relevanssi_get_an_object( $_post )['object'];
        $product = wc_get_product( $post_object );
        if ((!$product->is_in_stock()) && ($product->get_name() == $hits[1])) {
          array_push($exact_match, $_post);
        } elseif ($product->is_in_stock()) {
    	array_push($everything_else, $_post);
        } else {
          array_push($out_of_stock, $_post);
        }
      }
      $hits[0] = array_merge( $exact_match, $everything_else, $out_of_stock );
      return $hits;
    }
Viewing 15 replies - 16 through 30 (of 34 total)
  • The topic ‘Website Shows Results but Admin doesnt’ is closed to new replies.