Recipe 10.11 Indexing an Attribute

10.11.1 Problem

You want to index an attribute so that searches using that attribute are faster.

10.11.2 Solution

For Windows 2000 Active Directory you need to enable schema modifications before proceeding. See Recipe 10.2 for more information.

10.11.2.1 Using a graphical user interface
  1. Open the Active Directory Schema snap-in.

  2. In the left pane, click on the Attributes folder.

  3. In the right pane, double-click the attribute you want to index.

  4. Check the box beside Index this attribute in the Active Directory.

  5. Click OK.

10.11.2.2 Using a command-line interface

You can index an attribute by using the ldifde utility and an LDIF file that contains the following:

dn: cn=<AttrCommonName>,cn=schema,cn=configuration,<ForestRootDN> changetype: modify replace: searchFlags searchFlags: 1 -

If the LDIF file were named index_attribute.ldf, you would run the following command:

> ldifde -v -i -f index_attribute.ldf
10.11.2.3 Using VBScript
' This code indexes an attribute. ' ------ SCRIPT CONFIGURATION ------ ' Set to the common name (not LDAP display name) of the attribute strAttrName = "<AttrCommonName>"   ' e.g. rallencorp-LanguagesSpoken ' ------ END CONFIGURATION --------- set objRootDSE = GetObject("LDAP://RootDSE") set objAttr = GetObject("LDAP://cn=" & strAttrName & "," &                         objRootDSE.Get("schemaNamingContext")) objAttr.Put "searchFlags", 1 objAttr.SetInfo WScript.Echo "Indexed attribute: " & strAttrName

The CLI and VBScript solutions assume that searchFlags wasn't previously set and just blindly overwrites whatever value is present if one was. See Recipe 4.12 for a better solution that will enable the bit you want without overwriting any previous settings.

10.11.3 Discussion

To index an attribute, you need to enable the 1 bit (0001) in the searchFlags attribute for the attributeSchema object.

searchFlags is a bit flag attribute that is used to set various properties related to searching with the attribute. Table 10-5 contains the various bit flags that can be set with searchFlags. When setting searchFlags, you may often need to set a couple bits together. For example, all Ambiguous Name Resolution (ANR) attributes must also be indexed, which means searchFlags should be set to 5 (1 + 4).

You can find the attributes that are indexed in the schema by using the following search criteria:

Base
cn=Schema,cn=Configuration,<ForestRootDN>
Filter
(&(objectcategory=attributeSchema)(searchFlags:1.2.840.113556.1.4.803:=1))
Scope
 onelevel

Alternatively, to find attributes that aren't indexed, change the previous search filter to the following:

(&(objectcategory=attributeSchema)(!(searchFlags:1.2.840.113556.1.4.803:=1)))

10.11.4 See Also

Recipe 4.12 for modifying a bit-flag attribute, Recipe 10.7 for adding a new attribute, and MS KB 243311 (Setting an Attribute's searchFlags Property to Be Indexed for ANR)



Active Directory Cookbook
Active Directory Cookbook, 3rd Edition
ISBN: 0596521103
EAN: 2147483647
Year: 2006
Pages: 456

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net