When updating a document in search, update termIdMap so that invariants hold

Be more explicit about map changing here, as well, because Data.Map has no nice "alter and return old" function.