You are here: Re: [PHP] FW: Advanced search form « PHP « IT news, forums, messages
Re: [PHP] FW: Advanced search form

Posted by Brent Baisley on 12/07/05 16:41

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация