7.6. Changing the Width for Indexed Substring Searches

By default, for a search to be indexed, the search string must be at least three characters long, without counting any wildcard characters. For example, the string abc would be an indexed search while ab* would not be. Indexed searches are significantly faster than unindexed searches, so changing the minimum length of the search key is helpful to increase the number of indexed searches.
To improve search performance, particularly for sites with many wildcard searches, the search string length for indexed searches can be changed. Directory Server has three attributes which allow you to change the minimum number of characters required for an indexed search:
  • The nsSubStrBegin attribute sets the required number of characters for an indexed search for the beginning of a search string, before the wildcard.
    abc*
  • The nsSubStrMiddle attribute sets the required number of characters for an indexed search where a wildcard is used in the middle of a search string. For example:
    ab*z
  • The nsSubStrEnd attribute sets the required number of characters for an indexed search for the end of a search string, after the wildcard. For example:
    *xyz
The default substring search length for the string triplet (before, middle, and end) is 3, 3, and 3, meaning every search requires a minimum of three characters, in every wildcard position.
For any attribute index to have alternate string lengths, add the extensibleObject object class to the entry and then set the substring search lengths.
  1. Set the new key length for the specific attribute index. This requires adding the extensibleObject object class and then adding the nsSubStrBegin, nsSubStrEnd, or nsSubStrMiddle attributes as appropriate. For example:
    /usr/lib64/mozldap/ldapmodify -D "cn=directory manager" -w secret -p 389 -h server.example.com
    
    dn: attribute_name,cn=index,cn=database_name,cn=ldbm database,cn=plugins,cn=config
    objectClass: extensibleObject
    nsSubStrBegin: 2
    nsSubStrMiddle: 2
    nsSubStrEnd: 2
  2. Stop the server.
    service dirsrv stop
  3. Recreate the attribute index. If even one of the substring search width options is changed, then the entire index must be recreated.
    db2index -t attribute_name
  4. Start the server again.
    service dirsrv start