Excellent question, to begin let's start at a common ground with CRUD:
In CRUD, we lay our application's methods out like such:
The second method 'Read' is essentially what you want to do against the User table in your database or object store.
In your read function rather than searching for
where user.twitterId == 'mySearch'
Instead do
where user.twitterId LIKE '%mySearch%'
The first would restrict your users to knowing IDs exactly, whereas the second gives leeway yet may be slow; thus begins your optimisation journey via tweaking
To answer your question, yes twitter may be querying a list of you and/or your friends followers on app startup or slowly as you use it, which is their solution in runtime optimisation.
Perhaps in your app each post retrieved will come with their top 5 contributiors which are added to relevant Ids to search.