379 refactor search into module

Moved search function into a lib class that gets loaded into the models requiring search. Works almost exactly the same as before. Resolves #379.