3 Replies Latest reply on May 11, 2013 8:58 AM by deathrobot

    Trouble with custom function

    deathrobot

      Title

      Trouble with custom function

      Post

           I currently have a custom function that takes a field and make all the iterations of its contents minus 1 character each time in order to be able to do instant portal filtering:

           ORIGINAL FIELD IS
           "Some Name Here"

           FUNCTION MAKES
           "Some Name Here
           Some Name Her
           Some Name He
           Some Name H
           Some Name
           Some Nam
           Some Na
           Some N
           Some
           Som
           So
           S"

           The problem with this is that if I try to search on the second word, it doesn't work. So I'm trying to rewrite the function so that it also adds the iterations for each word, like so:

           FUNCTION MAKES
           "Some Name Here
           Some Name Her
           Some Name He
           Some Name H
           Some Name
           Some Nam
           Some Na
           Some N
           Some
           Som
           So
           S
           Name
           Nam
           Na
           N
           Here
           Her
           He
           H"

           The original (working) function is:

           __________

            

           Case(
            
           not IsEmpty(Field);
            
           Field & "¶" & MultiKey(Left(Field; Length(Field) - 1));
            
           )
           __________

            

            

           The new (non-working) function is:

            

           __________
            
           Case(
            
           not IsEmpty(Field);
            
           Set Variable [ $numberOfWords; WordCount ( Field ) + 1 ]
            
           Loop
                Exit Loop If [$numberOfWords = 0]
                Set Variable [$numberOfWords; $numberOfWords -1 ]
                MiddleWords ( Field ; $numberOfWords ; 1 ) & "¶" & MultiKeyPerWord(Left(MiddleWords ( Field ; $numberOfWords ; 1 ); Length(Field) - 1))
           End Loop
           ;
            
           )
           __________
            
           I'm not sure on the correct way to define a variable in a function, but this is definitely not it. This also just deals with the individual words, so I would lose searching on the phrase. And I know there are some other problems with this concept, but can't quite get my head around it.  What am I doing wrong here?
            
           Thanks!
           Michael