From: Lebbeous Fogle-Weekley Date: Mon, 20 Aug 2012 15:16:21 +0000 (-0400) Subject: Get all search results, not just first 10 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=30c4d7a90d60028d71dcbc137c6de44c8750e1ec;p=evergreen%2Fequinox.git Get all search results, not just first 10 Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/URLVerify.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/URLVerify.pm index 1305f88fe9..67f1a31bc3 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/URLVerify.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/URLVerify.pm @@ -670,29 +670,65 @@ sub session_perform_search { return $e->die_event unless $session and $e->allowed("VERIFY_URL", $session->owning_lib); - # XXX TODO, if the following search takes too long, the caller of our method - # can time out - # XXX TODO keep doing this to page over the whole result set - my $search_results = $U->simplereq( - "open-ils.search", "open-ils.search.biblio.multiclass.query.staff", - {}, $session->search - ); + my @result_ids; + + # Don't loop if the user has specific their own offset. + if ($session->search =~ /offset\(\d+\)/) { + my $res = $U->simplereq( + "open-ils.search", + "open-ils.search.biblio.multiclass.query.staff", + {}, $session->search + ); + + return new OpenILS::Event("UNKNOWN") unless $res; + return $res if $U->is_event($res); + + @result_ids = map { shift @$_ } @{$res->{ids}}; # IDs nested in array + } else { + my $count; + my $so_far = 0; + + do { + my $search = $session->search . + " offset(" . scalar(@result_ids) . ")"; + + my $res = $U->simplereq( + "open-ils.search", + "open-ils.search.biblio.multiclass.query.staff", + {}, $search + ); - return new OpenILS::Event("UNKNOWN") unless $search_results; - return $search_results if $U->is_event($search_results); + return new OpenILS::Event("UNKNOWN") unless $res; + return $res if $U->is_event($res); + + # Search only returns the total count when offset is 0. + # We can't get more than one superpage this way, XXX TODO ? + $count = $res->{count} unless defined $count; + + my @this_batch = map { shift @$_ } @{$res->{ids}}; # unnest IDs + push @result_ids, @this_batch; + + # Send a keepalive in case search is slow, although it'll probably + # be the query for the first ten results that's slowest. + $client->status(new OpenSRF::DomainObject::oilsContinueStatus); + + last unless @this_batch; # Protect against getting fewer results + # than count promised. + + } while ($count - scalar(@result_ids) > 0); + } $e->xact_begin; # Make and save a bucket item for each search result. - # remember, from search, each ID is nested in its own array ref my $pos = 0; - foreach my $wrapper (@{$search_results->{ids}}) { + foreach my $bre_id (@result_ids) { my $bucket_item = Fieldmapper::container::biblio_record_entry_bucket_item->new; $bucket_item->bucket($session->container); - $bucket_item->target_biblio_record_entry(pop @$wrapper); + $bucket_item->target_biblio_record_entry($bre_id); $bucket_item->pos($pos++); # we don't actually care $e->create_container_biblio_record_entry_bucket_item($bucket_item) or