# 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');
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;
} @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) . ")";
}
$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});