[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
Re: [mv] Efficient [perl] Results page
****** message to minivend-users from Mike Heins <mikeh@minivend.com> ******
Quoting Handytman@aol.com (Handytman@aol.com):
>
> I have seen statements on this list, indicating that the least CPU-intensive
> way to display search results is to write the page in perl.
>
> This is of interest to me, as my results page must check a database and
> display items one way if condition X is true, and differently otherwise.
> Also, seemingly the server would rather interpolate the [item-fields] once
> per item, and then perl could write the page to display that data two or
> three times per item, if need be.
>
> What I've got so far is a results page which has all the [search-list]
> display stuff in perl tags. (Actually, I use [calc] tags.) This results in
> one perl call per item. Since the page is called to display eight items per
> page, that means eight perl calls per page.
> It occurs to me that one perl call per page would be better. I'm asking:
>
>
> How can one perl call display all the items on the results page, eliminating
> the need for [search-list][/search-list] tags?
I do believe I have shown this one many, many, times on the list.
I don't think I have documented too much of this, though; it is one we
will get to soon.
In MV4, it is:
[perl tables="products pricing"]
# The empty key is the default search passed in by URL or form
my $s = $Search->{''};
return "No search passed." if ! $s;
# mv_results is the result array
my $ary = $s->{mv_results};
return "Bad search object." if ! $ary;
return "No match." unless @$ary;
# If you used mv_return_fields / rf, the array will contain all
# of the fields
# ra=yes/rf=sku,title,price will look something like:
# [
# [ '00-0011', 'Mona Lisa', 50000000 ],
# [ '00-0011a', 'Gilded Frame', 1000 ],
# [ 'etc.', 'etc.', 0 ],
#
# ]
my $out = '';
foreach $row (@$ary) {
my ($sku, $title, $price) = @$row;
$out .= &do_your_stuff();
# Get a field you didn't return in the search
$extra = tag_data('products', 'color', $sku);
if($extra) {
$out .= &do_some_more();
}
}
return $out;
[/perl]
You can use [mvasp] with the same stuff, and you can pass in db references
with [perl tables="products pricing etc"] if you want to use tag_data() or
other tags that use database references.
You can always use the old MV3 approach, which is somewhat easier if you
are not strong on references:
[perl]
$string = <<EOF;
[search-list][item-code]|[item-data sometable somecol]
[/search-list]
EOF
@items = split /\n/, $string;
for(@items) {
($code, $field) = split /\|/, $_;
etc();
etc();
}
[/perl]
--
Akopia, Inc., 131 Willow Lane, Floor 2, Oxford, OH 45056
phone +1.513.523.8220 fax 7501 <heins@akopia.com>
Research is what I'm doing when I don't know what I'm doing.
-- Wernher Von Braun
-
To unsubscribe from the list, DO NOT REPLY to this message. Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list