Theatre Australia

your portal for australian theatre

DGSSearch

Tue, 10 Feb 2004, 05:54 am
Walter Plinge6 posts in thread
Hey guys,

I did a Google search for the term "dgssearch modification" and your site was listed third. I'm using dgssearch as the basis of a site I'm building and noticed that it doesn't support boolean searches (e.g. nissan and maxima). You guys appear to have modified the base code to support this kind of search.

I might be out of line in asking, but what the hell. Would you mind sharing the modified search code? I'm fairly new to php coding and this would save me a bunch of time.

Thanks for the consideration.

Mark Russell
www.findingautos.com

Re: DGSFound

Tue, 10 Feb 2004, 12:57 pm
Hi Mark

Mark Russell wrote:
> I might be out of line in asking, but what the hell. Would
> you mind sharing the modified search code? I'm fairly new to
> php coding and this would save me a bunch of time.

It's actually not boolean, but it does allow searching on keywords rather than just phrases. The key being to split the search string into individual tokens and then build the query. It's very inefficient!

This was something I hacked together from a search routine in Phorum. Licensing details here: http://phorum.org/license.txt

The following works fine for PostgreSQL but I don't see any reason why it shouldn't also work for any SQL db. It needs to be dropped into db.php in the libs/search/ directory. There should be enough context for you to pick up where it belongs.

$statement .= ' WHERE ';
if (strlen($tableAssoc) > 0)
$statement .= $tableAssoc . ' AND ';
$statement .=' (';

$search = $q;
$search=stripslashes($search);
$search=eregi_replace("[[:space:]]+", " ", $search);
$search=trim($search);
$searchtext = htmlentities($search);
$q=$searchtext;
if($search!=""){
$params = split(" ", $search);
$InQuotedString = 0;
$tokNum = 0;
$tokens = array();
$tokens[$tokNum] = "";
for($i=0; $i if(!IsSet($tokens[$tokNum])){
$tokens[$tokNum] = "";
}
$param = $params[$i];
if(ereg("^\"", $param) || ereg("^[+-]\"", $param)){
$InQuotedString = 1;
}
if($InQuotedString == 1){
$tokens[$tokNum] .= ereg_replace("\"", "", $param) . " ";
}
else{
$tokens[$tokNum++] = $param;
}

if(ereg("\"$", $param)){
$InQuotedString = 0;
$tokens[$tokNum] = chop($tokens[$tokNum]);
echo "\n\n";
$tokNum++;
}
}
}

$statement .= "(";
for($j=0; $j $x=0;
reset($sfields);
while (list(, $entry) = each($sfields)) {
$x++;
$token = ereg_replace(" $", "", $tokens[$j]);
if(ereg("^\\+", $token)){
$token = ereg_replace("^\\+", "", $token);
$statement .= "$entry ~* '$token'";
} elseif(ereg("^\\-", $token)) {
$token = ereg_replace("^\\-", "", $token);
$statement .= "$entry NOT ~* '$token'";
}else{
$statement .= "$entry ~* '$token'";
}
if ($x < count($sfields))
$statement .= ' OR ';
}
if($j $statement .= ") AND (";
}
$statement .= ")";

[%sig%]

Thread (6 posts)

DGSSearchWalter Plinge10 Feb 2004
← Back to Tech Talk