Creating a separate task for this and split it form T107947 since it involves quite some discussion by now.
First patch by @EBernhardson has been merged: https://gerrit.wikimedia.org/r/#/c/236195/
But according to @JKroll it seems it doesn't cover all cases that are relevant for #Deepcat-Gadget:
> I think the current patch doesn't work for all cases yet. The gadget replaces certain search terms by their "expanded" variations. Users can combine several subcategory searches with other search terms and with each other.
> For instance, this search string 'Music deepcat:Cello deepcat:Person' would be transformed by the gadget to something like this:
> Music incategory:id:123|incategory:id:456[...] incategory:id:432|incategory:id:765[...]
> So that the search result would be the intersection of categories 'Cello' and 'Person', including subcategories, and pages which contain the word 'Music'.
> If I understand the patch correctly, the current regexp wouldn't allow such a search string to exceed the length limit. Can that be fixed?