Browse Source

fix: 修复Step4处理空标题的错误

修复:
- 处理 title 为 None 的情况,避免 TypeError
- 安全地处理空值:title, desc, channel_content_id
- 空标题显示为 "(无标题)"

错误信息:
  TypeError: 'NoneType' object is not subscriptable
  在 title[:50] 时发生

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
yangxiaohui 2 weeks ago
parent
commit
7057ed4be8
1 changed files with 7 additions and 5 deletions
  1. 7 5
      step4_search_result_match.py

+ 7 - 5
step4_search_result_match.py

@@ -37,9 +37,9 @@ async def match_single_note(
     Returns:
         匹配结果
     """
-    title = note.get("title", "")
-    desc = note.get("desc", "")
-    channel_content_id = note.get("channel_content_id", "")
+    title = note.get("title", "") or ""
+    desc = note.get("desc", "") or ""
+    channel_content_id = note.get("channel_content_id", "") or ""
 
     # 调用通用匹配模块
     # B = 灵感, A = 帖子标题, A_Context = 帖子描述
@@ -208,9 +208,11 @@ async def main(current_time: str = None, log_url: str = None, force: bool = Fals
     print("Top 5 匹配结果:")
     for i, result in enumerate(results_sorted[:5], 1):
         score = result.get("匹配结果", {}).get("score", 0)
-        title = result.get("业务信息", {}).get("title", "")
+        title = result.get("业务信息", {}).get("title", "") or ""
         channel_content_id = result.get("业务信息", {}).get("channel_content_id", "")
-        print(f"  {i}. [score={score:.2f}] {title[:50]}... (ID: {channel_content_id})")
+        # 安全地截取标题
+        title_display = title[:50] if title else "(无标题)"
+        print(f"  {i}. [score={score:.2f}] {title_display}... (ID: {channel_content_id})")
     print()
 
     # 保存结果