fix error when there are no patterns in db, improve search