When you ransack, you rifle through things, steal some of them, and leave a huge mess behind. If neighborhood dogs got into a cupcake shop, they would probably ransack it.
You can use the verb ransack to describe a careful search — you might ransack your backpack looking for your car keys, for example. Marauding armies, feral cats, burglars, and other troublemakers are often described as ransacking towns, rooms, gardens, or shops, especially if they take things and leave disarray in their wake. The word ransack comes from the Old Norse rannsaka, which has a similar meaning but is literally "search the house."