Node Title Sort
It was brought to my attention by a client that the title sort was not being done correctly. After looking at the queries generated on Views with the views_alpha pager, I noticed that the order clause was incorrectly using the following as the first order clause.
ORDER BY(LEFT(TRIM(LEADING 'AND ' FROM (TRIM(LEADING 'THE ' FROM (TRIM(LEADING 'A ' FROM (TRIM(LEADING '\'' FROM (TRIM(LEADING '"' FROM (TRIM(LEADING ' ' FROM (UPPER(node.title))))))))))))),1) = 'A')
I can only assume that it would be best to sort the query by the full value after the Leading Trim words were removed, like so
(TRIM(LEADING 'AND ' FROM (TRIM(LEADING 'THE ' FROM (TRIM(LEADING 'A ' FROM (TRIM(LEADING '\'' FROM (TRIM(LEADING '"' FROM (TRIM(LEADING ' ' FROM (UPPER(node.title)))))))))))))
I found the bug at line 138-150 in the views_alpha_pager.module:
$myfield = 'UPPER('. $sort_field .')'; if ($ignore = variable_get('views_alpha_pager_ignore', 'a the and')) { $trimterms = array(' ', '"', '\\\''); foreach (explode(' ', $ignore) as $word) { $trimterms[] = check_plain($word) .' '; } // use the ignore words to trim sort field foreach ($trimterms as $trim) { $myfield = "TRIM(LEADING '". strtoupper($trim) ."' FROM ($myfield))"; } } $myfield = "LEFT($myfield, 1)";
read more