From 810772ef3a33655411b6158f6ede56b19320f671 Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Thu, 13 Sep 2012 09:28:08 -0400 Subject: [PATCH] Code style: break up long lines For lines blowing past the 100-char width barrier, take a couple of approaches: * Use the "x" operator to multiply strings, rather than explicitly copy the space operator over and over * Try to keep long lines broken at a natural point once you get in the vicinity of 80 chars Also, for extremely long lines, it becomes much more legible to put the conditional test at the start, rather than appending it to the end; otherwise you have to read all of the way through the line before realizing that the line doesn't apply to your case because of the appended condition. Signed-off-by: Dan Scott --- .../Application/Storage/Driver/Pg/QueryParser.pm | 33 ++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm index ee608b8723..9485dfdf09 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm @@ -573,7 +573,11 @@ sub toSQL { # generate the relevance ranking my $rel = '1'; # Default to something simple in case rank_list is empty. - $rel = "AVG(\n${spc}${spc}${spc}${spc}${spc}(" . join(")\n${spc}${spc}${spc}${spc}${spc}+ (", @{$$flat_plan{rank_list}}) . ")\n${spc}${spc}${spc}${spc})+1" if (@{$$flat_plan{rank_list}}); + if (@{$$flat_plan{rank_list}}) { + $rel = "AVG(\n" . ${spc} x 5 . "(" . join( + ")\n" . ${spc} x 5 + "(", @{$$flat_plan{rank_list}} + ) . ")\n" . ${spc} x 4 . ")+1"; + } # find any supplied sort option my ($sort_filter) = $self->find_filter('sort'); @@ -866,15 +870,20 @@ sub flatten { my $node_rank = 'COALESCE(' . $node->rank . " * ${talias}.weight, 0.0)"; my $core_limit = $self->QueryParser->core_limit || 25000; - $from .= "\n${spc}${spc}${spc}${spc}LEFT JOIN (\n${spc}${spc}${spc}${spc}${spc}SELECT fe.*, fe_weight.weight, ${talias}_xq.tsq /* search */\n${spc}${spc}${spc}${spc}${spc} FROM $table AS fe"; - $from .= "\n${spc}${spc}${spc}${spc}${spc}${spc}JOIN config.metabib_field AS fe_weight ON (fe_weight.id = fe.field)"; + $from .= "\n" . ${spc} x 4 . "LEFT JOIN (\n" . ${spc} x 5 . + "SELECT fe.*, fe_weight.weight, ${talias}_xq.tsq " . + "/* search */\n" . ${spc} x 5 . " FROM $table AS fe"; + $from .= "\n" . ${spc} x 6 . "JOIN config.metabib_field " . + "AS fe_weight ON (fe_weight.id = fe.field)"; if ($node->dummy_count < @{$node->only_atoms} ) { $with .= ",\n " if $with; $with .= "${talias}_xq AS (SELECT ". $node->tsquery ." AS tsq )"; - $from .= "\n${spc}${spc}${spc}${spc}${spc}${spc}JOIN ${talias}_xq ON (fe.index_vector @@ ${talias}_xq.tsq)"; + $from .= "\n" . ${spc} x 6 . "JOIN ${talias}_xq ON " . + "(fe.index_vector @@ ${talias}_xq.tsq)"; } else { - $from .= "\n${spc}${spc}${spc}${spc}${spc}${spc}, (SELECT NULL::tsquery AS tsq ) AS ${talias}_xq"; + $from .= "\n" . ${spc} x 6 . ", (SELECT NULL::tsquery AS tsq)" . + " AS ${talias}_xq"; } my @bump_fields; @@ -889,7 +898,7 @@ sub flatten { } @bump_fields ); if (@field_ids) { - $from .= "\n${spc}${spc}${spc}${spc}${spc}${spc}WHERE fe_weight.id IN (" . + $from .= "\n" . ${spc} x 6 . "WHERE fe_weight.id IN (" . join(',', @field_ids) . ")"; } @@ -918,8 +927,16 @@ sub flatten { $where .= '(' . $talias . ".id IS NOT NULL"; - $where .= ' AND ' . join(' AND ', map {"${talias}.value ~* ".$self->QueryParser->quote_phrase_value($_)} @{$node->phrases}) if (@{$node->phrases}); - $where .= ' AND ' . join(' AND ', map {"${talias}.value !~* ".$self->QueryParser->quote_phrase_value($_)} @{$node->unphrases}) if (@{$node->unphrases}); + if (@{$node->phrases}) { + $where .= ' AND ' . join(' AND ', map { + "${talias}.value ~* ".$self->QueryParser->quote_phrase_value($_) + } @{$node->phrases}); + } + if (@{$node->unphrases}) { + $where .= ' AND ' . join(' AND ', map { + "${talias}.value !~* ".$self->QueryParser->quote_phrase_value($_) + } @{$node->unphrases}); + } for my $atom (@{$node->only_real_atoms}) { next unless $atom->{content} && $atom->{content} =~ /(^\^|\$$)/; $where .= " AND ${talias}.value ~* ".$self->QueryParser->quote_phrase_value($atom->{content}); -- 2.11.0