It will be difficult to provide the exact implementation details because it depends on how the internal search function has been built into your site.
But basically, when the search results are shown, you should then update your data layer with the search term and number of search results. Those should be populated by your internal search function somehow. After your data layer has been updated with them, then you can track as desired to your analytics tool.