Fix query in template search