From 2114cd21f8ff4df7e82bae0d26fc53ab8d5e20a6 Mon Sep 17 00:00:00 2001 From: miker Date: Tue, 4 May 2010 15:06:26 +0000 Subject: [PATCH] repair SQL generation for ORed queries git-svn-id: svn://svn.open-ils.org/ILS/trunk@16384 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../Application/Storage/Driver/Pg/QueryParser.pm | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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 5e265e22d..7c9d85d52 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 @@ -602,20 +602,26 @@ sub flatten { my $table = $node->table; my $talias = $node->table_alias; - my $node_rank = $node->rank . " * ${talias}_weight.weight"; + my $node_rank = $node->rank . " * ${talias}.weight"; - $from .= "\n\tLEFT JOIN (\n\t\tSELECT * /* search */\n\t\t FROM $table\n\t\t WHERE index_vector @@ (" .$node->tsquery . ')'; + my $core_limit = $self->QueryParser->core_limit || 25000; + $from .= "\n\tLEFT JOIN (\n\t\tSELECT fe.*, fe_weight.weight /* search */\n\t\t FROM $table AS fe"; + $from .= "\n\t\t\tJOIN config.metabib_field AS fe_weight ON (fe_weight.id = fe.field)"; + $from .= "\n\t\t WHERE fe.index_vector @@ (" .$node->tsquery . ')'; my @bump_fields; if (@{$node->fields} > 0) { @bump_fields = @{$node->fields}; - $from .= "\n\t\t\tAND field IN (SELECT id FROM config.metabib_field WHERE field_class = ". $self->QueryParser->quote_value($node->classname) ." AND name IN ("; - $from .= join(",", map { $self->QueryParser->quote_value($_) } @{$node->fields}) . "))"; + $from .= "\n\t\t\tAND fe_weight.field_class = ". $self->QueryParser->quote_value($node->classname) ." AND fe_weight.name IN ("; + $from .= join(",", map { $self->QueryParser->quote_value($_) } @{$node->fields}) . ")"; } else { @bump_fields = @{$self->QueryParser->search_fields->{$node->classname}}; } + $from .= "\n\t\tLIMIT $core_limit\n\t) AS $talias ON (m.source = $talias.source)"; + + my %used_bumps; for my $field ( @bump_fields ) { my $bumps = $self->QueryParser->find_relevance_bumps( $node->classname => $field ); @@ -629,10 +635,6 @@ sub flatten { } } - my $core_limit = $self->QueryParser->core_limit || 25000; - $from .= "\n\t\tLIMIT $core_limit\n\t) AS $talias ON (m.source = $talias.source)"; - $from .= "\n\tJOIN config.metabib_field AS ${talias}_weight ON (${talias}_weight.id = $talias.field)\n"; - $where .= '(' . $talias . ".id IS NOT NULL"; $where .= ' AND ' . join(' AND ', map {"$talias.value ~* ".$self->QueryParser->quote_value($_)} @{$node->phrases}) if (@{$node->phrases}); $where .= ')'; -- 2.11.0