forked from GithubBackups/vichan
- Reworked tag weight.
Signed-off-by: 8n-tech <8n-tech@users.noreply.github.com>
This commit is contained in:
parent
0347bf772d
commit
67bab31510
@ -119,7 +119,6 @@ unset( $boardTags );
|
|||||||
|
|
||||||
/* Activity Fetching */
|
/* Activity Fetching */
|
||||||
$boardActivity = fetchBoardActivity( array_keys( $response['boards'] ), $search['time'], true );
|
$boardActivity = fetchBoardActivity( array_keys( $response['boards'] ), $search['time'], true );
|
||||||
$response['tags'] = array();
|
|
||||||
|
|
||||||
// Loop through each board and record activity to it.
|
// Loop through each board and record activity to it.
|
||||||
// We will also be weighing and building a tag list.
|
// We will also be weighing and building a tag list.
|
||||||
@ -141,21 +140,8 @@ foreach ($response['boards'] as $boardUri => &$board) {
|
|||||||
|
|
||||||
unset( $precision );
|
unset( $precision );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($board['tags']) && count($board['tags']) > 0) {
|
|
||||||
foreach ($board['tags'] as $tag) {
|
|
||||||
if (isset($response['tags'][$tag])) {
|
|
||||||
$response['tags'][$tag] += $board['active'];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$response['tags'][$tag] = $board['active'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unset( $boardActivity );
|
|
||||||
|
|
||||||
// Sort boards by their popularity, then by their total posts.
|
// Sort boards by their popularity, then by their total posts.
|
||||||
$boardActivityValues = array();
|
$boardActivityValues = array();
|
||||||
$boardTotalPostsValues = array();
|
$boardTotalPostsValues = array();
|
||||||
@ -177,16 +163,63 @@ $response['omitted'] = $search['index'] ? 0 : count( $response['boards'] ) - $bo
|
|||||||
$response['boards'] = array_splice( $response['boards'], 0, $boardLimit );
|
$response['boards'] = array_splice( $response['boards'], 0, $boardLimit );
|
||||||
$response['order'] = array_keys( $response['boards'] );
|
$response['order'] = array_keys( $response['boards'] );
|
||||||
|
|
||||||
// Get the top most popular tags.
|
|
||||||
if (count($response['tags']) > 0) {
|
|
||||||
// Sort by most active tags.
|
|
||||||
arsort( $response['tags'] );
|
|
||||||
// Get the first n most active tags.
|
|
||||||
$response['tags'] = array_splice( $response['tags'], 0, 100 );
|
|
||||||
|
|
||||||
// $tagLightest = end( array_keys( $response['tag'] ) );
|
// Loop through the truncated array to compile tags.
|
||||||
|
$response['tags'] = array();
|
||||||
|
$tagUsage = array( 'boards' => array(), 'users' => array() );
|
||||||
|
|
||||||
|
foreach ($response['boards'] as $boardUri => &$board) {
|
||||||
|
if (isset($board['tags']) && count($board['tags']) > 0) {
|
||||||
|
foreach ($board['tags'] as $tag) {
|
||||||
|
if (!isset($tagUsage['boards'][$tag])) {
|
||||||
|
$tagUsage['boards'][$tag] = 0;
|
||||||
|
}
|
||||||
|
if (!isset($tagUsage['users'][$tag])) {
|
||||||
|
$tagUsage['users'][$tag] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$response['tags'][$tag] = true;
|
||||||
|
++$tagUsage['boards'][$tag];
|
||||||
|
$tagUsage['users'][$tag] += $board['active'];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the top most popular tags.
|
||||||
|
if (count($response['tags']) > 0) {
|
||||||
|
arsort( $tagUsage['boards'] );
|
||||||
|
arsort( $tagUsage['users'] );
|
||||||
|
|
||||||
|
array_multisort(
|
||||||
|
$tagUsage['boards'], SORT_DESC, SORT_NUMERIC,
|
||||||
|
$tagUsage['users'], SORT_DESC, SORT_NUMERIC,
|
||||||
|
$response['tags']
|
||||||
|
);
|
||||||
|
|
||||||
|
// Get the first n most active tags.
|
||||||
|
$response['tags'] = array_splice( $response['tags'], 0, 100 );
|
||||||
|
$response['tagOrder'] = array_keys( $response['tags'] );
|
||||||
|
$response['tagWeight'] = array();
|
||||||
|
|
||||||
|
$tagsMostUsers = max( $tagUsage['users'] );
|
||||||
|
$tagsLeastUsers = min( $tagUsage['users'] );
|
||||||
|
$tagsAvgUsers = array_sum( $tagUsage['users'] ) / count( $tagUsage['users'] );
|
||||||
|
|
||||||
|
$weightDepartureFurthest = 0;
|
||||||
|
|
||||||
|
foreach ($tagUsage['users'] as $tagUsers) {
|
||||||
|
$weightDeparture = abs( $tagUsers - $tagsAvgUsers );
|
||||||
|
|
||||||
|
if( $weightDeparture > $weightDepartureFurthest ) {
|
||||||
|
$weightDepartureFurthest = $weightDeparture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($tagUsage['users'] as $tagName => $tagUsers) {
|
||||||
|
$weightDeparture = abs( $tagUsers - $tagsAvgUsers );
|
||||||
|
$response['tagWeight'][$tagName] = 75 + round( 100 * ( $weightDeparture / $weightDepartureFurthest ), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Include our interpreted search terms. */
|
/* Include our interpreted search terms. */
|
||||||
$response['search'] = $search;
|
$response['search'] = $search;
|
||||||
|
@ -19,8 +19,8 @@ if (count($searchJson)) {
|
|||||||
if (isset($searchJson['boards'])) {
|
if (isset($searchJson['boards'])) {
|
||||||
$boards = $searchJson['boards'];
|
$boards = $searchJson['boards'];
|
||||||
}
|
}
|
||||||
if (isset($searchJson['tags'])) {
|
if (isset($searchJson['tagWeight'])) {
|
||||||
$tags = $searchJson['tags'];
|
$tags = $searchJson['tagWeight'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1043,6 +1043,15 @@ span.pln {
|
|||||||
min-height: 76px;
|
min-height: 76px;
|
||||||
min-width: 128px;
|
min-width: 128px;
|
||||||
}
|
}
|
||||||
|
.loading-small {
|
||||||
|
background: none;
|
||||||
|
background-color: none;
|
||||||
|
background-image: url('/static/infinity-small.gif');
|
||||||
|
background-position: center center;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
min-height: 24px;
|
||||||
|
min-width: 48px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Responsive helpers */
|
/* Responsive helpers */
|
||||||
@ -1378,6 +1387,18 @@ table.board-list-table .board-tags {
|
|||||||
padding: 0 15px 0 4px;
|
padding: 0 15px 0 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table.board-list-table .board-uri .board-nsfw {
|
||||||
|
color: rgb(230,0,0);
|
||||||
|
margin: 0 0 0 0.6em;
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
table.board-list-table .board-uri .board-sfw {
|
||||||
|
/* I'm using blue instead of green to help users with Deuteranopia (most common form of colorblndness). */
|
||||||
|
color: rgb(0,0,230);
|
||||||
|
margin: 0 0 0 0.6em;
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
table.board-list-table div.board-cell {
|
table.board-list-table div.board-cell {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@ -1397,9 +1418,7 @@ aside.search-container .box {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.board-search {
|
.board-search {
|
||||||
padding: 0 0 8px 0;
|
margin: 8px 0;
|
||||||
margin: 8px;
|
|
||||||
border-bottom: 1px solid #000333;
|
|
||||||
}
|
}
|
||||||
.search-item {
|
.search-item {
|
||||||
margin: 8px 0;
|
margin: 8px 0;
|
||||||
@ -1427,12 +1446,17 @@ aside.search-container .box {
|
|||||||
min-width: 100%;
|
min-width: 100%;
|
||||||
width: 100%:
|
width: 100%:
|
||||||
}
|
}
|
||||||
|
#search-loading {
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: bottom;
|
||||||
|
}
|
||||||
|
|
||||||
ul.tag-list {
|
ul.tag-list {
|
||||||
display: block;
|
display: block;
|
||||||
list-style: none;
|
list-style: none;
|
||||||
padding: 0;
|
margin: 8px 8px -9px 8px;
|
||||||
margin: 0 8px;
|
padding: 8px 0 0 0;
|
||||||
|
border-top: 1px solid #000333;
|
||||||
}
|
}
|
||||||
ul.tag-list::after {
|
ul.tag-list::after {
|
||||||
content: ' ';
|
content: ' ';
|
||||||
@ -1445,7 +1469,10 @@ li.tag-item {
|
|||||||
font-size: 100%;
|
font-size: 100%;
|
||||||
list-style: none;
|
list-style: none;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0 0.6em 0 0;
|
padding: 0 4px 0 0;
|
||||||
|
}
|
||||||
|
li.tag-item:last-child {
|
||||||
|
padding-bottom: 17px;
|
||||||
}
|
}
|
||||||
a.tag-link {
|
a.tag-link {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{% for tag, weight in tags %}
|
{% for tag, weight in tags %}
|
||||||
<li class="tag-item">
|
<li class="tag-item">
|
||||||
<a class="tag-link" href="#">{{tag}}</a>
|
<a class="tag-link" href="#" style="font-size: {{weight}}%;">{{tag}}</a>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
Loading…
x
Reference in New Issue
Block a user