LP#1744385: Adjust virtual-combined-class real-field search
authorMike Rylander <mrylander@gmail.com>
Wed, 14 Feb 2018 17:25:25 +0000 (12:25 -0500)
committerDan Wells <dbw2@calvin.edu>
Wed, 28 Feb 2018 21:18:54 +0000 (16:18 -0500)
Instead of searching by combined field within the rank-addition real fields,
we'll just search on the fields itself.  This preserves the ranking additions
provided by the real-virtual mapping.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm

index a763f4d..9774fd0 100644 (file)
@@ -1277,29 +1277,24 @@ sub flatten {
                             for my $real_field (@$real_fields) {
                                 $node->add_vfield($real_field);
                                 $logger->debug("Looking up virtual field for real field $real_field");
-                                my $vclass = $self->QueryParser->search_field_class_by_id($real_field)->{classname};
-                                my $vtable = $node->table($vclass);
-                                my $vfield = 'field';
-                                my $vrecord = 'source';
-                                $from .= "\n" . ${spc} x 8 . "UNION ALL\n";
-
-                                if ($node->combined_search) { # real fields inherit combine'dness from the virtual field
-                                    $vtable = $node->combined_table($vclass);
-                                    $vfield = 'metabib_field';
-                                    $vrecord = 'record';
-                                    $from .= ${spc} x 5 . "SELECT 0::BIGINT AS id, fe.record AS source, fe.metabib_field AS field, "
-                                          . "'' AS value, fe.index_vector, fe_weight.weight, ${talias}_xq.tsq, ${talias}_xq.tsq_rank /* virtual field addition */\n";
-                                } else {
-                                    $from .= ${spc} x 5 . "SELECT fe.id, fe.source, fe.field, fe.value, fe.index_vector, "
-                                          . "fe_weight.weight, ${talias}_xq.tsq, ${talias}_xq.tsq_rank /* virtual field addition */\n";
-                                }
-                                
-                                $from .= ${spc} x 6 . "FROM  $vtable AS fe\n"
+                                my $vtable = $node->table(
+                                    $self->QueryParser
+                                        ->search_field_class_by_id($real_field)
+                                        ->{classname}
+                                );
+
+                                # NOTE: only real fields that match the (component) tsquery will
+                                #       get to contribute to and increased rank for the record.
+                                $from .= "\n" . ${spc} x 8 . "UNION ALL\n"
+                                      . ${spc} x 5 . "SELECT fe.id, fe.source, fe.field, fe.value, fe.index_vector, "
+                                      . "fe_weight.weight, ${talias}_xq.tsq, ${talias}_xq.tsq_rank /* virtual field addition */\n"
+                                      . ${spc} x 6 . "FROM  $vtable AS fe\n"
                                       . ${spc} x 7 . "JOIN config.metabib_field_virtual_map AS fe_weight ON ("
                                             ."fe_weight.virtual = $possible_vfield AND "
                                             ."fe_weight.real = $real_field AND "
-                                            ."fe_weight.real = fe.$vfield)\n"
-                                      . ${spc} x 7 . "JOIN ${talias}_xq ON (fe.index_vector @@ ${talias}_xq.tsq)";
+                                            ."fe_weight.real = fe.field)\n"
+                                      . ${spc} x 7 . "JOIN ${talias}_xq ON (fe.index_vector @@ ${talias}_xq.tsq)"
+                                ;
                             }
                         }
                     }