Relevanssi doesn’t know anything about the accordions. The way I see it, Relevanssi’s responsibilities end just before the search results page, and whatever comes after that falls under the responsibility of the theme.
Now can this be done? Perhaps. You’d probably need two things:
- PHP code that reads in the search terms from HTTP_REFERER and places them in variables on the page for easy javascript access. See
relevanssi_highlight_in_docs()
in /lib/excerpts-highlights.php for an example on how to do that.
- Javascript that goes through the page content and finds all the search term matches, figures out if they’re inside an accordion element and if they are, opens the accordion.
I can help you with the first bit, but you can probably sort that out from the relevanssi_highlight_in_docs()
example. I have little skill – and to be honest, little interest – in figuring out the second part.
Thank you Mikko for pointing me in the right direction. This “issue” is clearly not directly limited to Relevanssi or Divi, but as far as I can see, a problem with any implementation of accordions, toggles and tabs where user interaction is required to see the content. Something to be aware of when structuring the content really.
I recon it to some degree can be improved by a skilled programmer, toggles can be opened by javascript, but when it comes to tabs? – I can’t imagine how that should be solved elegantly – only one tab can be active.
Thanks again for providing this great plugin to the community. I’ve been implementing a few tricks to improve the search when using the Divi theme quite a lot. The solution includes Relevanssi, and I hope to find time to write a blog post about it when I’m done..
A great day to you Mikko.
/Bjarne