)
JOIN
if ($sort_filter eq 'poprel') {
- $rank = $rel . ' * (1 + AVG(COALESCE(rbs.value::NUMERIC,0.0)) / 5.0)';
+ $rank = '(' . $rel . ') * (1.0 + AVG(COALESCE(rbs.value::NUMERIC,0.0)) / 5.0)';
} else {
$rank = 'AVG(COALESCE(rbs.value::NUMERIC,0.0))';
}
+ } else { # no numeric badge_orgs filter arguments ... bad input, assume all orgs
+ $pop_join = 'LEFT JOIN rating.record_badge_score rbs ON ( m.source = rbs.record )';
+ if ($sort_filter eq 'poprel') {
+ $rank = '(' . $rel . ') * (1.0 + AVG(COALESCE(rbs.value::NUMERIC,0.0)) / 5.0)';
+ } else {
+ $rank = 'AVG(COALESCE(rbs.value::NUMERIC,0.0))';
+ }
+ }
+ } else { # no badge_orgs filter supplied, assume all orgs
+ $pop_join = 'LEFT JOIN rating.record_badge_score rbs ON ( m.source = rbs.record )';
+ if ($sort_filter eq 'poprel') {
+ $rank = '(' . $rel . ') * (1.0 + AVG(COALESCE(rbs.value::NUMERIC,0.0)) / 5.0)';
} else {
- $rank = $rel;
+ $rank = 'AVG(COALESCE(rbs.value::NUMERIC,0.0))';
}
- } else {
- $rank = $rel;
}
} else {
# default to rel ranking
cachable => 1,
);
+my $top_org;
+
sub query_parser_fts_wrapper {
my $self = shift;
my $client = shift;
die "No search arguments were passed to ".$self->api_name;
}
+ $top_org ||= actor::org_unit->search( { parent_ou => undef } )->next;
+
$log->debug("Constructing QueryParser query from staged search hash ...", DEBUG);
my $base_query = '';
for my $sclass ( keys %{$args{searches}} ) {
my $borgs = undef;
+ my $site = undef;
+
my ($site_filter) = $base_plan->parse_tree->find_filter('site');
if ($site_filter && @{$site_filter->args}) {
- my $cstore = OpenSRF::AppSession->create( 'open-ils.cstore' );
- my $site;
- $site = $cstore->request(
- 'open-ils.cstore.direct.actor.org_unit.search',
- { parent_ou => undef }
- )->gather(1) if ($site_filter->args->[0] eq '-');
-
- $site = $cstore->request(
- 'open-ils.cstore.direct.actor.org_unit.search',
- { shortname => $site_filter->args->[0] }
- )->gather(1) unless ($site);
-
- $site = $cstore->request(
- 'open-ils.cstore.direct.actor.org_unit.retrieve',
- $args{org_unit}
- )->gather(1) if (!$site and $args{org_unit});
-
- if ($site) {
- my ($depth_filter) = $base_plan->parse_tree->find_filter('depth');
- if ($depth_filter && $depth_filter->args->[0] =~ /^\d+$/) {
- $borgs = $cstore->request(
- 'open-ils.cstore.json_query.atomic',
- { from => [ 'actor.org_unit_descendants', $site->id, $depth_filter->args->[0] ] }
- )->gather(1);
- } else {
- $borgs = $cstore->request(
- 'open-ils.cstore.json_query.atomic',
- { from => [ 'actor.org_unit_descendants', $site->id ] }
- )->gather(1);
- }
+ $site = $top_org if ($site_filter->args->[0] eq '-');
+ $site = $top_org if ($site_filter->args->[0] eq $top_org->shortname);
+ $site = actor::org_unit->search( { shortname => $site_filter->args->[0] })->next unless ($site);
+
+ } elsif ($args{org_unit}) {
+ $site = $top_org if ($args{org_unit} eq '-');
+ $site = $top_org if ($args{org_unit} eq $top_org->shortname);
+ $site = actor::org_unit->search( { shortname => $args{org_unit} })->next unless ($site);
+ }
+
+ if ($site && $site->id <> $top_org->id) {
+ my ($depth_filter) = $base_plan->parse_tree->find_filter('depth');
+ my $depth = $depth_filter->args->[0] if ($depth_filter && $depth_filter->args->[0] =~ /^\d+$/);
+ $depth = $args{depth} if (!defined($depth) && defined($args{depth}) && $args{depth} =~ /^\d+$/);
+
+ if (defined $depth and $depth > 0) { # Not scoped to the top of the tree
+ $borgs = OpenSRF::AppSession->create( 'open-ils.cstore' )->request(
+ 'open-ils.cstore.json_query.atomic',
+ { from => [ 'actor.org_unit_descendants', $site->id, $depth ] }
+ )->gather(1);
+ } else {
+ $borgs = OpenSRF::AppSession->create( 'open-ils.cstore' )->request(
+ 'open-ils.cstore.json_query.atomic',
+ { from => [ 'actor.org_unit_descendants', $site->id ] }
+ )->gather(1);
+ }
- if (ref $borgs && @$borgs) {
- $borgs = join(',', map { $_->{'actor.org_unit_descendants'} } @$borgs);
- } else {
- $borgs = undef;
- }
+ if (ref $borgs && @$borgs) {
+ $borgs = join(',', map { $_->{'actor.org_unit_descendants'} } @$borgs);
+ } else {
+ $borgs = undef;
}
}