[ic] How to do multiple searchs

Mike Heins mikeh@minivend.com
Fri, 5 Jan 2001 09:12:54 -0500


Quoting luiss@telenetsa.com (luiss@telenetsa.com):
> Hello,
> 
> We are using Interchange 4.6 with MySQL. We need to implement multiple 
> word search for articles, like Yahoo and other search engines.
> 
> For example:
> Search for: "Screw and Steel"
> Returns:
>         Steel Screw, 2" BSW
>         Steel Nut with Screw, 1.5" UNF
>         Brass Screw with Stainless Steel Washer, 0.5" BSWF
> 
> Any answer will be very appreciated.
> 

"Screw steel" as search terms will do that.

You could preprocess the search string to strip the AND (and possibly
an OR). I do this on the 4.7.x item page to allow searches like
category = Hammers AND price < 15

        [calc]
        $text_qualification = 'category = Hammers and price < 15';
        $CGI->{text_qualification} = <<EOF;
fi=products
st=db
co=1
EOF

        my @entries = split /\s+(and|or)\s+/i,  $text_qualification;
        my $or;
        for(@entries) {
                if(/^or$/i) {
                        $or = 1;
                        $CGI->{text_qualification} .= "os=1\n";
                        next;
                }   
                elsif(/^and$/i) {
                        $or = 0;
                        $CGI->{text_qualification} .= "os=0\n";
                        next;
                }   
                my ($f, $op, $s) = split /\s*([<=!>\^]+)\s*/, $_, 2;
                $op = "eq" if $op eq "==";
                $op = "rm" if $op eq "=";
                if($op eq '^') {
                        $op = 'rm';
                        $CGI->{text_qualification} .= "bs=1\nsu=1\n";
                }   
                else {
                        $CGI->{text_qualification} .= "bs=0\nsu=0\n";
                }   
                $CGI->{text_qualification} .= "se=$s\nsf=$f\nop=$op\n";
                if($op =~ /[<>]/ and $s =~ /^[\d.]+$/) {
                        $CGI->{text_qualification} .= "nu=1\n";
                }   
                else {
                        $CGI->{text_qualification} .= "nu=0\n";
                }   
        }   
        [/calc]

Now you can run:
<PRE>
        [cgi text_qualification]

        [loop search="[cgi text_qualification]"]
        [loop-code] [loop-description]
		[/loop]
</PRE>

-- 
Akopia, Inc., 131 Willow Lane, Floor 2, Oxford, OH  45056
phone +1.513.523.7621 fax 7501 <heins@akopia.com>

I have a cop friend who thinks he ought be able to give a new ticket;
"too dumb for conditions".