Better search normalization de-duping when 'params' are used
authordbwells <dbwells@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 1 Apr 2011 15:17:51 +0000 (15:17 +0000)
committerdbwells <dbwells@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 1 Apr 2011 15:17:51 +0000 (15:17 +0000)
This patch addresses search normalization deduping at two levels.  We now verify that both the function and the params are the same before excluding a normalization, both when the normalization is first added to the set and when the SQL is being built (since currently multiple sets may be involved).

git-svn-id: svn://svn.open-ils.org/ILS/trunk@19924 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/QueryParser.pm

index c74ffee..f207eb0 100644 (file)
@@ -802,8 +802,9 @@ sub buildSQL {
         for my $nfield (keys %$normalizers) {
             for my $nizer ( @{$$normalizers{$nfield}} ) {
                 if ($field eq $nfield) {
-                    if (!exists($norms{$nizer->{function}})) {
-                        $norms{$nizer->{function}} = {p=>$pos++,n=>$nizer};
+                    my $param_string = OpenSRF::Utils::JSON->perl2JSON($nizer->{params});
+                    if (!exists($norms{$nizer->{function}.$param_string})) {
+                        $norms{$nizer->{function}.$param_string} = {p=>$pos++,n=>$nizer};
                     }
                 }
             }
index 7792b49..1bee562 100644 (file)
@@ -1,4 +1,5 @@
 package QueryParser;
+use OpenSRF::Utils::JSON;
 our %parser_config = (
     QueryParser => {
         filters => [],
@@ -180,7 +181,11 @@ sub add_query_normalizer {
     my $func = shift;
     my $params = shift || [];
 
-    return $func if (grep { $_ eq $func } @{$pkg->query_normalizers->{$class}->{$field}});
+    # do not add if function AND params are identical to existing member
+    return $func if (grep {
+        $_->{function} eq $func and 
+        OpenSRF::Utils::JSON->perl2JSON($_->{params}) eq OpenSRF::Utils::JSON->perl2JSON($params)
+    } @{$pkg->query_normalizers->{$class}->{$field}});
 
     push(@{$pkg->query_normalizers->{$class}->{$field}}, { function => $func, params => $params });