ツール管理へ戻る

v2 → v3 の差分

--- v2
+++ v3
@@ -85,8 +85,7 @@
 
     input[type="date"],
     input[type="text"],
-    input[type="file"],
-    select {
+    input[type="file"] {
       max-width: 100%;
       padding: 9px 10px;
       border: 1px solid #9ba6b2;
@@ -117,13 +116,6 @@
       flex-wrap: wrap;
       gap: 10px 18px;
       margin: 8px 0;
-    }
-
-    .scope-grid {
-      display: grid;
-      grid-template-columns: repeat(2, minmax(0, 1fr));
-      gap: 6px 16px;
-      margin-top: 8px;
     }
 
     .buttons {
@@ -154,6 +146,11 @@
 
     button.secondary:hover { background: #f0f2f4; }
 
+    button:disabled {
+      opacity: .55;
+      cursor: not-allowed;
+    }
+
     #status {
       min-height: 1.6em;
       margin: 12px 0;
@@ -196,7 +193,7 @@
       font-size: .9rem;
     }
 
-    .excerpt {
+    .excerpt, .summary-output {
       margin: 10px 0;
       padding: 10px 12px;
       border-left: 3px solid var(--accent);
@@ -211,6 +208,13 @@
       font-weight: 700;
     }
 
+    .summary-output {
+      border-left-color: #6c4aa1;
+      background: #f7f4fb;
+    }
+
+    .summary-output[hidden] { display: none; }
+
     mark {
       padding: 0 2px;
       background: #fff1a8;
@@ -230,7 +234,7 @@
         padding: 16px;
       }
 
-      .grid, .scope-grid { grid-template-columns: 1fr; }
+      .grid { grid-template-columns: 1fr; }
     }
   </style>
 </head>
@@ -239,7 +243,7 @@
     <h1>是正処置記録検索</h1>
     <p class="intro">
       選択したファイルをブラウザ内で検索します。ファイルや検索内容を外部へ送信・自動保存しません。
-      外部AIサービスへの接続も行いません。
+      このページは外部AIサービスに接続せず、生成AIによる分析・要約は行いません。
     </p>
 
     <form id="searchForm">
@@ -251,7 +255,6 @@
           <p class="help">
             このページで内容を読み取れるのはCSV・TXTです。Excel形式(.xlsx/.xlsm/.xls)は
             ブラウザ標準機能だけではセル内容を解析できないため、ファイル名のみ検索します。
-            Excel内部の「原因」「対策」欄も検索するには、オフライン対応のExcel解析機能が別途必要です。
           </p>
         </div>
       </fieldset>
@@ -349,14 +352,18 @@
         .map(function (input) { return input.value; });
     }
 
-    function parseDate(value) {
+    function normalize(text) {
+      return String(text || "").toLocaleLowerCase("ja");
+    }
+
+    function findDate(text) {
       const patterns = [
         /(\d{4})[-.\/](\d{1,2})[-.\/](\d{1,2})/,
         /(\d{4})年(\d{1,2})月(\d{1,2})日/
       ];
 
       for (const pattern of patterns) {
-        const match = String(value).match(pattern);
+        const match = String(text).match(pattern);
         if (!match) continue;
 
         const year = Number(match[1]);
@@ -373,19 +380,6 @@
             String(day).padStart(2, "0");
         }
       }
-
-      return null;
-    }
-
-    function findDate(text) {
-      const matches = String(text).match(
-        /\d{4}[-.\/]\d{1,2}[-.\/]\d{1,2}|\d{4}年\d{1,2}月\d{1,2}日/g
-      ) || [];
-
-      for (const value of matches) {
-        const date = parseDate(value);
-        if (date) return date;
-      }
       return null;
     }
 
@@ -396,17 +390,13 @@
       }) || "部門不明";
     }
 
