Re: FW: Advanced search form

From: Date: Wed, 07 Dec 2005 14:41:20 +0000
Subject: Re: FW: Advanced search form
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-227049@lists.php.net to get a copy of this message
Here is some code that you can modify. It's design to convert a search string into a MySQL full text search string, not sure how different pgsql is. It adds * for word expansion where appropriate. It assume a space is the delimiter, but that's easy to change in the explode statement. Example: "this is a search" -XXX Test becomes +"this is a search" -XXX* +Test* Conversion function: function prepFullTextSearch($searchVal) { //Split words into list $word_List = explode(' ',stripslashes(trim($searchVal))); //Step through word list to get search phrases $i = 0; $isPhrase = false; foreach($word_List as $word) { $searchItems[$i] = trim(($isPhrase?$searchItems[$i].' '.$word:$word)); //Check for start of Phrase if(substr($searchItems[$i],0,1) == '"') { $isPhrase = true; } //If not building a phrase, append wildcard (*) to end of word if(!$isPhrase) { $searchItems[$i] .= '*'; $i++; } //Check for end of Phrase if(substr($searchItems[$i],-1) == '"') { $isPhrase = false; $i++; } } $searchVal = '+'.implode(' +',$searchItems); $searchVal = str_replace('+-','-',$searchVal); return $searchVal; } On Dec 7, 2005, at 8:18 AM, Michelle Konzack wrote:
Hello PHP-Gurus, I have already ask this on php-de and pgsql-pgp but unfortunatly gotten no answer. I have a search form and I like to add advanced search options like
        "this is a search" -XXX Test
which mean,
1)      "this is a search"      must be in this order
2)      -XXX                    Do not find XXX contents
3)      Test                    AND
Does anyone has a PHP/PGSQL code sniplet? Thanks Michelle --Linux-User #280138 with the Linux Counter, http://counter.li.org/ ##################### Debian GNU/Linux Consultant #####################
Michelle Konzack   Apt. 917                  ICQ #328449886
                   50, rue de Soultz         MSM LinuxMichi
0033/3/88452356    67100 Strasbourg/France   IRC #Debian (irc.icq.com)
--PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ----- End forwarded message ----- ******************************************************************
* Do not Cc: me, because I am on THIS list, if I write here      *
* Keine Cc: am mich, bin auf DIESER Liste wenn ich hier schreibe * ****************************************************************** Hello, Greetings Michelle --Linux-User #280138 with the Linux Counter, http://counter.li.org/ ##################### Debian GNU/Linux Consultant #####################
Michelle Konzack   Apt. 917                  ICQ #328449886
                   50, rue de Soultz         MSM LinuxMichi
0033/3/88452356    67100 Strasbourg/France   IRC #Debian (irc.icq.com)
--PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- Brent Baisley Systems Architect Landover Associates, Inc. Search & Advisory Services for Advanced Technology Environments p: 212.759.6400/800.759.0577

« previous php.general (#227049) next »