Improve similar badge search efficiency

This improves the efficiency of the getSimilar() badge method, both in terms of speed and memory usage.  Both should be improved by more than an order of magnitude.