From 64938cd1aedb5fef5a4a706cc2b1059336b750fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D9=81=D8=A7=D8=B7=D9=85=D9=87=20=D8=AA=D9=82=DB=8C=20?= =?UTF-8?q?=D9=BE=D9=88=D8=B1?= <20+f.taghipour@noreply.localhost> Date: Tue, 10 Nov 2026 10:33:04 +0000 Subject: [PATCH] Update search.js --- search.js | 57 +++++++++++++++---------------------------------------- 1 file changed, 15 insertions(+), 42 deletions(-) diff --git a/search.js b/search.js index eb12b4a..4627519 100644 --- a/search.js +++ b/search.js @@ -1,19 +1,18 @@ - let documents = []; const searchInput = document.getElementById("searchInput"); const results = document.getElementById("results"); const status = document.getElementById("status"); -// لینک مستقیم فایل CSV در مخزن Git +// آدرس فایل CSV + const CSV_URL = "https://git.sadentel.net/f.taghipour/Document/raw/branch/main/SadenTel_Documents.csv"; - -// یکسانسازی حروف و اعداد +// یکسانسازی متن و اعداد function normalize(value) { return String(value ?? "") - .trim() .toLowerCase() + .trim() .replace(/[۰-۹]/g, digit => "۰۱۲۳۴۵۶۷۸۹".indexOf(digit) ) @@ -24,8 +23,7 @@ function normalize(value) { .replace(/ك/g, "ک"); } - -// پردازش فایل CSV +// پردازش CSV function parseCSV(text) { const rows = []; let row = []; @@ -42,14 +40,10 @@ function parseCSV(text) { } else { insideQuotes = !insideQuotes; } - } - - else if (char === "," && !insideQuotes) { + } else if (char === "," && !insideQuotes) { row.push(field); field = ""; - } - - else if ( + } else if ( (char === "\n" || char === "\r") && !insideQuotes ) { @@ -65,9 +59,7 @@ function parseCSV(text) { row = []; field = ""; - } - - else { + } else { field += char; } } @@ -81,12 +73,10 @@ function parseCSV(text) { return rows; } - -// دریافت اطلاعات از لینک آنلاین CSV +// دریافت اطلاعات CSV async function loadDocuments() { try { searchInput.disabled = true; - status.textContent = "در حال دریافت اسناد..."; const response = await fetch(CSV_URL, { @@ -94,11 +84,10 @@ async function loadDocuments() { }); if (!response.ok) { - throw new Error("CSV file could not be loaded"); + throw new Error(`HTTP Error: ${response.status}`); } const text = await response.text(); - const rows = parseCSV(text); documents = rows.slice(1).map(columns => ({ @@ -113,18 +102,15 @@ async function loadDocuments() { searchInput.disabled = false; } catch (error) { - status.textContent = - "خطا در دریافت اطلاعات. دسترسی به فایل CSV را بررسی کنید."; + "خطا در دریافت اطلاعات. مسیر فایل CSV را بررسی کنید."; console.error("Loading error:", error); } } - // جستوجوی اسناد function searchDocuments() { - const query = normalize(searchInput.value); results.innerHTML = ""; @@ -136,35 +122,25 @@ function searchDocuments() { } const matches = documents.filter(doc => { + const titleWords = + normalize(doc.title).match(/[\p{L}\p{N}]+/gu) || []; - const title = normalize(doc.title); const id = normalize(doc.id); - // استخراج کلمات کامل عنوان - const titleWords = - title.match(/[\p{L}\p{N}]+/gu) || []; - - // تطابق کامل کلمه یا شناسه + // فقط تطابق کامل کلمه یا شناسه return titleWords.includes(query) || id === query; }); - console.log("Search query:", query); - console.table(matches); - status.textContent = `${matches.length} نتیجه پیدا شد.`; if (matches.length === 0) { - results.innerHTML = '