$rank = "FIRST((SELECT create_date FROM biblio.record_entry rbr WHERE rbr.id = m.source))";
} elsif ($sort_filter eq 'edit_date') {
$rank = "FIRST((SELECT edit_date FROM biblio.record_entry rbr WHERE rbr.id = m.source))";
+ } elsif ($sort_filter eq 'container_date' && @{$$flat_plan{container_list}}) {
+ # Just the first container for now
+ my $container_id = $self->QueryParser->quote_value(@{$$flat_plan{container_list}}[0]);
+ $rank = "FIRST((SELECT create_time FROM container.biblio_record_entry_bucket_item cbrebi WHERE cbrebi.target_biblio_record_entry = m.source AND cbrebi.bucket = " . $container_id . "))";
} else {
# default to rel ranking
$rank = $rel;
my $where = shift || '';
my $with = '';
my $uses_bre = 0;
+ my @container_list;
my @rank_list;
for my $node ( @{$self->query_nodes} ) {
my $rec_field = 'ci.target_biblio_record_entry';
if ($class eq 'bre') {
$class = 'biblio_record_entry';
+ push @container_list, $cid;
} elsif ($class eq 'acn') {
$class = 'call_number';
$rec_field = 'cn.record';
}
warn "flatten(): full filter where => $where\n" if $self->QueryParser->debug;
- return { rank_list => \@rank_list, from => $from, where => $where, with => $with, uses_bre => $uses_bre };
+ return { rank_list => \@rank_list, from => $from, where => $where, with => $with, uses_bre => $uses_bre, container_list => \@container_list };
}