Search preprocessor (rewritten in Haskell.)