A constructor of TermIndexEntry should allow to specify repository name, and there should be getter/setter for the repository name. Value of the field will not be stored in the database.
Having this field added would allow to use foreign entities in search.
This would involve extending ItemId::newFromNumber and PropertyId::newFromNumber to also accept repository name as a parameter (empty/null by default).