[open-ils-commits] r16023 - in trunk/Open-ILS/src/perlmods/OpenILS/Application: Search Storage/Driver/Pg Storage/Publisher (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Sat Mar 27 15:21:56 EDT 2010
Author: miker
Date: 2010-03-27 15:21:51 -0400 (Sat, 27 Mar 2010)
New Revision: 16023
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm
trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm
Log:
more backward compat for staged search -> QueryParser transition; added some debug logging to the compat wrapper function
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm 2010-03-27 17:46:35 UTC (rev 16022)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm 2010-03-27 19:21:51 UTC (rev 16023)
@@ -581,7 +581,7 @@
$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 @@
$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 @@
$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;
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm 2010-03-27 17:46:35 UTC (rev 16022)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm 2010-03-27 19:21:51 UTC (rev 16023)
@@ -464,7 +464,8 @@
)),'$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 @@
$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)";
}
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm 2010-03-27 17:46:35 UTC (rev 16022)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm 2010-03-27 19:21:51 UTC (rev 16023)
@@ -3012,6 +3012,7 @@
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,14 +3051,16 @@
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}) {
my @locales = config::i18n_locale->search_where({ code => { '<>' => '' } });
@@ -3074,9 +3077,11 @@
$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 @@
}
}
- 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",
More information about the open-ils-commits
mailing list