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) => {