images/contents.gifimages/index.gif

News Query Operators

There are three query operators available for use in search queries:

&
AND
, (comma)
INCLUSIVE OR
%
EXCLUSION

The ampersand (&) character represents the AND operation. It is a set intersection operator, where the contents of the two lists are compared and only those elements present in both lists are included in the result list. It may sometimes be useful to think of this operator as an inclusive filter operator which begins with one list and includes in the resulting list only those elements which are present in the second list, thus filtering out all elements not contained in the second list. This operation is commutative.

The comma (,) character represents an INCLUSIVE OR operation. It is actually a set union operator, where the contents of two lists are merged into one result list that contains everything present in the two original lists, but without duplication of common elements. This operation is commutative.

The percent sign (%) represents the EXCLUSION operation. It is a set difference operator, by which any elements of the first list which occur in the second list are "removed" from the first, leaving only those items which were different in the result list. Or, in other words, it reduces the contents of the first list by excluding any elements also found in the second list. This produces a result list which is hopefully smaller (that's the intent) but will never be larger than the first list. This operation is not commutative.

The exclusion operator makes an effective exclusive filter, filtering out of the first list any items which also appear in the second list. In other words, it allows the query to specify what stories are not wanted in the query results. This is often useful to trim a few extraneous stories from an otherwise satisfactory but slightly too inclusive search query.

Each of the three operators just described has a different intrinsic precedence level, with the AND operator being highest and the EXCLUSION operator being lowest in precedence. This assignment of precedence was chosen to make the interpretation of search queries more closely related to our use of natural language. For example, the query,

Clinton, Budget & Talk

would be evaluated by combining the match-lists derived from Budget and Talk and then combining that result with the match-list derived from Clinton. The higher precedence of the & operator causes it to be evaluated first. Explicitly grouped, the query would appear as:

Clinton, (Budget & Talk)

As before, this search query would match headlines containing Clinton as well as headlines containing both Budget and Talk. In other words, the query would produce a list of stories about anything involving Clinton as well as stories about the Budget talks. To override the default precedence and evaluation order, parentheses could be used as follows:

(Clinton, Budget) & Talk

This search query would match headlines containing Clinton as well as Budget, provided that the search keyword Talk also matched each of those headlines. In other words, the query would produce a list of stories about Clinton talking as well as stories about the Budget talks. Compare these results with the results of the previous example.