Search Query Users in User fields

I am trying to search() for users that can be selected on several pages.

I used users to store information about contacts, team members and so on. On several pages there is a userSelect field where editors can add contacts to pages or add team members to team pages.

Now i want the search() function to be able to find the names of these users on the pages where they are used. But kirby stores only the user object inside the content’s .txt file.

How could I add the user name(s) to the content so the search query can find it/them?

my query is very basic:

<?php

return function ($site) {
 $query   = trim((string)get(‘q’));
 $results = $site
  ->index()
  ->not(page(‘error’), page(‘impressum’), page(‘datenschutz’))
  ->search($query)
  ->paginate(20);

 return  [
  'query'        => $query,
  ‘results’      => $results,
  ‘pagination’   => $results->pagination(),
  ‘searchExcerpt’ => $searchExcerpt
 ];
};

I wouldn’t store the names of the users in the content files (you have no way to ensure these names are unique), but rather “convert” the search string (name) to user UUIDs and then search for these.

The reason why I want the user name to be searchable is because I have a search bar on the website. If visitors search for a name of a person it would be good if pages where this name appears in the frontend would be found. But since the content stores something like user://iuoqd2ho13and only in the template then i call $user→name()the name is not in the content hence cannot be found via search query.

I wondered if there is a possibility of useing a hidden field to automatically store the name(s). If so I am not exactly sure how to approach this.

Or is there even a better way to make the names searchable in frontend through the search query?