General rules for queries

The following rules apply to queries of all kinds:

Notes




Contains and Equals operators

Use the CONTAINS operator to search for any word or phrase within a particular property. If no operator is specified, the CONTAINS operator is assumed.

The following queries are equivalent:

@DocTitle "the red dog"
@DocTitle Contains "the red dog"

The following table illustrates the use of the CONTAINS operator in both long and short form.

Long form Short form
{prop name=DocTitle} Contains {phrase}the red dog{/phrase}{/prop} @DocTitle"the red dog"

A document whose title property value is "The story of the red dog" would satisfy both of these queries.

The EQUALS operator specifies that the value of the property must exactly match the word or phrase in the query. The long form of the operator is EQUALS. The short form is the equal sign (=).

For example:

@DocTitle = "the red dog"

Only a document whose Title property value is "the red dog" will satisfy this query. Indexing Service would not return a document with the title "The story of the red dog" because it contains words that are not in the query.

Notes

For more information about queries, see General rules for queries.




Boolean operators

You can use the Boolean operators AND, OR, and NOT in both content and property queries. The Boolean operator NEAR can be used only in content queries. You can use Boolean operators in both long-form and short-form queries. For more information on long-form and short-form queries, see Query language forms.

When you use the NEAR operator in a query, a document matches the query if the words are within 50 words of each other in the document. The closer together the words are, the higher the rank that is assigned to the document in the result set. If the words are more than 50 words apart, they are not considered near enough, and the document is assigned a rank of zero. The NEAR operator can be applied only to words or phrases.

In content queries, use the NOT operator only after the AND operator. Use the NOT operator only to exclude documents that match a previous content restriction. For property-value queries, the NOT operator can be used apart from the AND operator.

The following table explains the Boolean operators and their associated symbols.

Operator Long form Short form
AND AND &
OR OR |
NOT AND NOT &!
NEAR NEAR Near, ~

Boolean operators are available only in English.

The following table shows some examples of the use of Boolean operators:

To search for Long form Short form Result
Two terms in the same document red and dog red & dog Documents with both the words "red" and "dog"
Either of two terms in a document red or dog red | dog Documents with the words "red" or "dog"
One term without a second term red and not dog red & ! dog Documents with the word "red" but not "dog"
Documents not matching a property value not {prop name=size} = 100 ! @size = 100 Documents that are not 100 bytes
Two terms that are close together in the same document red near dog red ~ dog Documents with the word "red" near the word "dog"
Either of two terms and not two other terms if they are close together red or dog and not (black near cat) red | dog &! (black~cat) Documents with the word "red" or "dog" and not the words "black" and "cat" if they are within 50 words of each other

Note

Order of precedence rules

Boolean operators are evaluated in the following order:

  1. NOT
  2. AND or NEAR
  3. OR

After precedence rules are applied, operators are processed left to right. You can use parentheses (( )) to override the normal precedence. For example, the first three queries are equivalent, but the fourth is not:

a AND b OR c

c OR a AND b

c OR (a AND b)

(c OR a) AND b

In the fourth query, the OR operator is evaluated first because the expression is enclosed in parentheses.




Free-text and phrase queries

Free-text queries

With free-text queries, you can enter a group of words or a complete sentence. Indexing Service finds pages that best match the words and phrases in the free-text query. It does this by finding pages that match the meaning, rather than the exact wording, of the query. Indexing Service ignores Boolean, proximity, and wildcard operators.

You can use free-text queries to search both contents and property values. If you submit only the query text without specifying the type of query or the property, Indexing Service uses the free-text query and the Contents property by default.

The following queries return documents that contain text that most nearly matches the phrase, "How do I print in Microsoft Excel?"

Long form Short form
{freetext} {prop name=contents} How do I print in Microsoft Excel? How do I print in Microsoft Excel?

Or

$contents How do I print in Microsoft Excel

Phrase queries

To search for a phrase, either enclose it in quotation marks or precede it with the {phrase} tag. Words in a phrase query must appear in document in the order entered, with no intervening words.

The following expressions are equivalent:

{phrase} big red truck {/phrase}
"big red truck"

When the phrase tag is used, the sequence and position of the words are significant in determining whether a document matches the query. The {phrase} and {freetext} tags are mutually exclusive and cannot be embedded or nested. Phrase queries can be used to search both contents and property values.

The following table provides examples of the long and short forms of the phrase tags.

Long form Short form
{phrase} big red truck {/phrase}  "big red truck"   

Note




Sample queries

The following provides examples of queries for various purposes.

To search for Long form Short form Result
A specific value {prop name=DocAuthor}= Dalal Ketan{/prop} @DocAuthor = Dalal Ketan Documents authored by Dalal Ketan
Values beginning with a prefix {prop name=DocAuthor} {regex}George*{/regex}{/prop} #DocAuthor George* Documents whose Author property begins with "George"
Documents with any of a set of extensions {prop name=filename} {regex}*.|(exe|,dll|,sys|){/regex}{/prop} #filename *.|(exe|,dll|,sys|) Files with .exe, .dll, or .sys extensions
Documents modified after a certain date and time {prop name=write}>96/2/14 13:00:00{/prop} @write > 96/2/14 13:00:00 Documents modified after February 14, 1996, at 13:00 Coordinated Universal Time
Documents modified after a relative date {prop name=write}> -1d2h{/prop} @write > -1d2h Documents modified within the last 26 hours
Vectors matching a vector {prop name=vectorprop}={ 10, 15, 20 }{/prop} @vectorprop={ 10, 15, 20 } ActiveX documents with a vectorprop value of { 10, 15, 20 }
Vectors where each value matches a criterion {prop name=vectorprop}>^a 15{/prop} @vectorprop >^a 15 ActiveX documents with a vectorprop value where all values in the vector are greater than 15
Vectors where at least one value matches a criterion {prop name=vectorprop}=^s 15{/prop} @vectorprop =^s 15 ActiveX documents with a vectorprop value where at least one value is 15
general information  *  disclaimer  *  nc.gov
general information    disclaimer    nc.gov