From ebde84214e57eb5a3af9f28a6671710d78232bfd Mon Sep 17 00:00:00 2001
From: syuilo <syuilotan@yahoo.co.jp>
Date: Tue, 12 Jun 2018 02:00:05 +0900
Subject: [PATCH] Improve hashtag trend detection

---
 src/server/api/endpoints/hashtags/trend.ts | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/server/api/endpoints/hashtags/trend.ts b/src/server/api/endpoints/hashtags/trend.ts
index 43048c1c9f..efd74a21e0 100644
--- a/src/server/api/endpoints/hashtags/trend.ts
+++ b/src/server/api/endpoints/hashtags/trend.ts
@@ -8,6 +8,7 @@ import Note from '../../../../models/note';
 const rangeA = 1000 * 60 * 30; // 30分
 const rangeB = 1000 * 60 * 120; // 2時間
 const coefficient = 1.5; // 「n倍」の部分
+const requiredUsers = 3; // 最低何人がそのタグを投稿している必要があるか
 
 /**
  * Get trends of hashtags
@@ -42,7 +43,7 @@ module.exports = () => new Promise(async (res, rej) => {
 		return res([]);
 	}
 
-	const tags = [];
+	let tags = [];
 
 	// カウント
 	data.map(x => x._id).forEach(x => {
@@ -57,6 +58,9 @@ module.exports = () => new Promise(async (res, rej) => {
 		}
 	});
 
+	// 最低要求投稿者数を下回るならカットする
+	tags = tags.filter(tag => tag.count >= requiredUsers);
+
 	//#region 2. 1で取得したそれぞれのタグについて、「直近a分間のユニーク投稿数が今からa分前~今からb分前の間のユニーク投稿数のn倍以上」かどうかを判定する
 	const hotsPromises = tags.map(async tag => {
 		const passedCount = (await Note.distinct('userId', {