Improve result sorting #59
29
dfrndir.sql
|
@ -1,4 +1,4 @@
|
|||
-- Generation Time: Apr 21, 2017 at 03:58 AM
|
||||
-- Generation Time: Oct 26, 2018 at 05:31 AM
|
||||
|
||||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||
SET time_zone = "+00:00";
|
||||
|
@ -18,7 +18,7 @@ CREATE TABLE IF NOT EXISTS `flag` (
|
|||
`reason` int(11) NOT NULL,
|
||||
`total` int(11) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
|
@ -32,7 +32,7 @@ CREATE TABLE IF NOT EXISTS `photo` (
|
|||
`data` mediumblob NOT NULL,
|
||||
`score` float NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=2516 DEFAULT CHARSET=utf8mb4;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
|
@ -53,20 +53,16 @@ CREATE TABLE IF NOT EXISTS `profile` (
|
|||
`homepage` char(255) NOT NULL,
|
||||
`photo` char(255) NOT NULL,
|
||||
`tags` longtext NOT NULL,
|
||||
`filled_fields` tinyint(4) NOT NULL DEFAULT '0',
|
||||
`last_activity` varchar(7) DEFAULT NULL,
|
||||
`available` tinyint(1) NOT NULL DEFAULT '1',
|
||||
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`censored` tinyint(4) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `name` (`name`(250)),
|
||||
KEY `nurl` (`nurl`(250)),
|
||||
KEY `comm` (`comm`),
|
||||
KEY `pdesc` (`pdesc`(250)),
|
||||
KEY `locality` (`locality`(250)),
|
||||
KEY `region` (`region`(250)),
|
||||
KEY `country-name` (`country-name`(250)),
|
||||
KEY `homepage` (`homepage`(250))
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=2518 DEFAULT CHARSET=utf8mb4;
|
||||
KEY `profile_sorting` (`filled_fields`,`last_activity`,`updated`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
|
@ -82,7 +78,7 @@ CREATE TABLE IF NOT EXISTS `session` (
|
|||
PRIMARY KEY (`id`),
|
||||
KEY `sid` (`sid`(250)),
|
||||
KEY `expire` (`expire`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=22917 DEFAULT CHARSET=utf8mb4;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
|
@ -130,10 +126,10 @@ CREATE TABLE IF NOT EXISTS `site-health` (
|
|||
`ssl_state` bit(1) DEFAULT NULL,
|
||||
`ssl_grade` varchar(3) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `base_url` (`base_url`(250)),
|
||||
UNIQUE KEY `base_url` (`base_url`(250)) USING BTREE,
|
||||
KEY `health_score` (`health_score`),
|
||||
KEY `dt_last_seen` (`dt_last_seen`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=10035 DEFAULT CHARSET=utf8mb4;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
|
@ -151,7 +147,7 @@ CREATE TABLE IF NOT EXISTS `site-probe` (
|
|||
PRIMARY KEY (`id`),
|
||||
KEY `site_health_id` (`site_health_id`),
|
||||
KEY `dt_performed` (`dt_performed`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=28987 DEFAULT CHARSET=utf8mb4;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
|
@ -170,7 +166,7 @@ CREATE TABLE IF NOT EXISTS `site-scrape` (
|
|||
PRIMARY KEY (`id`),
|
||||
KEY `site_health_id` (`site_health_id`),
|
||||
KEY `dt_performed` (`dt_performed`)
|
||||
) ENGINE=MyISAM AUTO_INCREMENT=177675 DEFAULT CHARSET=utf8mb4;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
|
@ -257,5 +253,4 @@ CREATE TABLE IF NOT EXISTS `user` (
|
|||
--
|
||||
-- Indexes for table `profile`
|
||||
--
|
||||
ALTER TABLE `profile` ADD FULLTEXT KEY `tags` (`tags`);
|
||||
ALTER TABLE `profile` ADD FULLTEXT KEY `profile-ft` (`name`,`pdesc`,`homepage`,`locality`,`region`,`country-name`,`tags`);
|
||||
|
|
Before Width: | Height: | Size: 346 B After Width: | Height: | Size: 325 B |
Before Width: | Height: | Size: 490 B After Width: | Height: | Size: 469 B |
BIN
images/dfrn.gif
Before Width: | Height: | Size: 109 B After Width: | Height: | Size: 104 B |
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 8.1 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 8.1 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 16 KiB |
BIN
images/like.gif
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 132 B |
BIN
images/star.jpg
Before Width: | Height: | Size: 608 B After Width: | Height: | Size: 589 B |
|
@ -115,6 +115,11 @@ function run_submit($url)
|
|||
$params['comm'] = intval($params['comm']);
|
||||
}
|
||||
|
||||
$filled_fields =
|
||||
intval(!empty($params['pdesc'])) * 4
|
||||
+ intval(!empty($params['tags'])) * 2
|
||||
+ intval(!empty($params['locality']) || !empty($params['region']) || !empty($params['postal-code']) || !empty($params['country-name']));
|
||||
|
||||
if ($profile_exists) {
|
||||
$r = q("UPDATE `profile` SET
|
||||
`name` = '%s',
|
||||
|
@ -127,6 +132,8 @@ function run_submit($url)
|
|||
`nurl` = '%s',
|
||||
`comm` = %d,
|
||||
`tags` = '%s',
|
||||
`filled_fields` = %d,
|
||||
`last_activity` = '%s',
|
||||
`available` = 1,
|
||||
`updated` = '%s'
|
||||
WHERE `id` = %d LIMIT 1",
|
||||
|
@ -140,13 +147,29 @@ function run_submit($url)
|
|||
dbesc($nurl),
|
||||
intval($params['comm']),
|
||||
$params['tags'],
|
||||
$filled_fields,
|
||||
x($params, 'last-activity') ? $params['last-activity'] : NULL,
|
||||
dbesc(datetime_convert()),
|
||||
intval($profile_id)
|
||||
);
|
||||
logger('Update returns: ' . $r);
|
||||
} else {
|
||||
$r = q("INSERT INTO `profile` ( `name`, `pdesc`, `locality`, `region`, `postal-code`, `country-name`, `homepage`, `nurl`, `comm`, `tags`, `created`, `updated` )
|
||||
VALUES ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s' )",
|
||||
$r = q("INSERT INTO `profile` SET
|
||||
`name` = '%s',
|
||||
`pdesc` = '%s',
|
||||
`locality` = '%s',
|
||||
`region` = '%s',
|
||||
`postal-code` = '%s',
|
||||
`country-name` = '%s',
|
||||
`homepage` = '%s',
|
||||
`nurl` = '%s',
|
||||
`comm` = %d,
|
||||
`tags` = '%s',
|
||||
`filled_fields` = %d,
|
||||
`last_activity` = '%s',
|
||||
`available` = 1,
|
||||
`created` = '%s',
|
||||
`updated` = '%s'",
|
||||
$params['fn'],
|
||||
x($params, 'pdesc') ? $params['pdesc'] : '',
|
||||
x($params, 'locality') ? $params['locality'] : '',
|
||||
|
@ -157,6 +180,8 @@ function run_submit($url)
|
|||
dbesc($nurl),
|
||||
intval($params['comm']),
|
||||
x($params, 'tags') ? $params['tags'] : '',
|
||||
$filled_fields,
|
||||
x($params, 'last-activity') ? $params['last-activity'] : NULL,
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(datetime_convert())
|
||||
);
|
||||
|
|
|
@ -62,7 +62,7 @@ function directory_content(App $a)
|
|||
if ($alpha) {
|
||||
$order = ' ORDER BY `name` ASC ';
|
||||
} else {
|
||||
$order = ' ORDER BY `updated` DESC, `id` DESC ';
|
||||
$order = ' ORDER BY `filled_fields` DESC, `last_activity` DESC, `updated` DESC';
|
||||
}
|
||||
The last_actitivy is The last_actitivy is `YYYY-WW` with WW being the week number in the year, so we can't sort on the month if it made any sense. Besides, this sorting is only to improve the visual impression of the default display of the directory. The first page will always have filled profiles with recent activity. What happens in the subsequent pages is way less relevant.
Ah, yeah. We already compacted the data. So possibly we should sort by "last_activity" and "filled_fields" instead. Ah, yeah. We already compacted the data. So possibly we should sort by "last_activity" and "filled_fields" instead.
And then you'd have all the spam bots without any profile info first. Believe me, I thought about it, I tried different orders, and this was the most visually gratifying. And then you'd have all the spam bots without any profile info first. Believe me, I thought about it, I tried different orders, and this was the most visually gratifying.
Okay. Since we can change that very fast (and since there aren't that many installations), we can test it out. Okay. Since we can change that very fast (and since there aren't that many installations), we can test it out.
It's already in place on https://dir.friendica.social anyway! It's already in place on https://dir.friendica.social anyway!
|
||||
|
||||
$r = q("SELECT * FROM `profile` WHERE `censored` = 0 AND `available` = 1 $sql_extra $order LIMIT %d , %d ",
|
||||
|
|
|
@ -51,38 +51,40 @@ function search_content(App $a)
|
|||
goaway('/home');
|
||||
}
|
||||
|
||||
if ($search) {
|
||||
$alpha = true;
|
||||
if (strpos($search, ' ') === false) {
|
||||
$search .= '*';
|
||||
}
|
||||
|
||||
//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` )
|
||||
AGAINST ('$search' IN BOOLEAN MODE) " : '');
|
||||
$sql_where = "WHERE MATCH (`name`, `pdesc`, `homepage`, `locality`, `region`, `country-name`, `tags` )
|
||||
AGAINST ('$search' IN BOOLEAN MODE)
|
||||
AND NOT `censored`
|
||||
AND `available`";
|
||||
|
||||
if (!is_null($community)) {
|
||||
$sql_extra .= ' AND `comm` = ' . intval($community) . ' ';
|
||||
$sql_where .= '
|
||||
AND `comm` = ' . intval($community);
|
||||
}
|
||||
|
||||
$sql_extra = str_replace('%', '%%', $sql_extra);
|
||||
|
||||
$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)) {
|
||||
$total = $r[0]['total'];
|
||||
$a->set_pager_total($total);
|
||||
}
|
||||
|
||||
if ($alpha) {
|
||||
$order = ' ORDER BY `name` ASC ';
|
||||
} else {
|
||||
$order = ' ORDER BY `updated` DESC, `id` DESC ';
|
||||
}
|
||||
$query = "SELECT *
|
||||
FROM `profile`
|
||||
$sql_where
|
||||
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['itemspage'])
|
||||
);
|
||||
|
|
|
@ -9,8 +9,16 @@
|
|||
<div class="location">
|
||||
<?php
|
||||
$parts = array();
|
||||
if(!empty($profile['locality'])) $parts[] = $profile['locality'];
|
||||
if(!empty($profile['country-name'])) $parts[] = $profile['country-name'];
|
||||
if(!empty($profile['locality'])) {
|
||||
$parts[] = $profile['locality'];
|
||||
}
|
||||
if(!empty($profile['region'])
|
||||
&& strtolower($profile['locality']) != strtolower($profile['region'])) {
|
||||
$parts[] = $profile['region'];
|
||||
}
|
||||
if(!empty($profile['country-name'])) {
|
||||
$parts[] = $profile['country-name'];
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if (count($parts)): ?>
|
||||
|
|
Before Width: | Height: | Size: 109 B After Width: | Height: | Size: 104 B |
Before Width: | Height: | Size: 608 B After Width: | Height: | Size: 589 B |
Wouldn't it be better if the sorting would be by the month of the last update and then the number of filled fields? Sorting after the filled fields at first could put someone at first who had filled out all fields - but hadn't been active for years.