From c5d12656aa80a09928b3b7dd8deed6f886d56cfa Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Mon, 24 Jun 2013 11:41:32 -0400 Subject: [PATCH] Short circuit empty searches If we have no search terms, we shouldn't kick off a search. Accordingly, track whether we have, in fact, any type + value combos where value is not an empty string, or a non-empty original query, and return immediately if we have nothing to search. Compare the results of the following opensrf call before and after: request open-ils.search open-ils.search.biblio.multiclass.query {} "title: " Signed-off-by: Dan Scott --- .../src/perlmods/lib/OpenILS/Application/Search/Biblio.pm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm index 206812867b..eef7694fa5 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm @@ -854,6 +854,7 @@ sub multiclass_query { my $modifier_list_re = qr/(?:site|dir|sort|lang|available|preflib)/; my $tmp_value = ''; + my $nonempty_search = 0; # prevent entirely empty queries while ($query =~ s/$simple_class_re//so) { my $qpart = $1; @@ -871,10 +872,13 @@ sub multiclass_query { $tmp_value = ''; } - next unless $type and $value; + next unless $type; $value =~ s/^\s*//og; $value =~ s/\s*$//og; + + next unless $value; + $type = 'sort_dir' if $type eq 'dir'; if($type eq 'site') { @@ -915,6 +919,7 @@ sub multiclass_query { $search->{$type}->{term} = ($search->{$type}->{term}) ? $search->{$type}->{term} . " $value" : $value; } + $nonempty_search = 1; } $query .= " $tmp_value"; @@ -933,7 +938,11 @@ sub multiclass_query { $search->{$type} = {} unless $search->{$type}; $search->{$type}->{term} = ($search->{$type}->{term}) ? $search->{$type}->{term} . " $query" : $query; + $nonempty_search = 1; } + + return unless $nonempty_search; + my $real_search = $arghash->{searches} = { $type => { term => $orig_query } }; # capture the original limit because the search method alters the limit internally -- 2.11.0