There are two related issues around the MatchingTermsLookup::getTopMatchingTerms() method:
- There only remaining (non-mock) implementation, DatabaseMatchingTermsLookup, doesn’t really implement the method – it just returns the result of getMatchingTerms() unchanged, since the new term store doesn’t support a notion of “top” matching terms. This suggests that getTopMatchingTerms() could be removed from the interface.
- However, in doing so, DatabaseMatchingTermsLookup actually violates the contract of the method. The interface documentation clearly states that the method should only return one TermIndexEntry per Entity, and even the mock implementation (MockMatchingTermsLookup) takes care to ensure this – but DatabaseMatchingTermsLookup will happily return multiple search results for the same entity (e. g. if there were multiple matching aliases).
Do any callers of getTopMatchingTerms() actually rely on this “distinct entities” behavior? So far, while I’ve seen a TermSearchInteractor return multiple results for the same entity in a PHP shell, I haven’t seen multiple results for the same entity in an API search response, so maybe a filter is already being applied at a higher level.