The search for protected content is - partially - possible

I have integrated the search function on a customer website.
There is a protected page where some content is only visible to clients.
I have realized this with this cookbook.

In the search, the protected page is displayed as a hit when I search for a word that is in the protected area. Of course, the protected content is not displayed if nobody is logged in. But the person knows on which page secret content is hidden.
Do I have to exclude the entire page from the search, or what solution is there for this undesirable behavior?

Well, search searches in your whole content file and cannot possibly know if you hide parts of that content via your template code. So yes, you have to exclude such pages explicitly

Of course, it’s true that all content in the .txt is searchable. In most cases, the entire page will also be protected and not just part of it. In my case, I leave it like this, otherwise the page won’t be found at all because it contains important keywords in the head-/subhead.