ツール管理へ戻る

v4 → v5 の差分

--- v4
+++ v5
@@ -193,24 +193,35 @@
       font-size: .9rem;
     }
 
-    .excerpt, .summary-output {
-      margin: 10px 0;
-      padding: 10px 12px;
+    .result-section {
+      margin: 12px 0;
+      padding: 12px;
+      border: 1px solid var(--line);
+      border-radius: 6px;
+      background: #fff;
+    }
+
+    .result-section h4 {
+      margin: 0 0 8px;
+      font-size: .98rem;
+    }
+
+    .excerpt {
+      margin: 6px 0;
+      padding: 9px 11px;
       border-left: 3px solid var(--accent);
       background: #f6f8fa;
       white-space: pre-wrap;
       overflow-wrap: anywhere;
     }
 
-    .excerpt-label {
-      display: block;
-      margin-bottom: 4px;
-      font-weight: 700;
-    }
-
     .summary-output {
-      border-left-color: #6c4aa1;
+      margin: 10px 0;
+      padding: 10px 12px;
+      border-left: 3px solid #6c4aa1;
       background: #f7f4fb;
+      white-space: pre-wrap;
+      overflow-wrap: anywhere;
     }
 
     .summary-output[hidden] { display: none; }
@@ -243,7 +254,7 @@
     <h1>是正処置記録検索</h1>
     <p class="intro">
       選択したファイルをブラウザ内で検索します。ファイルや検索内容を外部へ送信・自動保存しません。
-      このページは外部AIサービスに接続せず、生成AIによる分析・要約は行いません。
+      外部AIサービスへの接続は行いません。
     </p>
 
     <form id="searchForm">
@@ -271,6 +282,7 @@
             <input id="endDate" type="date">
           </div>
         </div>
+
         <div class="field" style="margin-top: 12px">
           <span class="title"><strong>対象部門</strong></span>
           <div class="checks">
@@ -278,6 +290,7 @@
             <label><input type="checkbox" name="department" value="時計製造部門" checked> 時計製造部門</label>
           </div>
         </div>
+
         <p class="help">
           期間指定時はファイル名またはCSV・TXT内の日付から判定します。
           対応する日付表記は YYYY-MM-DD、YYYY/MM/DD、YYYY年M月D日 です。
@@ -347,13 +360,13 @@
       });
     }
 
+    function normalize(text) {
+      return String(text || "").toLocaleLowerCase("ja");
+    }
+
     function selectedDepartments() {
       return Array.from(document.querySelectorAll('input[name="department"]:checked'))
         .map(function (input) { return input.value; });
-    }
-
-    function normalize(text) {
-      return String(text || "").toLocaleLowerCase("ja");
     }
 
     function findDate(text) {
@@ -392,11 +405,13 @@
 
     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));
+
+      const target = normalize(text);
+      const matches = terms.map(function (term) {
+        return target.includes(normalize(term));
       });
-      return mode === "OR" ? results.some(Boolean) : results.every(Boolean);
+
+      return mode === "OR" ? matches.some(Boolean) : matches.every(Boolean);
     }
 
     function splitSentences(text) {
@@ -456,46 +471,55 @@
 
     function getRecordFields(file, text) {
       const extension = file.name.toLowerCase().split(".").pop();
-      const result = {
+      const fields = {
         readable: false,
         cause: "",
         action: "",
+        effect: "",
         allText: file.name,
         date: findDate(file.name)
       };
 
       if (extension === "csv") {
-        result.readable = true;
+        fields.readable = true;
         const parsed = parseCsv(text);
         const causeIndex = findColumn(parsed.headers, [/原因/, /発生要因/, /真因/]);
         const actionIndex = findColumn(parsed.headers, [/対策/, /処置/, /再発防止/]);
+        const effectIndex = findColumn(parsed.headers, [/効果/, /レビュー/, /確認結果/, /有効性/]);
         const dateIndex = findColumn(parsed.headers, [/日付/, /発生日/, /処置日/, /記録日/]);
-        const allValues = [file.name];
+
         const causes = [];
         const actions = [];
+        const effects = [];
+        const allValues = [file.name];
 
         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]);
+          if (effectIndex >= 0 && row[effectIndex]) effects.push(row[effectIndex]);
+          if (!fields.date && dateIndex >= 0 && row[dateIndex]) {
+            fields.date = findDate(row[dateIndex]);
           }
         });
 
