• webdev

    (@swapnilwebdev)


    When i search the Category name it does not show any products in search results,

    for ex, patient lifting ,
    we have catagory named patient lifting which have many products, but when i search “patient lifting” it does not show any products

    What should i do to fix it ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Have you set up Relevanssi indexing so that Relevanssi indexes product categories for products? If you look at a product in the “Patient lifting” category with the Relevanssi debugger (Settings > Relevanssi > Debugging), do the words “patient” and “lifting” appear in the taxonomy content?

    Thread Starter webdev

    (@swapnilwebdev)

    Hi Mikko Saari,

    Patient lifting is parent category and Electric Lift Chairs is child category, products are in Electric Lift Chairs child category.

    So in debug its not showing any term from parent category ,
    here is debug of one of the product
    https://prntscr.com/26k0m3h

    we are using Flatsome theme which have Ajax based live search which shows search results as user starts typing…

    in live search it does not how any products for “Patient lifting”
    https://prntscr.com/26k0gj1

    But when i disable live search of theme and just use default search then it shows product for Patient lifting parent category name also, search results have products from other category also but looks related to keyword

    So what should i do to fix the live search ?

    is there any way to show Relevanssi search results with ajax similar to live search ?

    Plugin Author Mikko Saari

    (@msaari)

    See the Relevanssi Flatsome support documentation. That should help.

    Relevanssi doesn’t index parent category names by default. Here’s how you can index parent categories, just note you’re looking for product_cat, not category.

    Thread Starter webdev

    (@swapnilwebdev)

    Hi Mikko Saari,
    you link for Flatsome live documentations helped and now its showing results from revanssi to live search,

    Regrading indexing parent categories i have added filter in function.php of child theme and then re-run the indexing process , and then with debug checked one of product from child which still shows same data in results, does not shows terms from parent category

    add_filter( 'relevanssi_content_to_index', 'rlv_parent_categories', 10, 2 );
    function rlv_parent_categories( $content, $post ) {
    	$categories = get_the_terms( $post->ID, 'product_cat' );
    	if ( is_array( $categories ) ) {
    		foreach ( $categories as $category ) {
    			if ( ! empty( $category->parent ) ) {
    				$parent = get_term( $category->parent, 'product_cat' );
    				$content .= $parent->name;
    			}
    		}
    	}
    	return $content;
    }

    here is screenshot parent category is Mobility Scooters which is not showing https://prntscr.com/26mc5i5

    Plugin Author Mikko Saari

    (@msaari)

    Try changing the code to this:

    add_filter( 'relevanssi_content_to_index', 'rlv_parent_categories', 10, 2 );
    function rlv_parent_categories( $content, $post ) {
    	$categories = get_the_terms( $post->ID, 'product_cat' );
    error_log( "Categories for post $post->ID are: " . wp_json_encode( $categories ) );
    	if ( is_array( $categories ) ) {
    		foreach ( $categories as $category ) {
    			if ( ! empty( $category->parent ) ) {
    				$parent = get_term( $category->parent, 'product_cat' );
    				$content .= $parent->name;
    error_log( "Category {$category->name} has a parent {$parent->name}." );
    			} else {
    error_log( "Category {$category->name} does not have a parent." );
                            }
    		}
    	}
    	return $content;
    }

    Then go a save a post in a child product category and check what is printed out in the PHP error log. That should give a clue of what’s going on there.

    Hi Mikko

    Can you give an estimate of how long in seconds it should take for the search results to show in the drop-down view after pressing ‘search’?

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

    (@msaari)

    Do a normal Relevanssi search with the same keyword and see how long that takes. The AJAX search should take about the same amount of time. A normal response time is a second or two; longer than five seconds usually means something’s inefficient.

    If you have further questions, please start a new thread instead of posting to an unrelated thread.

    • This reply was modified 3 years, 1 month ago by Mikko Saari.

    Thanks Mikko

    Okay I will start a new thread.

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

    (@msaari)

    Please start a new thread, and I can provide advice. This thread is not the place for it; this thread is about getting Relevanssi to index parent category names for posts.

    For starters, install Query Monitor, it’s a great tool for timing WordPress queries. It will show you exactly what takes time.

    Anyway, please start a new thread.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Search with Category name not working’ is closed to new replies.