Ok, there might be a problem when a searched term appears in a section header and in other parts of a page.
But we have another problem. We have long pages in our mediawiki. If a user search for a term he just receive the link to a page. On this page he has to search for the term again with the browsers search tool to find the right place with the term. We will make this easier and present always additionally a link to the section where the term is first found.
I implemented this by adding the complete html text of all pages to the elasticsearch index. As search result I receive the highlighted text together with the complete html text. After extracting the highlighted term I extract the section header for this term from the html text and set sectionSnippet and sectionTitle in class CirrusSearch\Result. This works but is not really smart and not suitable for bigger wikis.
Is there a better way? Is it possible to show all section links up the hierarchy (h1, h2, ...) too?
Many Thanks! Henry