The built in member search and programmatically searching using new UserList doesn’t work consistently when using custom attributes as search queries.
For example, I have a custom attribute api_key for each user. I can search for these values in the member search but some users can not be found, whilst others can.
The same issue occurs when I search programmatically using magic methods for example
Loader::model('user_list');
$ul = new UserList();
$ul->filterByApiKey('key-here');
If I manually edit any attribute of a user who can not be found, then this starts to work again for that user?
That sounds like the search index is out of date.
You could try running the rebuild search index all job. I am not sure if that covers the user index on c5.6 (it may just be pages it reindexes)
Do you know whether the UserList class and in particular the magic filter methods uses the UserSearchIndexAttributes table as oppose to the raw users table.
It’s interesting because my UserSearchIndexAttributes table has 1,192 records and my users table has 1,198 which may account for the inconsistency of the search methods.
AFAIK it uses a join of user, user info, and the search index. The actual attribute tables are too complicated to search directly, hence they are merged into the search index.
On current cores, all the search indexes are rebuilt by the search index all job. I do not know if older cores do that, or perhaps older cores only re-index pages with the job.
Any change to a user or their attributes, including deletion, should be reflected with an appropriate update of the user search index. From what you are describing, at some point such an update to the index has been missed for some of your users and their index data is skewed.