Provide a QP modifier for sorting NULLS FIRST in the core SQL
authorMike Rylander <mrylander@gmail.com>
Tue, 25 Oct 2011 15:53:25 +0000 (11:53 -0400)
committerMike Rylander <mrylander@gmail.com>
Tue, 25 Oct 2011 15:53:25 +0000 (11:53 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>

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

index f5cb67d..41ed64c 100644 (file)
@@ -455,6 +455,8 @@ __PACKAGE__->add_search_filter( 'sort' );
 # modifies core query, not configurable
 __PACKAGE__->add_search_modifier( 'descending' );
 __PACKAGE__->add_search_modifier( 'ascending' );
+__PACKAGE__->add_search_modifier( 'nullsfirst' );
+__PACKAGE__->add_search_modifier( 'nullslast' );
 __PACKAGE__->add_search_modifier( 'metarecord' );
 __PACKAGE__->add_search_modifier( 'metabib' );
 
@@ -549,6 +551,9 @@ sub toSQL {
     my $desc = 'ASC';
     $desc = 'DESC' if ($self->find_modifier('descending'));
 
+    my $nullpos = 'NULLS LAST';
+    $nullpos = 'NULLS FIRST' if ($self->find_modifier('nullsfirst'));
+
     if (grep {$_ eq $sort_filter} @{$self->QueryParser->dynamic_sorters}) {
         $rank = "FIRST(mrd.attrs->'$sort_filter')"
     } elsif ($sort_filter eq 'create_date') {
@@ -668,7 +673,7 @@ SELECT  $key AS id,
         $combined_dyn_filters
         $flat_where
   GROUP BY 1
-  ORDER BY 4 $desc NULLS LAST, 5 DESC NULLS LAST, 3 DESC
+  ORDER BY 4 $desc $nullpos, 5 DESC $nullpos, 3 DESC
   LIMIT $core_limit
 SQL