11 Replies Latest reply on Dec 13, 2012 9:35 AM by BKBK

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

    stevenedmunds

      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.

       

        • 1. Re: CFLDAP - How does the order of conditional statments in the filter attribute work?
          Adam Cameron. Level 5

          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

          • 2. Re: CFLDAP - How does the order of conditional statments in the filter attribute work?
            BKBK Adobe Community Professional & MVP

            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.

            • 3. Re: CFLDAP - How does the order of conditional statments in the filter attribute work?
              stevenedmunds Level 1

              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.

              • 4. Re: CFLDAP - How does the order of conditional statments in the filter attribute work?
                BKBK Adobe Community Professional & MVP

                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.

                • 5. Re: CFLDAP - How does the order of conditional statments in the filter attribute work?
                  stevenedmunds Level 1

                  BKBK - I think you're misunderstanding  my question. I understand that if the first part of an OR statement is true then subsequent parts are not evaluated because they are irrelevant to larger conditional statement. What I'm seeing is the second part of the OR statement being ignored when the first part is FALSE. I should've included an example of the output of the ldap queries.

                   

                  For

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

                  the result includes "edmunds".

                   

                  For

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

                  the result does not include "edmunds"

                   

                  Do you see what I'm talking about now?

                   

                   


                  • 6. Re: CFLDAP - How does the order of conditional statments in the filter attribute work?
                    stevenedmunds Level 1

                    After trying some different things it looks like whenever the "sounds like" condition is on the left of the OR statement nothing after it gets evaluated, even if it is False. Perhaps this is a bug. I'm only using Coldfusion 8 though so maybe this was fixed at some point.

                    • 7. Re: CFLDAP - How does the order of conditional statments in the filter attribute work?
                      BKBK Adobe Community Professional & MVP

                      stevenedmunds wrote:

                       

                      ... What I'm seeing is the second part of the OR statement being ignored when the first part is FALSE.

                      If only you had said that! I can of course see the problem now.

                      • 8. Re: CFLDAP - How does the order of conditional statments in the filter attribute work?
                        BKBK Adobe Community Professional & MVP

                        stevenedmunds wrote:

                         

                        After trying some different things it looks like whenever the "sounds like" condition is on the left of the OR statement nothing after it gets evaluated, even if it is False. Perhaps this is a bug. I'm only using Coldfusion 8 though so maybe this was fixed at some point.

                        You are right in assuming it to be a bug. I am also going to have a look in the bug reports.

                        • 9. Re: CFLDAP - How does the order of conditional statments in the filter attribute work?
                          Adam Cameron. Level 5

                          The logical (A or B) is traditionally evaluated from left to right. If A is true, B is ignored.

                           

                          Hold yer horses here.  OR is short-circuited in a boolean expression, yes.  But in the context we are talking it's not a boolean expression, it's a search filter. Those are two very different things.

                           

                          Consider this more obvious/familiar example:

                           

                          SELECT *

                          FROM table

                          WHERE name = 'Steven'

                          OR name = 'BKBK'

                           

                          Clearly (I hope), you are not suggesting the DB finds matches for "Steven" and then goes "that's 'true', so I'll ignore the rest of the statement, so we don't need to worry about any BKBKs". No, the DB will return all matches for Steven and BKBK.

                           

                          A <cfldap> call is - for all intents and purposes - equivalent to a <cfquery> call (different protocol, different query language, but other than that, it's all just fetching data from a database), and the filter is the equivalent of the WHERE clause in an SQL statement.

                           

                          The whole thing will (or, hey should ~) be considered when doing the query.

                           

                           

                          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.

                           

                          Sounds reasonable, but I don't know that this is a contributing factor here.  I like yer wording though ;-)

                           

                          --

                          Adam

                          • 10. Re: CFLDAP - How does the order of conditional statments in the filter attribute work?
                            Adam Cameron. Level 5

                            For

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

                            the result includes "edmunds".

                             

                            For

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

                            the result does not include "edmunds"

                             

                             

                            After trying some different things it looks like whenever the "sounds like" condition is on the left of the OR statement nothing after it gets evaluated, even if it is False. Perhaps this is a bug. I'm only using Coldfusion 8 though so maybe this was fixed at some point.

                             

                            But when using Softerra it all works either way?

                             

                            Weird.

                             

                            Is there any scope on your directory server to monitor what queries are coming through (like using a profiler on an SQL database)?

                             

                            I'm void of ideas as to what's going on, sorry.  I really just expected CF to be passing the thing through to the directory, but it does indeed seem to be monkeying with things.

                             

                            --

                            Adam

                            • 11. Re: CFLDAP - How does the order of conditional statments in the filter attribute work?
                              BKBK Adobe Community Professional & MVP

                              Adam Cameron. wrote:

                               

                              The logical (A or B) is traditionally evaluated from left to right. If A is true, B is ignored.

                               

                              Hold yer horses here.  OR is short-circuited in a boolean expression, yes.  But in the context we are talking it's not a boolean expression, it's a search filter. Those are two very different things.

                               

                              Consider this more obvious/familiar example:

                               

                              SELECT *

                              FROM table

                              WHERE name = 'Steven'

                              OR name = 'BKBK'

                               

                              Clearly (I hope), you are not suggesting the DB finds matches for "Steven" and then goes "that's 'true', so I'll ignore the rest of the statement, so we don't need to worry about any BKBKs". No, the DB will return all matches for Steven and BKBK.

                              I have not only held my horses, I have tethered them. Your example clarifies something I didn't quite understand in StevenEdmunds' reaction. In particular, the business about commutativity now makes sense.

                               

                              To borrow your example, my antenna was tuned to something like

                               

                              SELECT *

                              FROM table

                              WHERE name LIKE 'Steve%'

                              OR name = 'Steven'

                               

                              Even so, my bad for implying that all filters like these apply short-circuiting. Thanks for the correction.