-    function normalize(text) {
-      return String(text || "").toLocaleLowerCase("ja");
-    }
-
-    function wordMatch(text, keywords, mode) {
-      if (keywords.length === 0) return true;
-      const target = normalize(text);
-      const found = keywords.map(function (word) {
-        return target.includes(normalize(word));
+    function wordMatch(text, terms, mode) {
+      if (!terms.length) return true;
+      const normalizedText = normalize(text);
+      const results = terms.map(function (term) {
+        return normalizedText.includes(normalize(term));
       });
-      return mode === "OR" ? found.some(Boolean) : found.every(Boolean);
+      return mode === "OR" ? results.some(Boolean) : results.every(Boolean);
     }
 
     function splitSentences(text) {
@@ -415,14 +405,6 @@
         .split(/[\n。!?!?;;]+/)
         .map(function (part) { return part.trim(); })
         .filter(Boolean);
-    }
-
-    function findHeaderColumn(headers, patterns) {
-      return headers.findIndex(function (header) {
-        return patterns.some(function (pattern) {
-          return pattern.test(String(header || "").trim());
-        });
-      });
     }
 
     function parseCsvLine(line) {
@@ -453,18 +435,23 @@
     }
 
     function parseCsv(text) {
-      const lines = String(text).replace(/^\uFEFF/, "").split(/\r?\n/);
-      const nonEmptyLines = lines.filter(function (line) {
-        return line.trim() !== "";
+      const lines = String(text).replace(/^\uFEFF/, "").split(/\r?\n/)
+        .filter(function (line) { return line.trim() !== ""; });
+
+      if (!lines.length) return { headers: [], rows: [] };
+
+      return {
+        headers: parseCsvLine(lines[0]),
+        rows: lines.slice(1).map(parseCsvLine)
+      };
+    }
+
+    function findColumn(headers, patterns) {
+      return headers.findIndex(function (header) {
+        return patterns.some(function (pattern) {
+          return pattern.test(String(header || "").trim());
+        });
       });
-
-      if (nonEmptyLines.length === 0) {
-        return { headers: [], rows: [] };
-      }
-
-      const headers = parseCsvLine(nonEmptyLines[0]);
-      const rows = nonEmptyLines.slice(1).map(parseCsvLine);
-      return { headers: headers, rows: rows };
     }
 
     function getRecordFields(file, text) {
@@ -474,63 +461,62 @@
         cause: "",
         action: "",
         allText: file.name,
-        date: findDate(file.name) || null
+        date: findDate(file.name)
       };
+
+      if (extension === "csv") {
+        result.readable = true;
+        const parsed = parseCsv(text);
+        const causeIndex = findColumn(parsed.headers, [/原因/, /発生要因/, /真因/]);
+        const actionIndex = findColumn(parsed.headers, [/対策/, /処置/, /再発防止/]);
+        const dateIndex = findColumn(parsed.headers, [/日付/, /発生日/, /処置日/, /記録日/]);
+        const allValues = [file.name];
+        const causes = [];
+        const actions = [];
+
+        parsed.rows.forEach(function (row) {
+          allValues.push(row.join(" "));
+          if (causeIndex >= 0 && row[causeIndex]) causes.push(row[causeIndex]);
+          if (actionIndex >= 0 && row[actionIndex]) actions.push(row[actionIndex]);
+          if (!result.date && dateIndex >= 0 && row[dateIndex]) {
+            result.date = findDate(row[dateIndex]);
+          }
+        });
+
+        result.cause = causes.join("\n");
+        result.action = actions.join("\n");
+        result.allText = allValues.join("\n");
+        return result;
+      }
 
       if (extension === "txt") {
         result.readable = true;
         result.allText = file.name + "\n" + text;
         result.date = result.date || findDate(text);
 
-        const causeLines = [];
-        const actionLines = [];
-        let current = "";
+        const causes = [];
+        const actions = [];
+        let currentSection = "";
 
         text.split(/\r?\n/).forEach(function (line) {
           const trimmed = line.trim();
+          if (!trimmed) return;
+
           if (/原因|発生要因|真因/.test(trimmed)) {
-            current = "cause";
-            causeLines.push(trimmed.replace(/^(不具合の)?原因[::\s]*/, ""));
+            currentSection = "cause";
+            causes.push(trimmed.replace(/^(不具合の)?原因[::\s]*/, ""));
           } else if (/対策|処置|再発防止/.test(trimmed)) {
-            current = "action";
-            actionLines.push(trimmed.replace(/^(不具合に対する)?対策[::\s]*/, ""));
-          } else if (current === "cause" && trimmed) {
-            causeLines.push(trimmed);
-          } else if (current === "action" && trimmed) {
-            actionLines.push(trimmed);
+            currentSection = "action";
+            actions.push(trimmed.replace(/^(不具合に対する)?対策[::\s]*/, ""));
+          } else if (currentSection === "cause") {
+            causes.push(trimmed);
+          } else if (currentSection === "action") {
+            actions.push(trimmed);
           }
         });
 
-        result.cause = causeLines.join("\n");
-        result.action = actionLines.join("\n");
-        return result;
-      }
-
-      if (extension === "csv") {
-        result.readable = true;
-        const parsed = parseCsv(text);
-        const headers = parsed.headers;
-        const causeIndex = findHeaderColumn(headers, [/原因/, /発生要因/, /真因/]);
-        const actionIndex = findHeaderColumn(headers, [/対策/, /処置/, /再発防止/]);
-        const dateIndex = findHeaderColumn(headers, [/日付/, /発生日/, /処置日/, /記録日/]);
-
-        const causeValues = [];
-        const actionValues = [];
-        const allValues = [file.name];
-
-        parsed.rows.forEach(function (row) {
-          allValues.push(row.join(" "));
-          if (causeIndex >= 0 && row[causeIndex]) causeValues.push(row[causeIndex]);
-          if (actionIndex >= 0 && row[actionIndex]) actionValues.push(row[actionIndex]);
-          if (!result.date && dateIndex >= 0 && row[dateIndex]) {
-            result.date = findDate(row[dateIndex]);
-          }
-        });
-
-        result.cause = causeValues.join("\n");
-        result.action = actionValues.join("\n");
-        result.allText = allValues.join("\n");
-        return result;
+        result.cause = causes.join("\n");
+        result.action = actions.join("\n");
       }
 
       return result;
@@ -543,10 +529,10 @@
       const sorted = terms.slice().sort(function (a, b) {
         return b.length - a.length;
       });
-      const escaped = sorted.map(function (term) {
+      const escapedTerms = sorted.map(function (term) {
         return term.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
       });
-      const pattern = new RegExp("(" + escaped.join("|") + ")", "giu");
+      const pattern = new RegExp("(" + escapedTerms.join("|") + ")", "giu");
 
       return value.split(pattern).map(function (part) {
         const matched = sorted.some(function (term) {
@@ -560,13 +546,63 @@
       const sentences = splitSentences(text);
       if (!sentences.length) return [];
 
-      if (!terms.length) return sentences.slice(0, 3);
+      if (!terms.length) return sentences.slice(0, 5);
 
       return sentences.filter(function (sentence) {
         return terms.some(function (term) {
           return normalize(sentence).includes(normalize(term));
         });
       }).slice(0, 5);
+    }
+
+    function makeExcerptBox(label, text, terms, readable) {
+      const box = document.createElement("div");
+      box.className = "excerpt";
+
+      const heading = document.createElement("span");
+      heading.className = "excerpt-label";
+      heading.textContent = label;
+      box.appendChild(heading);
+
+      const excerpts = relevantExcerpts(text, terms);
+      if (excerpts.length) {
+        excerpts.forEach(function (excerpt) {
+          const line = document.createElement("div");
+          line.innerHTML = highlight(excerpt, terms);
+          box.appendChild(line);
+        });
+      } else {
+        const message = document.createElement("span");
+        message.textContent = readable
+          ? "キーワードに一致する文章は見つかりませんでした。"
+          : "ファイル内容を読み取れないため抽出できません。";
+        box.appendChild(message);
+      }
+
+      return box;
+    }
+
+    function makeLocalSummary(record, terms) {
+      const causes = relevantExcerpts(record.cause, terms);
+      const actions = relevantExcerpts(record.action, terms);
+      const parts = [];
+
+      if (causes.length) {
+        parts.push("原因:" + causes.join("。"));
+      }
+      if (actions.length) {
+        parts.push("対策:" + actions.join("。"));
+      }
+
+      if (!record.readable) {
+        return "このファイル形式の内容は読み取れないため、要約できません。";
+      }
+      if (!parts.length) {
+        return "検索語に一致する原因・対策の文章が見つからず、整理できる情報がありません。";
+      }
+
+      return parts.join("\n\n") +
+        "\n\n※これはAIによる要約ではなく、検索語に一致した文章を項目別に並べたものです。";
     }
 
     function renderResults(records, terms) {
@@ -585,7 +621,7 @@
         return;
       }
 
-      records.forEach(function (record) {
+      records.forEach(function (record, index) {
         const card = document.createElement("article");
         card.className = "result-card";
 
@@ -598,61 +634,46 @@
         meta.textContent =
           "部門:" + record.department +
           " / 日付:" + (record.date || "見つかりません") +
-          " / 内容を読める形式:" + (record.readable ? "はい" : "いいえ");
+          " / ファイル内容を読み取れる形式:" + (record.readable ? "はい" : "いいえ");
         card.appendChild(meta);
 
-        const causeBox = document.createElement("div");
-        causeBox.className = "excerpt";
-        const causeLabel = document.createElement("span");
-        causeLabel.className = "excerpt-label";
-        causeLabel.textContent = "不具合の原因";
-        causeBox.appendChild(causeLabel);
-
-        const causeExcerpts = relevantExcerpts(record.cause, terms);
-        if (causeExcerpts.length) {
-          causeBox.insertAdjacentHTML(
-            "beforeend",
-            causeExcerpts.map(function (item) {
-              return "<div>" + highlight(item, terms) + "</div>";
-            }).join("")
-          );
-        } else {
-          const noCause = document.createElement("span");
-          noCause.textContent = record.readable
-            ? "キーワードに一致する原因の文章は見つかりませんでした。"
-            : "ファイル内容を読み取れないため抽出できません。";
-          causeBox.appendChild(noCause);
-        }
-        card.appendChild(causeBox);
-
-        const actionBox = document.createElement("div");
-        actionBox.className = "excerpt";
-        const actionLabel = document.createElement("span");
-        actionLabel.className = "excerpt-label";
-        actionLabel.textContent = "不具合に対する対策";
-        actionBox.appendChild(actionLabel);
-
-        const actionExcerpts = relevantExcerpts(record.action, terms);
-        if (actionExcerpts.length) {
-          actionBox.insertAdjacentHTML(
-            "beforeend",
-            actionExcerpts.map(function (item) {
-              return "<div>" + highlight(item, terms) + "</div>";
-            }).join("")
-          );
-        } else {
-          const noAction = document.createElement("span");
-          noAction.textContent = record.readable
-            ? "キーワードに一致する対策の文章は見つかりませんでした。"
-            : "ファイル内容を読み取れないため抽出できません。";
-          actionBox.appendChild(noAction);
-        }
-        card.appendChild(actionBox);
+        card.appendChild(makeExcerptBox("不具合の原因", record.cause, terms, record.readable));
+        card.appendChild(makeExcerptBox("不具合に対する対策", record.action, terms, record.readable));
+
+        const summarizeButton = document.createElement("button");
+        summarizeButton.type = "button";
+        summarizeButton.className = "summary-button";
+        summarizeButton.textContent = "AIによる要約";
+        summarizeButton.setAttribute("aria-expanded", "false");
+        summarizeButton.setAttribute("aria-controls", "summary-" + index);
+
+        const output = document.createElement("div");
+        output.id = "summary-" + index;
+        output.className = "summary-output";
+        output.hidden = true;
+        output.setAttribute("role", "region");
+        output.setAttribute("aria-label", "要約表示欄");
+
+        summarizeButton.addEventListener("click", function () {
+          const willShow = output.hidden;
+          if (willShow) {
+            output.textContent = makeLocalSummary(record, terms);
+            output.hidden = false;
+            summarizeButton.setAttribute("aria-expanded", "true");
+          } else {
+            output.hidden = true;
+            summarizeButton.setAttribute("aria-expanded", "false");
+          }
+        });
+
+        card.appendChild(summarizeButton);
+        card.appendChild(output);
 
         const note = document.createElement("p");
         note.className = "help";
         note.textContent =
-          "表示内容はキーワードに一致した文章の抜粋です。AIによる分析・要約は行っていません。";
+          "ボタン押下時に表示するのは、検索語に一致した文章を原因・対策別に並べたものです。" +
+          "生成AIによる分析や文章の言い換えは行いません。";
         card.appendChild(note);
 
         resultsBox.appendChild(card);
@@ -682,11 +703,12 @@
       }
 
       const incident = document.getElementById("incident").value.trim();
-      const extraKeywords = document.getElementById("keywords").value
+      const additional = document.getElementById("keywords").value
         .trim().split(/\s+/).filter(Boolean);
       const terms = [];
+
       if (incident) terms.push(incident);
-      extraKeywords.forEach(function (word) {
+      additional.forEach(function (word) {
         if (!terms.some(function (existing) {
           return normalize(existing) === normalize(word);
         })) {
@@ -705,40 +727,40 @@
           const department = getDepartment(file.name);
           if (!departments.includes(department)) continue;
 
+          const extension = file.name.toLowerCase().split(".").pop();
           let text = "";
-          const extension = file.name.toLowerCase().split(".").pop();
+
           if (extension === "csv" || extension === "txt") {
             text = await file.text();
           }
 
-          const record = getRecordFields(file, text);
-          const fileDate = record.date || findDate(file.name);
-
-          if ((startDate || endDate) && !fileDate) continue;
-          if (startDate && fileDate < startDate) continue;
-          if (endDate && fileDate > endDate) continue;
-
-          const searchableText = record.readable
-            ? record.allText + "\n" + record.cause + "\n" + record.action
+          const fields = getRecordFields(file, text);
+          const date = fields.date || findDate(file.name);
+
+          if ((startDate || endDate) && !date) continue;
+          if (startDate && date < startDate) continue;
+          if (endDate && date > endDate) continue;
+
+          const searchable = fields.readable
+            ? fields.allText + "\n" + fields.cause + "\n" + fields.action
             : file.name;
 
-          if (!wordMatch(searchableText, terms, mode)) continue;
+          if (!wordMatch(searchable, terms, mode)) continue;
 
           records.push({
             name: file.name,
             department: department,
-            date: fileDate,
-            readable: record.readable,
-            cause: record.cause,
-            action: record.action
+            date: date,
+            readable: fields.readable,
+            cause: fields.cause,
+            action: fields.action
           });
         }
 
         renderResults(records, terms);
         setStatus(
           "検索完了:" + records.length +
-          " 件。CSV・TXTは原因・対策欄の文章をキーワードで抽出しました。" +
-          " Excel形式の内部内容およびAI分析は対象外です。",
+          " 件。CSV・TXTでは原因・対策文章を抽出します。Excel内部の解析と生成AIによる要約は行いません。",
           "success"
         );
       } catch (error) {