Skip Navigation

[Resolved] Better search results of dynamic Toolset text content

This support ticket is created 4 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 9 replies, has 2 voices.

Last updated by Vane 4 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#1444745

Hi,

I'd like a text search solution where I want Toolset custom post type (CPT), custom taxonomy (CT) and custom field (CF) text values to be indexed by occurence - even dynamic values.
For example: I have 2 CPTs: Author and Book.
Author has a CF named Author Name (single line text)
Author and Book is in many-to-many relationship.
Author Name is displayed on both Author and Book (via Relationship reference) posts ( both single and archive).
I'd like the search to find this Author name on all Author AND Book posts where it is relevant.
This time default WP and Relevanssi search finds only Author Name on Author CPT, but not on Book CPT!

I have a thread with Relevanssi author here:
https://wordpress.org/support/topic/dynamic-custom-field-value-is-not-found-in-search/

So we clients can suppose Relevanssi is integrated to Toolset for some level, so Toolset might consider to fix this issue
(probably use that relevanssi_content_to_index filter hook, what that guy refers to ).

So is there any solution for a better text search for Toolset, either with Relevanssi or without?

Thank you

#1445919

Hello,

There isn't such kind of built-in feature within Toolset, it needs custom codes, I suggest you try with the Relevanssi plugin, and follow their document to setup custom PHP codes with filter hook "relevanssi_content_to_index":
hidden link

When you are indexing content of a book post, in Toolset side, you can get the related author posts with function "toolset_get_related_posts":
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
And return those fields(Author Name) into the indexed content:
https://developer.wordpress.org/reference/functions/get_post_meta/

#1446045

Hi Luo Yang,

thank you for your response.

Allow me to share my comments:
- we bought Toolset license partially because we are not familiar enough with PHP coding
- we can suppose, that Toolset can search text 100% properly for their CPTs, CTs, CFs etc. (even if that comes from a related object), either itself alone or they integrated Relevanssi on a level that it would do it really properly.
Now this is not the case.
- I'd hire a Toolset Contractor, but there's no any rating or review available about them.
I sent it to Toolset as a feature suggestion, but I never got a feedback (which I also think wrong).
(BTW there are a bunch of WP devs where their products' feature requests are public, clients can comment and vote for them and that works... This is also not the case with your company)

I have and idea:
as a workaround: can we automatically sync 2 Toolset entity parameter (CF, CT, ...) values easily?
I mean in my example: the Author CPT has a CF named Author Name.
AFAIK now Book CPT dynamically fetches this value from Author CPT when it needs.
What if I create also a CF for Book? If I could automatically set a sync for the 2,
Author / Author Name --> Book / Author Name
when first is changed, then the 2nd also, automatically changed, so Relevanssi could index both properly...
This feature would also be useful in other use cases, not only for improving text search.
(I won't waste my time to add it as a feature request though, I spend much more of my time with Toolset than I can)

Thank you

#1446075

Thanks for the comment, for the new question:
can we automatically sync 2 Toolset entity parameter (CF, CT, ...) values easily?
There isn't such kind of built-in feature within Toolset, and it makes things very complicated, so I don't think it is a good idea for your case.

But I do agree that integrating related post information with Relevanssi index is a good idea, and I have checked the Relevanssi document I mentioned above:
hidden link
It should be possible with custom PHP codes, if you need more assistance for it, please provide a copy of your website in below private message box, also point out the problem page URL: where do you search "Author Name" with Relevanssi plugin
I need to test and debug it in my localhost, thanks
https://toolset.com/faq/provide-supporters-copy-site/

#1448085

Thanks for the details, I am downloading the files, will update here if there is anything found.

#1450165

Since you are using higher version of Mysql server, it takes time to duplicate the site.

Please try this, add below codes into your theme file "functions.php":

add_filter('relevanssi_content_to_index', 'add_extra_content', 10, 2);
function add_extra_content($content, $post) {
	if( isset($post->post_type) && $post->post_type != 'book') return;
	$query = new WP_Query( 
		array(
			'post_type' => 'book-author',
			'posts_per_page' => -1,
			//new toolset_relationships query argument
			'toolset_relationships' => array(
				'role' => 'parent',
				'related_to' => $post->ID,
				'relationship' => 'book-author-book',
			),
			'fields' => 'ids',
		)
	);
	$ids = $query->posts;
	$extra_arr = array();
	foreach($ids as $id){
		$extra_arr[] = get_post_meta($id, 'wpcf-author-name', true);
	}
	$extra_content = implode(', ', $extra_arr);
	$content .= $extra_content;
    return $content;
} 

Rebuild the Relevanssi index, and test again

#1450359

It works properly, thank you!
Will you Toolset add this code in a more generalized way in one of the future versions?

#1450621

Thinking about it more:
Toolset is useful mainly for creating and managing directory style websites, managing non-WP-default entities, their attributes (CF, CT, etc.) and their relationships and their different displays (single, archive, custom), etc.
It allows us to display them in very complex ways, but a directory site is not only about displaying data, but also about preparing and providing their data properly for searches.
In most cases the user doesn't browse but searches,
so if I have a university website with CPTs like
- campus
- classroom
- professor
- subject
- course
- event
etc.
with complex relationships, cross referencing to data of another CPT (like Book Author Name in Book CPT in my OP),
user, who searches for string
"math"
wants to find all related results of every each CPT.
It is not a must have only now in 2020, but it was that also long years ago.

I honestly don't believe how this search feature doesn't work properly,
and no, I won't waste my time to add it as a feature request... ( my 2nd reason not to do: I won't get even a response at all )

So pls. Toolset fix it ASAP, not only for me but for the Toolset community!

New threads created by Luo Yang and linked to this one are listed below:

https://toolset.com/forums/topic/display-related-posts-in-relevanssi-search-result/

#1455189

I assume the original question of this thread is resolved:
https://toolset.com/forums/topic/better-search-results-of-dynamic-toolset-text-content/#post-1444745

According to our support policy, we prefer one ticket one question, for the other new questions, please check the new thread here:
https://toolset.com/forums/topic/display-related-posts-in-relevanssi-search-result/

#1455547

I consider the issue completely resolved if no need for custom PHP code to be able to search (and find!) text in CPTs also in Relationships.
Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.