diff options
author | friendica <info@friendica.com> | 2012-07-16 18:14:45 -0700 |
---|---|---|
committer | friendica <info@friendica.com> | 2012-07-16 18:14:45 -0700 |
commit | 07c31d547fce54dfdcad34a77f1dfcc6269ef62c (patch) | |
tree | 24bfdbc7c91f390a401dfa75a0d127eb0c42db82 /mod/search_ac.php | |
parent | d3d60c8ae555a784427178235093de4d9cb13dad (diff) | |
download | volse-hubzilla-07c31d547fce54dfdcad34a77f1dfcc6269ef62c.tar.gz volse-hubzilla-07c31d547fce54dfdcad34a77f1dfcc6269ef62c.tar.bz2 volse-hubzilla-07c31d547fce54dfdcad34a77f1dfcc6269ef62c.zip |
unified search autocomplete backend, browser performance seems to be a bit sucky
Diffstat (limited to 'mod/search_ac.php')
-rw-r--r-- | mod/search_ac.php | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/mod/search_ac.php b/mod/search_ac.php new file mode 100644 index 000000000..fb3b872da --- /dev/null +++ b/mod/search_ac.php @@ -0,0 +1,85 @@ +<?php + +function search_ac_init(&$a){ + if(!local_user()) + return ""; + + + $start = (x($_REQUEST,'start')?$_REQUEST['start']:0); + $count = (x($_REQUEST,'count')?$_REQUEST['count']:100); + $search = (x($_REQUEST,'search')?$_REQUEST['search']:""); + + if(x($_REQUEST,'query') && strlen($_REQUEST['query'])) { + $search = $_REQUEST['query']; + } + + + $sql_extra = ''; + + $x = array(); + $x['query'] = $search; + $x['photos'] = array(); + $x['links'] = array(); + $x['suggestions'] = array(); + $x['data'] = array(); + + + // Priority to people searches + + if ($search) { + $people_sql_extra = protect_sprintf(" AND `name` LIKE '%". dbesc($search) . "%' "); + $tag_sql_extra = protect_sprintf(" AND term LIKE '%". dbesc($search) . "%' "); + } + + $r = q("SELECT `id`, `name`, `micro`, `url` FROM `contact` + WHERE `uid` = %d AND `pending` = 0 + $people_sql_extra + ORDER BY `name` ASC ", + intval(local_user()) + ); + + if(count($r)) { + foreach($r as $g) { + $x['photos'][] = $g['micro']; + $x['links'][] = $g['url']; + $x['suggestions'][] = '@' . $g['name']; + $x['data'][] = intval($g['id']); + } + } + + $r = q("SELECT `id`, `name`, `photo`, `url` FROM `gcontact` where 1 + $people_sql_extra + ORDER BY `name` ASC " + ); + + if(count($r)) { + foreach($r as $g) { + $x['photos'][] = $g['photo']; + $x['links'][] = $g['url']; + $x['suggestions'][] = '@' . $g['name']; + $x['data'][] = intval($g['id']); + } + } + + $r = q("select tid, term, url from term where type = %d $tag_sql_extra order by term asc", + intval(TERM_HASHTAG) + ); + + if(count($r)) { + foreach($r as $g) { + $x['photos'][] = $a->get_baseurl() . '/images/hashtag.png'; + $x['links'][] = $g['url']; + $x['suggestions'][] = '#' . $g['term']; + $x['data'][] = intval($g['tid']); + } + } + + header("content-type: application/json"); + echo json_encode($x); + + logger('search_ac: ' . print_r($x,true)); + + killme(); +} + + |