Skip to main content
December 11, 2012
Question

CFLDAP - How does the order of conditional statments in the filter attribute work?

  • December 11, 2012
  • 2 replies
  • 1638 views

Why do the following two filter attributes yield different results in a cfldap query?

1)     Filter="(|(sn=edmu*)(sn~=edmu))"

2)     Filter="(|(sn~=edmu)(sn=edmu*))"

From the results it looks like the second OR operand in the second filter, "(sn=edmu*)" is just being ignored. I don't see any documentation though on what order things are supposed to be in for these filter attributes.

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    December 12, 2012

    It is working as it should. Your results are simply telling you that sn~=edmu is picking out most of the surnames starting with the letters edmu. The operator, ~= (is approximately equal to), uses proprietary "sounds like" algorithms to do the filtering. As you can imagine, that is not an exact science.

    The logical (A or B) is traditionally evaluated from left to right. If A is true, B is ignored. The filter sn~=edmu is one of those fishing nets that will grab the tuna as well as the sardine. I would therefore place it at the rightmost end of the OR-chain.

    December 12, 2012

    Thanks for the responses.

    Adam - I did try the filter strings in Softerra LDAP Browser, but in it the order didn't matter, which is why I thought it was a Coldfusion thing.

    BKBK - I understand how the "sounds like" operator works, but I still don't see why the order should matter. Shouldn't the "|" operator be commutative just like any "OR" operator? Since placing the "sounds like" section on the right of the OR-chain seems to get the correct answer I will probably just do that, but I'm uneasy relying on something that doesn't seem to work according to the documentation. Also, in this case I'm not using the "sounds like" operator as a catchall, because I'm making a search page where I want the user to be able to enter a name with wildcard characters, in which case only the "=" condition would catch, not the "sounds like" condition.

    BKBK
    Community Expert
    Community Expert
    December 12, 2012

    stevenedmunds wrote:

    Shouldn't the "|" operator be commutative just like any "OR" operator?

    I see that as the crux of your argument. And, yes, the | operator, like any OR operator, is commutative. That is beside the point. The crucial point here is that computer processing moves traditionally from left to right.

    I'll give you an example similar to yours: (x > 5 OR x > 6). Commutativity indeed holds, because that statement is equivalent to  (x > 6 OR x > 5).

    Suppose the test variables x take on successive values 5.001, 5.002, ..., 5.999. Then the filter (x > 6 OR x > 5) will perform both the test x > 6 and the test x > 5 for each variable. That is because, going from left to right, the first test fails in each case. However, for all 999 values, the filter (x > 5 OR x > 6) will only perform the first test, and ignore the second.

    Inspiring
    December 11, 2012

    I can't say for absolute certain - it's been about ten years since I looked at <cfldap> with any thoroughness, but I suspect <cfldap> works like <cfquery> in that it just palms the query off to the directory service you're connecting to, rather than doing any processing of it itself.

    You might want to run the same queries with a different directory query tool / browser to see what that returns, by way of comparison, and go from there.

    --

    Adam