Microsoft Teams already allows you to search for messages. You can just start typing a keyword into the search box and press Enter. Microsoft Teams will display a list of chat messages that include the keyword. When you click any of the search results, you will be taken to a view that contains only the selected message, rather than the entire chat thread.
In October 2022, Microsoft is fixing this chat message search experience. With the upcoming update, when you click any search result, you will be taken to the full chat thread, thereby offering full context of the conversation around the message result.
This feature will be available for Microsoft Teams Windows and Mac clients next month.