Search query refactor, schema cleanup, and indexes