First, the search engine matches the search query with keywords and ads related to that query. Next, it analyses other settings, such as the city or language in which the ad is set to appear