[ic] Custom SearchOP
Kevin Walsh
kevin at cursor.biz
Mon Sep 10 00:21:22 EDT 2007
Tom Tucker <tom at ttucker.com> wrote:
> Mac OS X 10.4.10
> Interchange 5.4.0 (Tried with both Low and High Traffic settings)
> Perl 5.8.6 threaded (PERL_SIGNALS="unsafe" set in the ENV)
> MySQL 5.0.27-standard
>
> Never had a problem starting daemon and no other odd behavior that I
> have seen.
>
> I have implemented the following Custom SearchOp according to the
> instructions in the list and docs (I think ):
>
> I have a column in my database, 'model', that can contain a comma
> separated list of model years for which a particular part is applicable.
> For example:
> 55
> 70-75
> 63,68-73
>
> I need to be able to search on three fields, prod_group, model and category.
>
> When I use a search of the form:
> http://www.mydomain.com/scan/co=yes/fi=products/sf=prod_group/se=Mustang/op=eq/sf=model/se=68/op=modelyr/sf=category/se=RADIO/op=eq/tf=category,description
>
> I get some products returned, but not the list I would expect. I added
> the ::logDebug statement but don't get any output in the debug.log file.
> In fact when I deliberately put in an error in SearchOp perl routine, I
> don't even get an error message on catalog restart.
>
> ## Custom search op for model years. Takes a comma
> ## separated list of individual 2 digit model years
> ## or a range, ex: 55,63,65-68,70-73 and will
> ## determine if the search expression matches
> ## specifically or falls within the range.
> CodeDef modelyr SearchOp
> CodeDef modelyr Routine <<EOR
> sub modelyr {
> my ($self, $i, $pat) = @_;
> ::logDebug("modelyr: testing $self against $pat");
>
> return sub {
> my $this = shift;
> my @pat = split(/,/, $pat);
> #print " subtesting $this ";
> foreach my $that ( @pat ) {
> # Check to see if matches in a range of model years
> if ( $that =~ /-/) {
> my ($strt, $end) = split(/-/, $that);
> #print "against $strt thru $end\n";
> return 1 if ($this >= $strt && $this <= $end);
> }
> # Check to see if matches a single model year
> #print "against $that\n";
> return $this == $that;
> }
> };
> }
> EOR
>
> Any assistance greatly appreciated.
>
The only thing I can see from my quick glance at your code is the
line that looks like this:
return $this == $that;
That would appear to be returning true or false, for the first
non-range value, and thereby ignoring the rest of the list.
You could try changing the end of your code to look a little more
like this:
# Check to see if matches a single model year
return 1 if $this == $that;
}
return 0;
};
}
EOR
You shouldn't really use $this as a variable name. Although the name
isn't reserved, it is confusing when used outside of its usual context.
I'm trying my best not to make any anti-Mac or anti-BSD comments. :-)
--
_/ _/ _/_/_/_/ _/ _/ _/_/_/ _/ _/
_/_/_/ _/_/ _/ _/ _/ _/_/ _/ K e v i n W a l s h
_/ _/ _/ _/ _/ _/ _/ _/_/ kevin at cursor.biz
_/ _/ _/_/_/_/ _/ _/_/_/ _/ _/
More information about the interchange-users
mailing list