fix: only do the substring test if the current term is longer then the possibly previously matched one