[ic] Did you know about SearchOp? (part of a series)
Mike Heins
mike at perusion.com
Wed Apr 13 13:15:22 EDT 2005
Interchange has a number of intrinsic search operations, including
the standard eq, lt, <=, =~, !~, etc. and also ones based on Text::Query
for Altavista-style query language. But did you know you can
define your own?
You just define a SearchOp code definition which returns a
subroutine to use to map against the string to search. (This
only applies to coordinated search.)
Here is one which checks to see if the search specification,
when reversed, matches the record.
CodeDef reverse SearchOp
CodeDef reverse Routine <<EOR
sub {
my ($sobj, $idx, $spec) = @_;
$spec = reverse($spec);
$spec = qr($spec)i; # could check for $sobj->{mv_case}[$idx]
# but we will just be case-insensitive
return sub {
my $str = shift; # the string to be searched
return $str =~ $spec; # does it match reversed spec?
};
}
EOR
Since there are things in the standard/foundation catalogs which
have "tool" in them, we will run our search for "loot":
[loop
search="
co=yes
sf=description
op=reverse
se=loot
rf=sku,description
"]
[loop-code] -- [loop-param description]<br>
[/loop]
Returns:
os28069 -- Flat Top Toolbox
os28070 -- Electricians Tool Belt
os28077 -- Carpenter's Tool Belt
And:
[loop
search="
co=yes
sf=description
op=reverse
se=tleb
rf=sku,description
"]
[loop-code] -- [loop-param description]<br>
[/loop]
Returns:
os28070 -- Electricians Tool Belt
os28077 -- Carpenter's Tool Belt
SearchOp works either global (in interchange.cfg) or local (in catalog.cfg),
with the permissions for using code the same as for UserTag (i.e. only
Safe code in catalog.cfg unless AllowGlobal is set).
--
Mike Heins
Perusion -- Expert Interchange Consulting http://www.perusion.com/
phone +1.765.647.1295 tollfree 800-949-1889 <mike at perusion.com>
There's nothing sweeter than life nor more precious than time.
-- Barney
More information about the interchange-users
mailing list