Custom OpenSearch Highlighter Plugin

Greetings all,

I have been trying to create a custom highlighter by creating a plugin that implements SearchPlugin, getHighlighter() method and create my own CustomHighlighter class that implements the Highlighter interface and its highlight() method.
My logic needs to check the user query to determine what should be highlighted.

Question: How can I get the user query from within SearchPlugin.getHighlighter() method and/or the CustomHighlighter?
(the whole REST request body is preferred).

Your help is highly appreciated.

try this example to replicate

Thanks.

But I dont see how this is related to highlighting. I mainly need to access the user query from within getHighlights method or any equivalent method.