Modifying results content before it is displayed in autocomplete suggestions
- markusParticipant4 years ago #24994
Hi,
I’m trying to find a way to modify post’s content before it is displayed in search suggestions by the suggestions twig template. I would need to remove some unwanted style strings from post’s content with regex. Those strings are made by Gutenberg blocks and they are stored in the database as is.
I already managed to do the same to results on the actual search page by using WordPress’sget_the_excerpt
filter hook and checking ifis_search()
. Actually, I realized it could also have done with WPSOLR’sWPSOLR_ACTION_POSTS_RESULTS
hook.So, is there some similar hook for autocomplete suggestions to modify post’s content before displaying it?
Thank you!
wpsolrKeymaster4 years ago #24998You could instead apply your regex at indexing time. This would fix your display results for search and suggestions, but also improve your search relevance.
You can do it with event WPSOLR_FILTER_SOLARIUM_DOCUMENT_FOR_UPDATE as seen in /wp-content/plugins/wpsolr-pro/wpsolr/pro/extensions/woocommerce/class-wpsolr-plugin-woocommerce.php:
add_filter( WPSOLR_Events::WPSOLR_FILTER_SOLARIUM_DOCUMENT_FOR_UPDATE, [$this, 'add_fields_to_document_for_update',], 10, 5 );
/** * Clean a document just before sending it to the index * @param array $document_for_update * @param $solr_indexing_options * @param $post * @param $attachment_body * @param WPSOLR_AbstractIndexClient $search_engine_client * * @return array Document updated with fields */ function add_fields_to_document_for_update( array $document_for_update, $solr_indexing_options, $post, $attachment_body, WPSOLR_AbstractIndexClient $search_engine_client ) { // Clean $document_for_update (....) return $document_for_update; }
You must be logged in to reply to this topic.