[open-ils-commits] r8948 -
trunk/Open-ILS/src/perlmods/OpenILS/Application/Search
svn at svn.open-ils.org
svn at svn.open-ils.org
Sun Mar 9 23:08:40 EDT 2008
Author: erickson
Date: 2008-03-09 22:35:40 -0400 (Sun, 09 Mar 2008)
New Revision: 8948
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm
Log:
added initial (basic) staged search support
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm 2008-03-10 02:08:11 UTC (rev 8947)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm 2008-03-10 02:35:40 UTC (rev 8948)
@@ -451,6 +451,7 @@
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 @@
$arghash->{limit} = $ol if $ol;
$data->{compiled_search} = $arghash;
+ $data->{query} = $orig_query;
$logger->info("compiled search is " . OpenSRF::Utils::JSON->perl2JSON($arghash));
@@ -719,7 +721,77 @@
}
+__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 {
my $key = shift;
@@ -740,7 +812,6 @@
return undef unless $offset < $count;
-
my @result;
for( my $i = $offset; $i <= $end; $i++ ) {
last unless my $d = $$data[$i];
More information about the open-ils-commits
mailing list