apply n-gram search