Fix race-condition around creating and assigning the search index