-        result.cause = causes.join("\n");
-        result.action = actions.join("\n");
-        result.allText = allValues.join("\n");
-        return result;
+        fields.cause = causes.join("\n");
+        fields.action = actions.join("\n");
+        fields.effect = effects.join("\n");
+        fields.allText = allValues.join("\n");
+        return fields;
       }
 
       if (extension === "txt") {
-        result.readable = true;
-        result.allText = file.name + "\n" + text;
-        result.date = result.date || findDate(text);
-
-        const causes = [];
-        const actions = [];
+        fields.readable = true;
+        fields.allText = file.name + "\n" + text;
+        fields.date = fields.date || findDate(text);
+
+        const sections = {
+          cause: [],
+          action: [],
+          effect: []
+        };
         let currentSection = "";
 
         text.split(/\r?\n/).forEach(function (line) {
@@ -504,22 +528,24 @@
 
           if (/原因|発生要因|真因/.test(trimmed)) {
             currentSection = "cause";
-            causes.push(trimmed.replace(/^(不具合の)?原因[::\s]*/, ""));
+            sections.cause.push(trimmed.replace(/^(不具合の)?原因[::\s]*/, ""));
           } else if (/対策|処置|再発防止/.test(trimmed)) {
             currentSection = "action";
-            actions.push(trimmed.replace(/^(不具合に対する)?対策[::\s]*/, ""));
-          } else if (currentSection === "cause") {
-            causes.push(trimmed);
-          } else if (currentSection === "action") {
-            actions.push(trimmed);
+            sections.action.push(trimmed.replace(/^(不具合に対する)?対策[::\s]*/, ""));
+          } else if (/効果|レビュー|確認結果|有効性/.test(trimmed)) {
+            currentSection = "effect";
+            sections.effect.push(trimmed.replace(/^(効果|レビュー|確認結果|有効性)[::\s]*/, ""));
+          } else if (currentSection) {
+            sections[currentSection].push(trimmed);
           }
         });
 
-        result.cause = causes.join("\n");
-        result.action = actions.join("\n");
-      }
-
-      return result;
+        fields.cause = sections.cause.join("\n");
+        fields.action = sections.action.join("\n");
+        fields.effect = sections.effect.join("\n");
+      }
+
+      return fields;
     }
 
     function highlight(text, terms) {
@@ -555,54 +581,61 @@
       }).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);
+    function makeResultSection(title, text, terms, readable, filenameOnly) {
+      const section = document.createElement("section");
+      section.className = "result-section";
+
+      const heading = document.createElement("h4");
+      heading.textContent = title;
+      section.appendChild(heading);
 
       const excerpts = relevantExcerpts(text, terms);
       if (excerpts.length) {
         excerpts.forEach(function (excerpt) {
           const line = document.createElement("div");
+          line.className = "excerpt";
           line.innerHTML = highlight(excerpt, terms);
-          box.appendChild(line);
+          section.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("。"));
-      }
+        const message = document.createElement("p");
+        message.className = "help";
+
+        if (filenameOnly) {
+          message.textContent = "このファイル形式はセル内容を読み取れないため、表示できません。";
+        } else if (!readable) {
+          message.textContent = "ファイル内容を読み取れないため、表示できません。";
+        } else {
+          message.textContent = "条件に一致する文章は見つかりませんでした。";
+        }
+
+        section.appendChild(message);
+      }
+
+      return section;
+    }
+
+    function makeOrganizedText(record, terms) {
+      const groups = [
+        { label: "原因", text: record.cause },
+        { label: "対策", text: record.action },
+        { label: "効果・レビュー", text: record.effect }
+      ];
+
+      const lines = [];
+      groups.forEach(function (group) {
+        const excerpts = relevantExcerpts(group.text, terms);
+        lines.push(group.label + ":");
+        lines.push(excerpts.length ? excerpts.join("。") : "該当する文章なし");
+        lines.push("");
+      });
 
       if (!record.readable) {
-        return "このファイル形式の内容は読み取れないため、要約できません。";
-      }
-      if (!parts.length) {
-        return "検索語に一致する原因・対策の文章が見つからず、整理できる情報がありません。";
-      }
-
-      return parts.join("\n\n") +
-        "\n\n※これはAIによる要約ではなく、検索語に一致した文章を項目別に並べたものです。";
+        return "このファイル形式の内容を読み取れないため、文章を整理できません。";
+      }
+
+      return lines.join("\n").trim() +
+        "\n\n※外部AIには接続していません。これは該当文章を項目別に並べたもので、生成AIによる要約ではありません。";
     }
 
     function renderResults(records, terms) {
@@ -625,39 +658,52 @@
         const card = document.createElement("article");
         card.className = "result-card";
 
-        const title = document.createElement("h3");
-        title.innerHTML = highlight(record.name, terms);
-        card.appendChild(title);
+        const fileSection = document.createElement("section");
+        fileSection.className = "result-section";
+
+        const fileHeading = document.createElement("h4");
+        fileHeading.textContent = "検索結果(ファイル名)";
+        fileSection.appendChild(fileHeading);
+
+        const fileTitle = document.createElement("h3");
+        fileTitle.innerHTML = highlight(record.name, terms);
+        fileSection.appendChild(fileTitle);
 
         const meta = document.createElement("p");
         meta.className = "result-meta";
         meta.textContent =
           "部門:" + record.department +
           " / 日付:" + (record.date || "見つかりません") +
-          " / ファイル内容を読み取れる形式:" + (record.readable ? "はい" : "いいえ");
-        card.appendChild(meta);
-
-        card.appendChild(makeExcerptBox("不具合の原因", record.cause, terms, record.readable));
-        card.appendChild(makeExcerptBox("不具合に対する対策", record.action, terms, record.readable));
+          " / 内容読み取り:" + (record.readable ? "可" : "不可(ファイル名のみ検索)");
+        fileSection.appendChild(meta);
+        card.appendChild(fileSection);
+
+        card.appendChild(makeResultSection(
+          "検索結果(原因)", record.cause, terms, record.readable, false
+        ));
+        card.appendChild(makeResultSection(
+          "検索結果(対策)", record.action, terms, record.readable, false
+        ));
+        card.appendChild(makeResultSection(
+          "検索結果(効果・レビュー)", record.effect, terms, record.readable, false
+        ));
 
         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);
