[ic] Custom SearchOP

Tom Tucker tom at ttucker.com
Mon Sep 10 02:16:55 EDT 2007

Kevin Walsh wrote:
> 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 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. :-)
Thanks for the response.

I appreciate your restraint almost as much as I appreciate your 
knowledge. I have been using Interchange in production since 4.8.3 and 
your posts along with Ed's, Racke's and of course Mike's are gospel and 
have answered many, many questions. I genuflect before the Four Horsemen 
of eCommerce.

I made the changes as described (including the replacement of my 
favorite interim variable names) but to no effect. The SearchOp perl 
code works as expected outside of Interchange. A little more detail:

I am using "Mike Heins' modified foundation demo" from 2003. Added a 
column for model to the products table (VARCHAR 64). The abridged 
dataset I am searching through looks like this:

sku        model  prod_group  Category      
---------  -----  ----------  --------
MRD_CD5    65-73  Mustang     RADIO
MRD_CD6    65-73  Mustang     RADIO
M_5482A    65-66  Mustang     RADIO
MRD_103    65-66  Mustang     RADIO
MRD_105CD  65-66  Mustang     RADIO
MRD_1601   65-66  Mustang     RADIO
MRD_1501   65-66  Mustang     RADIO
MRD_12000  65-66  Mustang     RADIO
MRD_105    65-66  Mustang     RADIO
MRD_106    65-66  Mustang     RADIO
MRD_106CD  65-66  Mustang     RADIO
MRD_S06    65-73  Mustang     RADIO
MRD_101    65-66  Mustang     RADIO
MRD_107    65-66  Mustang     RADIO
MRD_107CD  65-66  Mustang     RADIO
MRD_108    65-66  Mustang     RADIO
M_5482C    65-73  Mustang     RADIO
MRD_S11    65-68  Mustang     RADIO
MRD_S12    65-73  Mustang     RADIO
M_5486A    65-67  Mustang     RADIO
MRD_CD     65-73  Mustang     RADIO

But the scan only returns the following skus:

When I look at the mysql log, I see that an "active != 1" is added to 
the query (select * from products  WHERE inactive != 1 AND prod_group = 
'Mustang' AND category = 'RADIO') and then 15 iterative selects over the 
13 skus returned getting the additional product, pricing and inventory data.

Noting in the VENDROOT error.log nor debug.log and nothing in the 
CATROOT error.log. Curious that a ::logDebug in the SearchOp shows 
nothing in the VENDROOT debug.log.

Sorry to be so verbose, but the function of the SearchOp is critical 
path the to the autoparts catalog I am building. And the scan is only 
for testing the search form using the custom SearchOp that I need which 
returns exactly the same results.

As always, the assistance is greatly appreciated.


More information about the interchange-users mailing list