From b716a0ed5c2816d76a434ad3fdc66287971b5b2b Mon Sep 17 00:00:00 2001 From: Howard Date: Fri, 30 May 2025 01:04:51 +0800 Subject: [PATCH] Made the check words system much more useable, without the user's device being spammed with garbage requests. --- components/app/windows/news.vue | 28 +++++++++++++++++++++------- pages/desktop.vue | 4 +++- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/components/app/windows/news.vue b/components/app/windows/news.vue index 3aa6022..9861b1a 100644 --- a/components/app/windows/news.vue +++ b/components/app/windows/news.vue @@ -147,17 +147,20 @@ const findRel = async (title: string) => { const req = await fetch("/api/sort"); }; +// Check words +const checkIfEmptyArray = []; const useArgFindRel = (title, newsOrg) => { const targetVector = tf(title); const similarities = []; for (const item of contentArray.value) { - if (item.title !== title && item.contentType === "GENERAL" && item.publisher === newsOrg) { - console.log(item.title); + if ( + item.title !== title && + item.contentType === "GENERAL" && + item.publisher === newsOrg + ) { const itemVector = tf(item.title); - console.log(itemVector); const similarity = jaccardSimilarity(targetVector, itemVector); - console.log(similarity); if (similarity > 0.1) { similarities.push({ title: item.title, @@ -165,12 +168,22 @@ const useArgFindRel = (title, newsOrg) => { item: item, }); } - console.log(similarities); } } + const idx = checkIfEmptyArray.findIndex((x) => x.title === title); + if (idx !== -1) checkIfEmptyArray.splice(idx, 1); + checkIfEmptyArray.push({ + title: title, + contains: similarities.length === 0, + }); return similarities.sort((a, b) => b.similarity - a.similarity).slice(0, 3); }; +const checkIfEmpty = (item) => { + const found = checkIfEmptyArray.find((key) => key.title === item); + return found ? found.contains : false; +}; + const openNews = (url: string, titleName: string) => { emit("openArticles", url, titleName); }; @@ -273,6 +286,7 @@ const openPublisher = (text: string) => {

類似文章

{ :key="similar.item.id" class="p-2 bg-gray-100 rounded text-sm cursor-pointer hover:bg-gray-200" @click="openNews(similar.item.url.hash, item.title)" - v-if="similar" >
{{ similar.title }}
@@ -288,8 +301,9 @@ const openPublisher = (text: string) => { {{ similar.item.publisher }}
-
找不到類似文章
+
找不到類似文章
+