WIP:Add MatchFromDoc, and fix add_flag.