From c01a3d427bae2d8ebf203905d2b41073f7a02f6f Mon Sep 17 00:00:00 2001 From: v6ole Date: Tue, 12 May 2026 17:51:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AD=98=E5=BA=93=E5=89=8D=E5=85=88?= =?UTF-8?q?=E6=A0=87=E8=AE=B0=20keyword=5Fmatched=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=8E=86=E5=8F=B2=E6=95=B0=E6=8D=AE=E5=85=A8=E4=B8=BA?= =?UTF-8?q?=20false=20=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pipeline 原来先存库再过滤,导致 keyword_matched 永远是 False。 改为先标记再存库,最新公告查询才能正确区分两个来源。 Co-Authored-By: Claude Sonnet 4.6 --- app/services/pipeline.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/services/pipeline.py b/app/services/pipeline.py index b5049fe..ac4b829 100644 --- a/app/services/pipeline.py +++ b/app/services/pipeline.py @@ -20,24 +20,28 @@ class PostCrawlPipeline: if config.dedup_enabled: announcements = dedup_by_hash(announcements) - # 2. Store to database + # 2. 先标记 keyword_matched,再存库 + if config.filter_enabled and config.keywords: + for a in announcements: + a["keyword_matched"] = self._match_keywords(a, config.keywords) + + # 3. Store to database stored = await self._save_to_db(announcements) result.stored = stored to_notify = announcements - # 3. Filter + # 4. Filter if config.filter_enabled and config.keywords: before = len(to_notify) - to_notify = [a for a in to_notify - if self._match_keywords(a, config.keywords)] + to_notify = [a for a in to_notify if a.get("keyword_matched")] result.filtered = before - len(to_notify) - # 4. Skip already-notified + # 5. Skip already-notified if to_notify: to_notify = await self._exclude_sent(to_notify) - # 5. Notify + # 6. Notify if config.notify_mode == "all": result.notified = await self._send_notifications(to_notify) elif config.notify_mode == "filtered": @@ -46,7 +50,7 @@ class PostCrawlPipeline: elif not config.filter_enabled: result.notified = await self._send_notifications(to_notify) - # 6. Mark sent + # 7. Mark sent if config.mark_sent and result.notified > 0: await self._mark_sent(to_notify)