It’s possible to code just about anything 😇
A hurdle would be based upon what relay(s). (Like how to efficiently do this while truncating dups etc)
And I think it would be easier if one owns their own relay vs using public ones.
(Forgive me as I haven’t read the dev docs) but essentially all data is stored in a “database” (distributed like Nostr or centralized like X) so it then becomes a “simple” matter of querying the data with parameters to achieve the desired output.