From 4f65ce66449fedf58f8a702a5144c2b1a2be2b96 Mon Sep 17 00:00:00 2001 From: miker Date: Sat, 27 Mar 2010 19:21:51 +0000 Subject: [PATCH] more backward compat for staged search -> QueryParser transition; added some debug logging to the compat wrapper function git-svn-id: svn://svn.open-ils.org/ILS/trunk@16023 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm | 12 ++++++++---- .../OpenILS/Application/Storage/Driver/Pg/QueryParser.pm | 14 ++++++++++---- .../OpenILS/Application/Storage/Publisher/metabib.pm | 11 +++++++++-- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm b/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm index b20d69a424..3cf319101e 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm @@ -581,7 +581,7 @@ sub multiclass_query { $query =~ s/name(:|\|)/author$1/og; $logger->debug("cleansed query string => $query"); - my $search = $arghash->{searches} = {}; + my $search = {}; my $simple_class_re = qr/((?:\w+(?:\|\w+)?):[^:]+?)$/; my $class_list_re = qr/(?:keyword|title|author|subject|series)/; @@ -648,17 +648,19 @@ sub multiclass_query { $query =~ s/^\s+//go; $query =~ s/\s+$//go; + my $type = $arghash->{default_class} || 'keyword'; + $type = ($type eq '-') ? 'keyword' : $type; + $type = ($type !~ /^(title|author|keyword|subject|series)(?:\|\w+)?$/o) ? 'keyword' : $type; + if($query) { # This is the front part of the string before any special tokens were # parsed OR colon-separated strings that do not denote a class. # Add this data to the default search class - my $type = $arghash->{default_class} || 'keyword'; - $type = ($type eq '-') ? 'keyword' : $type; - $type = ($type !~ /^(title|author|keyword|subject|series)(?:\|\w+)?$/o) ? 'keyword' : $type; $search->{$type} = {} unless $search->{$type}; $search->{$type}->{term} = ($search->{$type}->{term}) ? $search->{$type}->{term} . " $query" : $query; } + my $real_search = $arghash->{searches} = { $type => { term => $orig_query } }; # capture the original limit because the search method alters the limit internally my $ol = $arghash->{limit}; @@ -677,6 +679,8 @@ sub multiclass_query { $method = $self->method_lookup($method); my ($data) = $method->run($arghash, $docache); + $arghash->{searches} = $search if (!$data->{complex_query}); + $arghash->{limit} = $ol if $ol; $data->{compiled_search} = $arghash; $data->{query} = $orig_query; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm index c240d0a5ad..de1d79a460 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm @@ -464,7 +464,8 @@ sub toSQL { )),'$default'))::TEXT SQL } elsif ($sort_filter eq 'pubdate') { - $rank = "COALESCE( FIRST(NULLIF(REGEXP_REPLACE(mrd.date1, E'\\\\D+', '0', 'g'),'')), '0' )::INT"; + my $default = $desc eq 'DESC' ? '0' : '99999'; + $rank = "COALESCE( FIRST(NULLIF(REGEXP_REPLACE(mrd.date1, E'\\\\D+', '0', 'g'),'0000')), '$default' )::INT"; } elsif ($sort_filter eq 'create_date') { $rank = "( FIRST (( SELECT create_date FROM biblio.record_entry rbr WHERE rbr.id = m.source)) )::TIMESTAMPTZ"; } elsif ($sort_filter eq 'edit_date') { @@ -740,18 +741,23 @@ sub buildSQL { $fields = $self->node->plan->QueryParser->search_fields->{$classname} if (!@$fields); - my @norm_list; + my %norms; + my $pos = 0; for my $field (@$fields) { for my $nfield (keys %$normalizers) { for my $nizer ( @{$$normalizers{$nfield}} ) { - push(@norm_list, $nizer) if ($field eq $nfield && !(grep {$_ eq $nizer} @norm_list)); + if ($field eq $nfield) { + if (!exists($norms{$nizer->{function}})) { + $norms{$nizer->{function}} = {p=>$pos++,n=>$nizer}; + } + } } } } my $sql = $self->node->plan->QueryParser->quote_value($self->content); - for my $n ( @norm_list ) { + for my $n ( map { $$_{n} } sort { $$a{p} <=> $$b{p} } values %norms ) { $sql = join(', ', $sql, map { $self->node->plan->QueryParser->quote_value($_) } @{ $n->{params} }); $sql = $n->{function}."($sql)"; } diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm index 65a48fcf80..4af207fa9d 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm @@ -3012,6 +3012,7 @@ sub query_parser_fts_wrapper { my $client = shift; my %args = @_; + $log->debug("Entering compatability wrapper function for old-style staged search", DEBUG); # grab the query parser and initialize it my $parser = $OpenILS::Application::Storage::QParser; $parser->use; @@ -3050,13 +3051,15 @@ sub query_parser_fts_wrapper { die "No search arguments were passed to ".$self->api_name; } + $log->debug("Constructing QueryParser query from staged search hash ...", DEBUG); my $base_query = ''; for my $sclass ( keys %{$args{searches}} ) { + $log->debug(" --> staged search key: $sclass --> term: $args{searches}{$sclass}{term}", DEBUG); $base_query .= " $sclass: $args{searches}{$sclass}{term}"; } my $query = $base_query; - + $log->debug("Full base query: $base_query", DEBUG); if (!$locale_map{COMPLETE}) { @@ -3074,9 +3077,11 @@ sub query_parser_fts_wrapper { $query = "preferred_language_weight($args{preferred_language_weight}) $query" if ($args{preferred_language_weight} and !$base_plan->parse_tree->find_filter('preferred_language_weight') and !$base_plan->parse_tree->find_filter('preferred_language_multiplier')); $query = "estimation_strategy($args{estimation_strategy}) $query" if ($args{estimation_strategy}); $query = "site($args{org_unit}) $query" if ($args{org_unit}); + $query = "sort($args{sort}) $query" if ($args{sort}); $query = "limit($args{limit}) $query" if ($args{limit}); $query = "offset($args{offset}) $query" if ($args{offset}); $query = "#available $query" if ($args{available}); + $query = "#descending $query" if ($args{sort_dir} && $args{sort_dir} =~ /^d/i); $query = "#staff $query" if ($self->api_name =~ /staff/); @@ -3103,7 +3108,9 @@ sub query_parser_fts_wrapper { } } - return query_parser_fts($self, $client, query => $query, _simple_plan => $parser->new( query => $base_query )->parse->simple_plan ); + $log->debug("Full QueryParser query: $query", DEBUG); + + return query_parser_fts($self, $client, query => $query, _simple_plan => $base_plan->simple_plan ); } __PACKAGE__->register_method( api_name => "open-ils.storage.biblio.multiclass.staged.search_fts", -- 2.11.0