In theory Matomo fully supports extracting the search keywords from the Referrer (previous URL).
But most search engines have stopped sending the full URL in the referrer, so all Matomo (and everything else on your website) is able to detect is e.g. https://www.google.com.
So there is no way to know the search keyword a visitor used.