From bd4d2f3b44face9d265c28c84e9ca9eb85d1ee7d Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 5 Mar 2015 19:16:50 -0800 Subject: make alpahabetic searches start with A --- mod/dirsearch.php | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'mod') diff --git a/mod/dirsearch.php b/mod/dirsearch.php index 12abfafb8..01cbccbed 100644 --- a/mod/dirsearch.php +++ b/mod/dirsearch.php @@ -186,8 +186,10 @@ function dirsearch_content(&$a) { } - if($sort_order == 'normal') + if($sort_order == 'normal') { $order = " order by xchan_name asc "; + $safesql .= " and ascii(substr(xchan_name FROM 1 FOR 1)) > 64 "; + } elseif($sort_order == 'reverse') $order = " order by xchan_name desc "; elseif($sort_order == 'reversedate') @@ -238,15 +240,44 @@ function dirsearch_content(&$a) { json_return_and_die($spkt); } else { - $r = q("SELECT xchan.*, xprof.* from xchan left join xprof on xchan_hash = xprof_hash where ( $logic $sql_extra ) and xchan_network = 'zot' and not ( xchan_flags & %d )>0 and not ( xchan_flags & %d )>0 and not ( xchan_flags & %d )>0 $safesql $order $qlimit ", + + // The query mangling is designed to make alphabetic searches start with 'A' and not precede real names + // with those containing a bunch of punctuation + + if($sort_order == 'normal') { + $sql = $safesql .= " and ascii(substr(xchan_name FROM 1 FOR 1)) > 64 "; + } + else { + $sql = $safesql; + } + + $r = q("SELECT xchan.*, xprof.* from xchan left join xprof on xchan_hash = xprof_hash where ( $logic $sql_extra ) and xchan_network = 'zot' and not ( xchan_flags & %d )>0 and not ( xchan_flags & %d )>0 and not ( xchan_flags & %d )>0 $sql $order $qlimit ", intval(XCHAN_FLAGS_HIDDEN), intval(XCHAN_FLAGS_ORPHAN), intval(XCHAN_FLAGS_DELETED) ); - } - $ret['page'] = $page + 1; - $ret['records'] = count($r); + $ret['page'] = $page + 1; + $ret['records'] = count($r); + + + if(! $r) { + + if($sort_order == 'normal') { + $sql = $safesql .= " and ascii(substr(xchan_name FROM 1 FOR 1)) <= 64 "; + + $r = q("SELECT xchan.*, xprof.* from xchan left join xprof on xchan_hash = xprof_hash where ( $logic $sql_extra ) and xchan_network = 'zot' and not ( xchan_flags & %d )>0 and not ( xchan_flags & %d )>0 and not ( xchan_flags & %d )>0 $sql $order $qlimit ", + intval(XCHAN_FLAGS_HIDDEN), + intval(XCHAN_FLAGS_ORPHAN), + intval(XCHAN_FLAGS_DELETED) + ); + + $ret['page'] = $page + 1; + $ret['records'] = count($r); + + } + } + } if($r) { -- cgit v1.2.3