Improve result sorting #59

Merged
MrPetovan merged 6 commits from task/improve-result-sorting into master 2018-11-01 16:35:12 +01:00
16 changed files with 69 additions and 39 deletions

View File

@ -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`);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 346 B

After

Width:  |  Height:  |  Size: 325 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 490 B

After

Width:  |  Height:  |  Size: 469 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 109 B

After

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 132 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 608 B

After

Width:  |  Height:  |  Size: 589 B

View File

@ -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())
);

View File

@ -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';
}
annando commented 2018-11-01 07:48:31 +01:00 (Migrated from github.com)
Review

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.

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.
MrPetovan commented 2018-11-01 12:33:17 +01:00 (Migrated from github.com)
Review

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.

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.
annando commented 2018-11-01 12:52:07 +01:00 (Migrated from github.com)
Review

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.
MrPetovan commented 2018-11-01 12:55:25 +01:00 (Migrated from github.com)
Review

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.
annando commented 2018-11-01 13:10:14 +01:00 (Migrated from github.com)
Review

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.
MrPetovan commented 2018-11-01 15:24:24 +01:00 (Migrated from github.com)
Review

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 ",

View File

@ -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'])
);

View File

@ -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)): ?>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 109 B

After

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 608 B

After

Width:  |  Height:  |  Size: 589 B