Advertising: Using keywords
Keywords allow certain ads to come up more often when a user's search term is relevant to the ad. For example, an airline company may want their banner ads tied to the keyword "travel". Keyword can also tie a specific realm to an ad. Use "realm:foo" as an advertising keyword to make that ad appear when a user has selected realm "foo".
When selecting an ad, the search engine first loops through all advertisements, comparing their keywords to the user's search terms. If any keywords match any search term, then a smaller set of advertisements is built from the subset of keyword ads which have at least one matching term. Then a random ad is selected from that subset based on the weights of each advertisement in the set. If no keyword-searchterm matches are found, then the engine just selects an advertisement at random based on weights.
For example, assume Bob has 4 ads. Ad 1 has no keywords; Ad 2 has keywords "foo bar"; Ad 3 has keyword "foo", and Ad 4 of course has keyword "bar". Ads 1 and 2 have weight 200 and Ads 3 and 4 have weight 100. Jane does a search on "bar", and the engine identifies Ad 2 and Ad 4 as being particularly meaningful for Jane. The engine calculates the net weight of 2 and 4 as 200 + 100 = 300. The engine chooses a random number between 1 and 300; if it is in 1-200 then it will return Ad 2; if its between 201 and 300, it will return Ad 4. It receives 240 back from rand(), and so it serves Ad 4 to Jane.
As a counter example, assume Jane searches on "widget". None of the keywords match, so the engine does a normal ad selection. A random number in the 200 + 200 + 100 + 100 = 600 range is chosen. The engine gets 410. This number falls in the 3rd interval, and so it returns Ad 3. This example shows that keyword ads have a good chance of being returned when no keyword matches. If this is not desired, give the keyword ads very low weights (in the 1-10 range). This will limit their frequency to mostly keyword searches.
"Advertising: Using keywords" https://www.xav.com/scripts/search/help/1043.html