+        summarizeButton.setAttribute("aria-controls", "summary-output-" + index);
 
         const output = document.createElement("div");
-        output.id = "summary-" + index;
+        output.id = "summary-output-" + 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);
+          if (output.hidden) {
+            output.textContent = makeOrganizedText(record, terms);
             output.hidden = false;
             summarizeButton.setAttribute("aria-expanded", "true");
           } else {
@@ -668,14 +714,6 @@
 
         card.appendChild(summarizeButton);
         card.appendChild(output);
-
-        const note = document.createElement("p");
-        note.className = "help";
-        note.textContent =
-          "ボタン押下時に表示するのは、検索語に一致した文章を原因・対策別に並べたものです。" +
-          "生成AIによる分析や文章の言い換えは行いません。";
-        card.appendChild(note);
-
         resultsBox.appendChild(card);
       });
     }
@@ -691,6 +729,7 @@
 
       const startDate = document.getElementById("startDate").value;
       const endDate = document.getElementById("endDate").value;
+
       if (startDate && endDate && startDate > endDate) {
         setStatus("開始日は終了日以前の日付を指定してください。", "error");
         return;
@@ -703,12 +742,12 @@
       }
 
       const incident = document.getElementById("incident").value.trim();
-      const additional = document.getElementById("keywords").value
+      const extraKeywords = document.getElementById("keywords").value
         .trim().split(/\s+/).filter(Boolean);
       const terms = [];
 
       if (incident) terms.push(incident);
-      additional.forEach(function (word) {
+      extraKeywords.forEach(function (word) {
         if (!terms.some(function (existing) {
           return normalize(existing) === normalize(word);
         })) {
@@ -741,11 +780,17 @@
           if (startDate && date < startDate) continue;
           if (endDate && date > endDate) continue;
 
-          const searchable = fields.readable
-            ? fields.allText + "\n" + fields.cause + "\n" + fields.action
+          const searchableText = fields.readable
+            ? [
+                file.name,
+                fields.allText,
+                fields.cause,
+                fields.action,
+                fields.effect
+              ].join("\n")
             : file.name;
 
-          if (!wordMatch(searchable, terms, mode)) continue;
+          if (!wordMatch(searchableText, terms, mode)) continue;
 
           records.push({
             name: file.name,
@@ -753,14 +798,16 @@
             date: date,
             readable: fields.readable,
             cause: fields.cause,
-            action: fields.action
+            action: fields.action,
+            effect: fields.effect
           });
         }
 
         renderResults(records, terms);
         setStatus(
           "検索完了:" + records.length +
-          " 件。CSV・TXTでは原因・対策文章を抽出します。Excel内部の解析と生成AIによる要約は行いません。",
+          " 件。CSV・TXTは原因・対策・効果・レビューの文章を項目別に表示します。" +
+          " Excel内部の解析および生成AIによる要約は行いません。",
           "success"
         );
       } catch (error) {