5.5. Custom search operators
You can write your own search operator with Interchange's CodeDef. In interchange.cfg, or in the code directory tree, you can put:
CodeDef find_mirrored SearchOp
CodeDef find_mirrored Routine <<EOR
sub {
my ($self, $i, $pat) = @_;
$pat = reverse $pat;
return sub {
my $string = shift;
$string =~ /$pat/io;
};
}
EOR
Now you can do:
[loop search="
se=sretniap
sf=description
fi=products
st=db
co=yes
rf=*
op=find_mirrored
"]
[loop-code] [loop-param description]<br>
[/loop]
The passed parameters are:
- The search object ($self)
- The index into coordinated search array ($i)
- The pattern to match
- The name of the op (find_hammer in this case)
Must return a sub which receives the data to match and returns 1 if it matches. DOES NOT HONOR mv_negate UNLESS you tell it to.
See Vend::Search::create_text_query for an example of how to return a proper routine and look in search object for the associated params.