'See perldoc ' . __PACKAGE__ . ' for more detail.',
type => 'object'
},
- {desc => 'limit (optional)', type => 'number'},
- {desc => 'offset (optional)', type => 'number'}
+ {desc => 'timeout (optional)', type => 'number'}
],
return => {
desc => 'Results object like: { "count": $i, "ids": [...] }',
);
}
-=head3 open-ils.search.biblio.marc (arghash, limit, offset)
+=head3 open-ils.search.biblio.marc (arghash, timeout)
As elsewhere the arghash is the required argument, and must be a hashref. The keys are:
=cut
# FIXME: that example above isn't actually tested.
+# FIXME: sort and limit added. item_type not tested yet.
# TODO: docache option?
sub marc_search {
- my( $self, $conn, $args, $limit, $offset, $timeout ) = @_;
+ my( $self, $conn, $args, $timeout ) = @_;
my $method = 'open-ils.storage.biblio.full_rec.multi_search';
$method .= ".staff" if $self->api_name =~ /staff/;
$method .= ".atomic";
- $limit ||= 10; # FIXME: what about $args->{limit} ?
- $offset ||= 0; # FIXME: what about $args->{offset} ?
+ my $limit = $args->{limit} || 10;
+ my $offset = $args->{offset} || 0;
- # allow caller to pass in a call timeout since MARC searches
- # can take longer than the default 60-second timeout.
- # Default to 2 mins. Arbitrarily cap at 5 mins.
- $timeout = 120 if !$timeout or $timeout > 300;
+ # allow caller to pass in a call timeout since MARC searches
+ # can take longer than the default 60-second timeout.
+ # Default to 2 mins. Arbitrarily cap at 5 mins.
+ $timeout = 120 if !$timeout or $timeout > 300;
my @search;
push( @search, ($_ => $$args{$_}) ) for (sort keys %$args);
my $recs = search_cache($ckey, $offset, $limit);
if(!$recs) {
+ my $ses = OpenSRF::AppSession->create('open-ils.storage');
+ my $req = $ses->request($method, %$args);
+ my $resp = $req->recv($timeout);
- my $ses = OpenSRF::AppSession->create('open-ils.storage');
- my $req = $ses->request($method, %$args);
- my $resp = $req->recv($timeout);
-
- if($resp and $recs = $resp->content) {
+ if($resp and $recs = $resp->content) {
put_cache($ckey, scalar(@$recs), $recs);
- $recs = [ @$recs[$offset..($offset + ($limit - 1))] ];
} else {
$recs = [];
}
- $ses->kill_me;
+ $ses->kill_me;
}
my $count = 0;
$relevance = 1 if (!$copies_visible);
my $rank = $relevance;
+
+ my $string_default_sort = 'zzzz';
+ $string_default_sort = 'AAAA' if ($sort_dir =~ /^DESC$/i);
+
+ my $number_default_sort = '9999';
+ $number_default_sort = '0000' if ($sort_dir =~ /^DESC$/i);
+
if (lc($sort) eq 'pubdate') {
$rank = <<" RANK";
( FIRST ((
- SELECT COALESCE(SUBSTRING(frp.value FROM E'\\\\d+'),'9999')::INT
+ SELECT COALESCE(SUBSTRING(MAX(frp.value) FROM E'\\\\d{4}'),'$number_default_sort')::INT
FROM $metabib_full_rec frp
WHERE frp.record = f.record
AND frp.tag = '260'
$rank = <<" RANK";
( FIRST (( SELECT edit_date FROM $br_table rbr WHERE rbr.id = f.record)) )
RANK
- } elsif (lc($sort) eq 'title') {
+ } elsif (lc($sort) =~ /^title/i) {
$rank = <<" RANK";
( FIRST ((
- SELECT COALESCE(LTRIM(SUBSTR( frt.value, COALESCE(SUBSTRING(frt.ind2 FROM E'\\\\d+'),'0')::INT + 1 )),'zzzzzzzz')
+ SELECT COALESCE(LTRIM(SUBSTR(MAX(frt.value), COALESCE(SUBSTRING(MAX(frt.ind2) FROM E'\\\\d+'),'0')::INT + 1 )),'$string_default_sort')
FROM $metabib_full_rec frt
WHERE frt.record = f.record
AND frt.tag = '245'
LIMIT 1
)) )
RANK
- } elsif (lc($sort) eq 'author') {
+ } elsif (lc($sort) =~ /^author/i) {
$rank = <<" RANK";
( FIRST((
- SELECT COALESCE(LTRIM(fra.value),'zzzzzzzz')
- FROM $metabib_full_rec fra
- WHERE fra.record = f.record
- AND fra.tag LIKE '1%'
- AND fra.subfield = 'a'
- ORDER BY fra.tag::text::int
- LIMIT 1
+ SELECT COALESCE(LTRIM(MAX(query.value)),'$string_default_sort')
+ FROM (
+ SELECT fra.value
+ FROM $metabib_full_rec fra
+ WHERE fra.record = f.record
+ AND fra.tag LIKE '1%'
+ AND fra.subfield = 'a'
+ ORDER BY fra.tag::text::int
+ LIMIT 1
+ ) query
)) )
RANK
} else {
$sort = undef;
}
-
if ($copies_visible) {
$select = <<" SQL";
SELECT f.record, $relevance, count(DISTINCT cp.id), $rank
$method .= '.staff' if $self->ctx->{is_staff};
my $timeout = 120;
my $ses = OpenSRF::AppSession->create('open-ils.search');
+
+ #when a sort variable is passed in we need to add its value to the arguments
+ my $arghash = {searches => $query, org_unit => $self->ctx->{search_ou}};
+ if (defined $self->cgi->param("sort")) {
+ my ($sort, $sort_dir) = split /\./, $self->cgi->param('sort');
+ $arghash = {%$arghash, sort => "$sort"};
+ if (!defined $sort_dir) {
+ #DESC is the default value for the sort_dir, so we only need to
+ #pass a value to the args if we want an ascending sort. Ascending is indicated
+ #in the interface by only passing the sort axis.
+ #For example, if I want descending authorsort then I pass
+ #authorsort.descending. However, if I want ascending authorsort
+ #then I pass only authorsort in the url
+ $arghash = {%$arghash, sort_dir => "ASC"};
+ }
+ }
+
+ #add the offset and limit to the argash, so we can go past 100 results
+ #if offset and limit are not in the args then they default to 0 and 100
+ #respectively in biblio_multi_search_full_rec, which limits the results to 100
+ #records
+ $arghash = {%$arghash, offset => $offset, limit => $limit};
+
my $req = $ses->request(
$method,
- {searches => $query, org_unit => $self->ctx->{search_ou}},
- $limit, $offset, $timeout);
+ $arghash,
+ $timeout);
my $resp = $req->recv($timeout);
my $results = $resp ? $resp->content : undef;
[% END %]
[% IF is_advanced || is_special %]
<div>
- <input type="hidden" name="_adv" value="1" />
+ [% IF is_advanced %]
+ <input type="hidden" name="_adv" value="1" />
+ [% END %]
+ [% IF is_special %]
+ <input type="hidden" name="_special" value="1" /> [%
+ number_of_expert_rows = CGI.param('tag').list.size;
+ index = 0;
+ WHILE index < number_of_expert_rows %]
+ <input type="hidden" name="tag" value="[% CGI.param('tag').list.$index %]" />
+ <input type="hidden" name="subfield" value="[% CGI.param('subfield').list.$index %]" />
+ <input type="hidden" name="term" value="[% CGI.param('term').list.$index %]" />
+ [% index = index + 1; %]
+ [% END %]
+ [% END %]
+
[% IF ctx.processed_search_query OR (NOT is_advanced AND NOT is_special) %]
- <input name='page' type='hidden' value="0" />
+ <input name='page' type='hidden' value="0" />
[% END %]
</div>
[%- END %]