Update search with better sorting

- Remove * append to search string when query contains a space
This commit is contained in:
Hypolite Petovan 2018-10-25 23:35:53 -04:00
parent 79ad132ce6
commit 90ea11c6d8

View file

@ -51,38 +51,40 @@ function search_content(App $a)
goaway('/home'); goaway('/home');
} }
if ($search) { if (strpos($search, ' ') === false) {
$alpha = true; $search .= '*';
} }
//Run our query. //Run our query.
if ($search) { $search = dbesc($search);
$search = dbesc($search . '*'); $search = str_replace('%', '%%', $search);
}
$sql_extra = ((strlen($search)) ? " AND MATCH (`name`, `pdesc`, `homepage`, `locality`, `region`, `country-name`, `tags` ) $sql_where = "WHERE MATCH (`name`, `pdesc`, `homepage`, `locality`, `region`, `country-name`, `tags` )
AGAINST ('$search' IN BOOLEAN MODE) " : ''); AGAINST ('$search' IN BOOLEAN MODE)
AND NOT `censored`
AND `available`";
if (!is_null($community)) { if (!is_null($community)) {
$sql_extra .= ' AND `comm` = ' . intval($community) . ' '; $sql_where .= '
AND `comm` = ' . intval($community);
} }
$sql_extra = str_replace('%', '%%', $sql_extra);
$total = 0; $total = 0;
$r = q("SELECT COUNT(*) AS `total` FROM `profile` WHERE `censored` = 0 AND `available` = 1 $sql_extra "); $r = q("SELECT COUNT(*) AS `total`
FROM `profile`
$sql_where");
if (count($r)) { if (count($r)) {
$total = $r[0]['total']; $total = $r[0]['total'];
$a->set_pager_total($total); $a->set_pager_total($total);
} }
if ($alpha) { $query = "SELECT *
$order = ' ORDER BY `name` ASC '; FROM `profile`
} else { $sql_where
$order = ' ORDER BY `updated` DESC, `id` DESC '; ORDER BY `filled_fields` DESC, `last_activity` DESC, `updated` DESC
} LIMIT %d, %d";
$r = q("SELECT * FROM `profile` WHERE `censored` = 0 AND `available` = 1 $sql_extra $order LIMIT %d , %d ", $r = q($query,
intval($a->pager['start']), intval($a->pager['start']),
intval($a->pager['itemspage']) intval($a->pager['itemspage'])
); );