• 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 - 1 through 15 (of 34 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Have you set up Relevanssi to index the Yoast SEO parameters? Those are not indexed automatically; they are extras that you need to set up Relevanssi to index. I guess they’re stored in custom fields, so you need to either figure out the names of the custom fields and add them to the list of custom fields Relevanssi indexes (this would be best), or you can set Relevanssi to index all custom fields (this adds a lot of unnecessary garbage).

    The AJAX popup search depends on how it’s implemented. Some AJAX searches have filter hooks that can be used to replace the search engine with Relevanssi, and some don’t. Where is the AJAX search coming from? Perhaps you can ask the developers if there’s a filter hook to adjust the search query parameters or to replace the search function.

    Thread Starter stoelwinder

    (@stoelwinder)

    Thanks for the prompt response! I have Relevanssi Search Options > Indexing > Custom fields set to All so it should be indexing custom fields. I know its not optimal, but wanted to get it working first and then can optimise it later (which of course I never got to ;D).

    Again, the results do show up when I search for MPN on the website, which seems to indicate that Relevanssi is working as intended, but the admin interface doesnt show any results when searching for the same MPN.

    Thread Starter stoelwinder

    (@stoelwinder)

    I’m happy to inform you that I’ve managed to fix the AJAX Live Search now showing results when searching for MPN and results are consistent with the search results shown when pressing enter.

    Turns out I should’ve searched the Knowledge Base for “Flatsome” as it gave me the bullet I needed to fix it. I didnt need the big Flatsome portion of code, but I could use the code under “If the live search does not work” and it showed up perfectly.

    Thread Starter stoelwinder

    (@stoelwinder)

    Here I thought I was soooo stupid because Relevanssi Options > Searching > Admin Search was unchecked, but after checking the box and saving, there’s still no results when I search for MPN *Pfew!

    Plugin Author Mikko Saari

    (@msaari)

    On some sites, the Relevanssi admin search does not work with the product post type. I’m not sure why; I’ve never been able to reproduce the problem myself. But it may be that. You can use the Relevanssi admin search (Dashboard > Admin search), that’s guaranteed to work. I can’t guarantee that the admin search for products uses Relevanssi.

    Thread Starter stoelwinder

    (@stoelwinder)

    Thanks for the alternative suggestion. Unfortunately the Admin Search option under Dashboard is not very useable because whatever products it finds, when you click on the link, instead of bringing up the Edit page (to allow me to make product changes), it opens the external page (which I can already get by searching the external site).

    But…….

    Eureka! Managed to get it to work by searching the forum here:

    I added

    add_filter( 'relevanssi_search_ok', 'rlv_product_search_override', 10, 2 );
    function rlv_product_search_override( $ok, $query ) {
    	if ( isset( $query->query_vars['product_search'] ) ) $ok = true;
    	return $ok;
    }

    and

    add_filter( 'relevanssi_modify_wp_query', 'rlv_product_search_modify' );
    function rlv_product_search_modify( $query ) {
    	if ( isset( $query->query_vars['product_search'] ) ) {
    		$s = $_GET['s'];
    		$query->set( 's', $s );
    	}
    	return $query;
    }

    And it now uses Relevanssi for searching in admin. Which caused 1 odd (but understandable) issue:

    When I search products and the product is hidden from the Catalog & Search (for external users), the products now also dont show up for administrators, which can be problematic (some products may need to be hidden while waiting for launch or products may be temporarily unavailable and later have to be made available again without allowing external users to see them).

    Is there some way to adjust the code above to include “hidden” products as well?

    • This reply was modified 2 years, 1 month ago by stoelwinder.
    Plugin Author Mikko Saari

    (@msaari)

    In the Relevanssi admin search, the post title links to the front-end view of the post, but right after is a link “(Edit product)”, which points to the post edit page.

    The WooCommerce visibility in Relevanssi is usually handled at the indexing level so that Relevanssi does not even index products that are hidden from the search. That means having them show up in the admin search is impossible.

    What you can do here is to remove the WooCommerce indexing filters with this:

    remove_filter( 'relevanssi_indexing_restriction', 'relevanssi_woocommerce_restriction' );

    This will make Relevanssi index all products, solving your problem with the admin search. Of course, it now introduces a new problem: you need to now exclude the hidden posts from the front-end search results.

    add_filter( 'relevanssi_modify_wp_query', function( $query ) {
      if ( ! is_admin() ) {
        $tax_query = array(
          array(
            'taxonomy' => 'product_visibility',
            'terms'    => array( 'exclude-from-catalog', 'exclude-from-search' ),
            'field'    => 'slug',
            'operator' => 'NOT IN',
          ),
        );
        $query->set( 'tax_query', $tax_query );
      }
      return $query;
    } );

    Something like that – I just typed that out without testing, so there may be typos, and this assumes you don’t have any other tax_query restrictions in use.

    Thread Starter stoelwinder

    (@stoelwinder)

    I just added both pieces of code to my functions.php but that didnt do the trick.

    Situation:
    Product A: Catalog & Search
    Public Search: Shown
    Private Search: Shown

    Product B: Hidden
    Public Search: Not Shown
    Private Search: Not Shown

    This is applicable both before and after I enabled the code above in functions.php. Is there a typo somewhere?

    Thread Starter stoelwinder

    (@stoelwinder)

    Based on what I can see, it has to do with the remove_filter. When I dont add the second part of the code and I search for the Hidden product, it still doesnt show up in both public and private search.

    Plugin Author Mikko Saari

    (@msaari)

    Did you rebuild the index after removing the WooCommerce indexing filter?

    Thread Starter stoelwinder

    (@stoelwinder)

    Yes I actually did

    Plugin Author Mikko Saari

    (@msaari)

    And the posts are indexed correctly? If you look at them with the Relevanssi debugger, the correct content appears?

    Anyway, the second filter does not actually do anything about hidden posts. It only covers exclude-from-catalog and exclude-from-search. What are hidden posts? How exactly are they hidden?

    Thread Starter stoelwinder

    (@stoelwinder)

    Sorry for the confusion. What I meant was for Woocommerce products, for visibility I change it from “Catalog & Search” to “Hidden” if I don’t want them to show up in public search results, but still want to be able to edit them. This often happens when a product is prelaunch or when it is semi-permanently out of stock but may still experience small batches of restocks irregularly.

    I did not try the debugger. How can I do that?

    Plugin Author Mikko Saari

    (@msaari)

    Settings > Relevanssi > Debugger. Enter the post ID of a hidden post and see what it prints out. If everything is right, you should see the full post content there. This determines whether this is an indexing problem or a searching problem.

    If the hidden posts are not indexed, then the problem may be that you remove the indexing filter before Relevanssi adds it. Changing it to this and reindexing may help:

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

    (@stoelwinder)

    When I hide the result and go to debugging using the post ID, it says:

    <strong>Possible reasons this post is not indexed</strong>
    WooCommerce Yoast SEO Relevanssi index exclude

    However, when I go to the product in question and scroll down to Yoast SEO settings, it shows:

    Allow search engines to show this Product in search results?: Yes

    Is there something else I’m doing wrong?

Viewing 15 replies - 1 through 15 (of 34 total)
  • The topic ‘Website Shows Results but Admin doesnt’ is closed to new replies.