Adding search to a tree

This is about adding a search field to a tree: the search for a keyword is supposed to return all tree nodes containing that keyword

Also the tree nodes have the usual expand / collapse checkboxes

The specifics about the tree is that when a tree node is selected, a list of attached entities is displayed on a side panel

How should the search work in regards to previously selected nodes (and previously displayed entities), from the usability point of view ?

Thank you so much in advance