Search Filters

This chapter describes search filters and how searches work.

Search Filters

To narrow a search, you can specify search filters directly to the Smart Search field. If the search field contains an equal sign (=), Smart Search assumes the value is a search filter, and it uses this filter directly to perform the search.

Search filters use the value of an attribute to select the entries to be returned for Smart Search. For example, the following filter specifies a search for a common name equal to Babs Jensen:

Search Filter Syntax

The basic syntax of a search filter is:

For example:

In the example above, employeenumber is the attribute, >= is the operator, and 100 is the value.

You can also define filters that use combinations of different attributes.

Using Attributes in a Filter

When searching for an entry, you can specify attributes associated with that type of entry. For example, when you search for entries about people, you can use the cn attribute to search for people with specific common names.

Examples of attributes for entries about people might include:

For a listing of the attributes associated with entries, see Appendix A, "Entries and attribute fields". Note that you need to use the internal attribute names in search filters.

Using Operators in a Filter

An operator defines one of the following types of searches:

Search type Operator Description
Equality = Returns entries containing attributes which match the specified value. For example,

    cn=Bob Johnson

Substring =<string>*<string> Returns entries containing attributes containing the specified substring. For example,

    cn=Bob*

    cn=*Johnson

    cn=*John*

    cn=B*John

Greater than or equal to >= Returns entries containing attributes that are greater than or equal to the specified value. For example,

    employeenumber >= 100

Less than or equal to <= Returns entries containing attributes that are less than or equal to the specified value. For example,

    employeenumber <= 100

Presence =* Returns entries containing the specified attribute. For example,

    cn=*

    telephonenumber=*

    manager=*

Approximate ~= Returns entries containing the specified attribute that is approximately equal to the specified value. For example,

    cn~=surette

    l~=san fransico

For more information on these types of searches, see "How searching works."

Using Multiple Search Filters

You can combine different search filters by using boolean operators. Use the operators in prefix notation as follows:

where boolean_operator is any one of the boolean operators. For example:

In the example above, the combination of filters finds entries whose organizational unit is Marketing (ou=Marketing) and whose common name starts with Ray (cn=Ray*). The boolean operator for "And" (&) is used in prefix notation, which means that it precedes the search criteria.

In addition, you can nest boolean operators to form complex expressions, such as:

Boolean Operators

The boolean operators available for use with search filters are:

Operator Symbol Description
And & All specified filters must be true for the statement to be true. For example,

    (&(filter1)(filter2)(filter3)...)

Filter1, filter2, and filter3 must all be true for an entry to match.

Or | At least one specified filter must be true for the statement to be true. For example,

    (|(filter1)(filter2)(filter3)...)

If any of filter1, filter2, or filter3 match, the entry is returned.

Not ! The specified statement must not be true for the statement to be true. Note that only one filter is affected by the not operator. For example,

    (!(filter))

Any entry not matching the filter is returned.

Search Filter Examples

The following filter searches for entries containing the manager attribute. This is also known as a presence search:

 manager=*

The following filter searches for entries containing the common name of Ray Kultgen. This is also known as an equality search:

 cn=Ray Kultgen

The following filter returns any entries that do not contain the common name of Ray Kultgen:

 (!(cn=Ray Kultgen))

The following filter returns any entries that contain a description attribute with a substring of X.500:

 description=*X.500*

The following filter returns any entries whose organizational unit is Marketing and whose description field does not contain the substring X.500:

 (&(ou=Marketing)(!(description=*X.500*)))

The following filter returns any entries whose organizational unit is Marketing and who have Julie Fulmer or Cindy Zwaska as a manager:

 (&(ou=Marketing)(|(manager="cn=Julie Fulmer,ou=Marketing,o=Example Corp,c=US")
(manager="cn=Cindy Zwaska,ou=Marketing,o=Example Corp,c=US")))

The following filter returns any entries that do not represent a person:

 (!(objectclass=person))

The following filter returns any entries that do not represent a person and whose common name is approximately printer3b:

 (&(!(objectclass=person))(cn~=printer3b))

How Searching Works

Note:

The Directory Server interface is actually a collection of forms and CGI programs that operate independently from the Directory Server. This interface acts as an LDAP client to the Directory Server.

The following section explains what happens when you search the Directory Server:

  1. When you submit the form, you send a search filter to the Directory Server.
  2. The Directory Server examines the incoming request to verify that the information is in the local directory. If the information is not in the local directory and the Referral parameter is set for the server, the Directory Server returns the URL for the other Directory Server where the client can attempt to pursue the request.
  3. The Directory Server generates a list of entries from the directory tree. The Directory Server then examines each of the candidate entries to see if any entry matches the search criteria. Matching entries are returned to the Directory Server interface as each is found. This process continues until the Directory Server either has examined all applicable entries, or until it reaches one of the following limits:

Your administrator can configure these settings. For more detailed information on the searching algorithm, see the Directory Server Administrator's Guide.

The rest of this section explains how approximate searches work and how substring searches work.

How Approximate ("sounds like") Searches Work

The approximate search finds a word that "sounds like" the value you enter. In the Advanced Search interface, the approximate search corresponds to the "sounds like" search type.

For example, an entry may include the attribute value cn=Robert E Lee. An approximate search allows you to find this entry by specifying Robert Lee, Robert, or Lee. Similarly, a search for the location approximately equal to San Fransico (l~=San Fransico; note the misspelling) would return entries including locations exactly equal to San Francisco (l=San Francisco).

The Directory Server treats each value in an entry as a sequence of words and generates a phonetic code for each word. When you enter a value in an approximate search, the Directory Server also translates the value to a sequence of phonetic codes. An entry is considered to match a query if:

For example:

Name in the directory
(Phonetic code)
Your search string
(Phonetic code)
Match comments
Alice B Sarette
(ALS B SRT)
Alice Sarette
(ALS SRT)
Matches. Codes are specified in the correct order.
Alice Sarrette
(ALS SRT)
Matches. Codes are specified in the correct order despite the misspelling of Sarette.
Surette
(SRT)
Matches. The generated code exists in the original name despite the misspelling of Sarette.
Bertha Sarette
(BR0 SRT)
No match. The code BR0 does not exist in the original name.
Sarette, Alice
(SRT ALS)
No match. The codes are not specified in the correct order.

How Substring Searches Work

The substring search finds entries that contain the value you have entered. In the Advanced Search interface, the substring search corresponds to the "starts with", "contains", and "ends with" search types.

For example, searches of the form:

would match the common names containing strings such as:

and so forth. Similarly, the search for

would return all the entries in your directory with telephone numbers that contain 555.