2 Replies Latest reply on Aug 1, 2009 7:28 PM by kevnug

    Help with AND/OR Search


      Hi all,


      I'm setting up an 'Advanced Search' feature using a filter function and need some help with the logic - seem to be suffering a brain fade...


      There's a search form with (let's say) 4 different options:  Name, Description, Price, Features.


      I want the user to be able to fill in all or none of the fields and return the matching results.


      I can do an OR function like this:


      if(Name.match(regx1) || Description.match(regx2) || Price .match(regx3) )|| Features .match(regx4){

           return true;


           return false;



      I know I could change the "||" to "&&" - but I need to do this only if there's something to search...


      The only way I can think of doing this at the moment is to write a bunch of 'if statements' with all permutations - eg:


      if(Name && !Description && !Price && !Features){

           //match Name only

      }else if(Name && Description && !Price && !Features){

           //match Name & Description

      }else... you get the idea



      Thanks for your help!




        • 1. Re: Help with AND/OR Search
          Madhav Subedi Level 4

          it woud depend entirely on your application requirement; whether one field match is enough ( the second case ) or needs all fields match.


          i faced a similar case, in which, i had to AND ( as in the first case ) all the criteria whose search term is not empty.


          var criteria:Boolean = true;


          if( name not empty )

               criteria &= if(name.match)

          if ( price not empty )

               criteria &= if(price.match)






          hope it helps.

          • 2. Re: Help with AND/OR Search
            kevnug Level 1

            hey Madhav,


            Thanks for the pointer.  I haven't used a bitwise AND Assignment before...


            When I write some code like below I get a compile error saying "Implicit conversion of type Boolean to an unrelated type Integer"


            From what I understand, 'criteria' should remain true only if the comparator is true.  But why do I get a compile error?


            Do you know what I'm doing wrong?



            var criteria:Boolean = true;

            var nameMatch:Boolean = false;




                      nameMatch = true;





                crieteria &= nameMatch;  // compile error here




            thanks for your help!