function showResults($q, $page) { $profile = new Profile(); $search_engine = $profile->getSearchEngine('profile'); $search_engine->set_sort_mode('chron'); // Ask for an extra to see if there's more. $search_engine->limit(($page - 1) * PROFILES_PER_PAGE, PROFILES_PER_PAGE + 1); if (false === $search_engine->query($q)) { $cnt = 0; } else { $cnt = $profile->find(); } if ($cnt > 0) { $terms = preg_split('/[\\s,]+/', $q); $results = new PeopleSearchResults($profile, $terms, $this); $results->show(); $profile->free(); $this->pagination($page > 1, $cnt > PROFILES_PER_PAGE, $page, 'peoplesearch', array('q' => $q)); } else { // TRANS: Message on the "People search" page where a query has no results. $this->element('p', 'error', _('No results.')); $this->searchSuggestions($q); $profile->free(); } }
/** * Search for users matching the query and spit the results out * as a quick-n-dirty JSON document * * @return void */ function showResults() { $people = array(); $profile = new Profile(); $search_engine = $profile->getSearchEngine('profile'); $search_engine->set_sort_mode('nickname_desc'); $search_engine->limit(0, 10); $search_engine->query(strtolower($this->query . '*')); $cnt = $profile->find(); if ($cnt > 0) { $sql = 'SELECT profile.* FROM profile, user WHERE profile.id = user.id ' . ' AND LEFT(LOWER(profile.nickname), ' . strlen($this->query) . ') = \'%s\' ' . ' LIMIT 0, 10'; $profile->query(sprintf($sql, $this->query)); } while ($profile->fetch()) { $people[] = $profile->nickname; } header('Content-Type: application/json; charset=utf-8'); print json_encode($people); }
function showResults($q, $page) { $profile = new Profile(); // lcase it for comparison // $q = strtolower($q); $search_engine = $profile->getSearchEngine('identica_people'); $search_engine->set_sort_mode('chron'); // Ask for an extra to see if there's more. $search_engine->limit(($page - 1) * PROFILES_PER_PAGE, PROFILES_PER_PAGE + 1); if (false === $search_engine->query($q)) { $cnt = 0; } else { $cnt = $profile->find(); } if ($cnt > 0) { $terms = preg_split('/[\\s,]+/', $q); $results = new PeopleSearchResults($profile, $terms, $this); $results->show(); } else { $this->element('p', 'error', _('No results')); } $profile->free(); $this->pagination($page > 1, $cnt > PROFILES_PER_PAGE, $page, 'peoplesearch', array('q' => $q)); }
function getUsers() { $profile = new Profile(); $offset = ($this->page - 1) * PROFILES_PER_PAGE; $limit = PROFILES_PER_PAGE + 1; if (isset($this->q)) { // User is searching via query $search_engine = $profile->getSearchEngine('profile'); $mode = 'reverse_chron'; if ($this->sort == 'nickname') { if ($this->reverse) { $mode = 'nickname_desc'; } else { $mode = 'nickname_asc'; } } else { if ($this->reverse) { $mode = 'chron'; } } $search_engine->set_sort_mode($mode); $search_engine->limit($offset, $limit); $search_engine->query($this->q); $profile->find(); } else { // User is browsing via AlphaNav $sort = $this->getSortKey(); $sql = 'SELECT profile.* FROM profile, user WHERE profile.id = user.id'; switch ($this->filter) { case 'all': // NOOP break; case '0-9': $sql .= ' AND LEFT(profile.nickname, 1) BETWEEN \'0\' AND \'9\''; break; default: $sql .= sprintf(' AND LEFT(LOWER(profile.nickname), 1) = \'%s\'', $this->filter); } $sql .= sprintf(' ORDER BY profile.%s %s, profile.nickname ASC LIMIT %d, %d', $sort, $this->reverse ? 'DESC' : 'ASC', $offset, $limit); $profile->query($sql); } return $profile; }
function getResults() { $profiles = array(); $q = $this->arg('q'); $q = strtolower($q); if (strlen($q) < 3) { // TRANS: Error message in case a search is shorter than three characters. $this->msg = _('The search string must be at least 3 characters long.'); } $page = $this->arg('page'); $page = (int) (empty($page) ? 1 : $page); $profile = new Profile(); $search_engine = $profile->getSearchEngine('profile'); if (Event::handle('StartProfileCompletionSearch', array($this, &$profile, $search_engine))) { $search_engine->set_sort_mode('chron'); $search_engine->limit(($page - 1) * PROFILES_PER_PAGE, PROFILES_PER_PAGE + 1); if (false === $search_engine->query($q)) { $cnt = 0; } else { $cnt = $profile->find(); } // @todo FIXME: Call-time pass-by-reference has been deprecated. Event::handle('EndProfileCompletionSearch', $this, &$profile, $search_engine); } while ($profile->fetch()) { $profiles[] = clone $profile; } return $this->filter($profiles); }
function getUsers() { $profile = new Profile(); // Comment this out or disable to get global profile searches $profile->joinAdd(array('id', 'user:id')); $offset = ($this->page - 1) * PROFILES_PER_PAGE; $limit = PROFILES_PER_PAGE + 1; if (!empty($this->q)) { // User is searching via query $search_engine = $profile->getSearchEngine('profile'); $mode = 'reverse_chron'; if ($this->sort == 'nickname') { if ($this->reverse) { $mode = 'nickname_desc'; } else { $mode = 'nickname_asc'; } } else { if ($this->reverse) { $mode = 'chron'; } } $search_engine->set_sort_mode($mode); $search_engine->limit($offset, $limit); $search_engine->query($this->q); $profile->find(); } else { // User is browsing via AlphaNav switch ($this->filter) { case 'all': // NOOP break; case '0-9': $profile->whereAdd(sprintf('LEFT(%1$s.%2$s, 1) BETWEEN %3$s AND %4$s', $profile->escapedTableName(), 'nickname', $profile->_quote("0"), $profile->_quote("9"))); break; default: $profile->whereAdd(sprintf('LEFT(LOWER(%1$s.%2$s), 1) = %3$s', $profile->escapedTableName(), 'nickname', $profile->_quote($this->filter))); } $order = sprintf('%1$s.%2$s %3$s, %1$s.%4$s ASC', $profile->escapedTableName(), $this->getSortKey('nickname'), $this->reverse ? 'DESC' : 'ASC', 'nickname'); $profile->orderBy($order); $profile->limit($offset, $limit); $profile->find(); } return $profile; }