From c152a9b0c238d65c75fe90b34d14e3fc3eeb697a Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 10 Mar 2008 02:35:40 +0000 Subject: [PATCH] added initial (basic) staged search support git-svn-id: svn://svn.open-ils.org/ILS/trunk@8948 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Search/Biblio.pm | 73 ++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm b/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm index 2ebaf4ab7a..ee8d69bae2 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm @@ -451,6 +451,7 @@ sub multiclass_query { my($self, $conn, $arghash, $query, $docache) = @_; $logger->debug("initial search query => $query"); + my $orig_query = $query; $query = decode_utf8($query); $query =~ s/\+/ /go; @@ -526,6 +527,7 @@ sub multiclass_query { $arghash->{limit} = $ol if $ol; $data->{compiled_search} = $arghash; + $data->{query} = $orig_query; $logger->info("compiled search is " . OpenSRF::Utils::JSON->perl2JSON($arghash)); @@ -719,6 +721,76 @@ sub the_quest_for_knowledge { } +__PACKAGE__->register_method( + method => 'staged_search', + api_name => 'open-ils.search.biblio.multiclass.staged'); +__PACKAGE__->register_method( + method => 'staged_search', + api_name => 'open-ils.search.biblio.multiclass.staged.staff', + signature => q/@see open-ils.search.biblio.multiclass.staged/); +__PACKAGE__->register_method( + method => 'staged_search', + api_name => 'open-ils.search.metabib.multiclass.staged', + signature => q/@see open-ils.search.biblio.multiclass.staged/); +__PACKAGE__->register_method( + method => 'staged_search', + api_name => 'open-ils.search.metabib.multiclass.staged.staff', + signature => q/@see open-ils.search.biblio.multiclass.staged/); + +my $CACHE_LIMIT = 200; + +sub staged_search { + my($self, $conn, $search_hash, $nocache) = @_; + + my $method = ($self->api_name =~ /metabib/) ? + 'open-ils.storage.metabib.multiclass.staged.search_fts': + 'open-ils.storage.biblio.multiclass.staged.search_fts'; + + $method .= '.staff' if $self->api_name =~ /staff$/; + $method .= '.atomic'; + + my $results = try_staged_search_cache($method, $search_hash); + + if($results) { + $nocache = 1; + + } else { + $results = $U->storagereq($method, %$search_hash); + unless($nocache) { + # XXX cache me + } + } + + return { + summary => shift(@$results), + results => $results + }; +} + +sub try_staged_search_cache { + my $method = shift; + my $search_hash = shift; + my $key = search_cache_key($method, $search_hash); + my $start = $search_hash->{offset}; + my $end = $start + $search_hash->{limit} - 1; + + # XXX pull me from the cache + return undef; +} + +# creates a unique token to represent the query in the cache +sub search_cache_key { + my $method = shift; + my $search_hash = shift; + my @sorted; + for my $key (sort keys %$search_hash) { + push(@sorted, ($key => $$search_hash{$key})) + if $key ne 'limit' and $key ne 'offset'; + } + my $s = OpenSRF::Utils::JSON->perl2JSON(\@sorted); + return $pfx . md5_hex($method . $s); +} + sub search_cache { @@ -740,7 +812,6 @@ sub search_cache { return undef unless $offset < $count; - my @result; for( my $i = $offset; $i <= $end; $i++ ) { last unless my $d = $$data[$i]; -- 2.43.2