My search code works fine on the preview mode but not on the live site

sync your database from sandbox to live. Go to your database and select sync