When a user types in the template picker search box, we run a search and show the results in a dropdown
This task is to show the transclusion count for each template next to the template title in the dropdown
One way we might implement this is to add a new prop param in the action api for action=query&list=search - maybe prop=transclusioncount? - and then return the number in the api response for display
Candidate query for retrieving the transclusion count: SELECT count(*) FROM templatelinks INNER JOIN linktarget ON tl_target_id = lt_id WHERE lt_title = '<title>' AND lt_namespace =0
Additional work:
Best of all would be to be able to sort the query results by transclusion count (descending). To use the count for sorting it would have to be a dedicated numeric field in the search index document for the page - the search team could provide one, but it would need an appropriate indexing pipeline (doesn't fit in weighted_tags). If we had a dedicated field the count would be pre-computed and we'd be able to retrieve it from the search-index doc without having the run the query for each result. Note that this would also involve re-indexing, which takes ~16 weeks