Forum for discussing general topics related to Couch.
3 posts Page 1 of 1
@KK,

Please refer to following post: viewtopic.php?f=2&t=9789.

I just wonder is this code only fit for 3 words? I tried to change the following part:
Code: Select all
foreach( $searchwords as $word ){
            if( mb_strlen($word, 'UTF-8')>2 ){
                $longwords[] = $word;
            }
            else{
                if( mb_strlen($word, 'UTF-8')==2 ){
                    if(!in_array($val,array('and','the','him','her')))
                    $shortwords[] = $word;
                }
            }
        }


I changed 3 to 2. Strange things happened, it can now search 2 words but failed to search 3 words.

I don't need you to go further on this source code. I just need to confirm. Thank you.
nsy wrote: Strange things happened, it can now search 2 words but failed to search 3 words.

Maybe try it like this:
Code: Select all
foreach( $searchwords as $word ){
            if( mb_strlen($word, 'UTF-8')>3 ){
                $longwords[] = $word;
            }
            else{
                if( mb_strlen($word, 'UTF-8')>=2 && mb_strlen($word, 'UTF-8')<=3 ){
                    if(!in_array($val,array('and','the','him','her')))
                    $shortwords[] = $word;
                }
            }
        }

Depending on your use case, you might also want to add some 2-letter words to the list of excluded short words.
@tim,

Thanks, dude. It works perfectly, appreciate your help. :D :D :D
3 posts Page 1 of 1