Given the input from a free-form search field, I need to query the LDAP system and return user records. Our LDAP schema includes a "preferredName". Possible valid inputs include: "LastName", "GivenName", "PreferredName LastName", "LastName, PreferredName", "GivenName LastName", etc., including such variations as multiple-word last names (with or without hyphens).
Our current less-than-optimal process splits out the individual words, makes some assumptions about order (based on the presence or absence of a comma) and then makes several simple LDAP queries (e.g.: For "John Smith" it would submit the following queries:
(&(objectclass=person)(sn=*smith*)(preferredName=*john*))
(&(objectclass=person)(givenName=*john*)(sn=*smith*))
We then amalgamate and de-dupe the results of the multiple queries. A single-query solution would be much preferable, even if the query itself is complex. With my very basic understanding of LDAP query syntax, I could string together every possible permutation of the name words into one gigantic query, but I'm hoping that there's a more elegant solution.