argo-search 2.14.0 → 2.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +1 -1
- package/README.es.md +18 -8
- package/README.ja.md +18 -8
- package/README.ko.md +18 -8
- package/README.md +511 -608
- package/README.zh.md +975 -0
- package/SKILL.md +1 -1
- package/assets/readme/counts.json +1 -1
- package/backends/domain_profiles.json +24 -0
- package/backends/engine_registry.yaml +69 -18
- package/backends/quota_profiles.json +40 -0
- package/config.yaml +23 -3
- package/docs/CHANGELOG.md +22 -0
- package/docs/ENGINE_CATALOG.md +41 -37
- package/docs/MCP_SETUP.md +1 -1
- package/docs/RELEASE_NOTES_v2.14.0.md +12 -1
- package/docs/RELEASE_NOTES_v2.14.1.md +80 -0
- package/docs/RELEASING.md +52 -0
- package/engines/specs/artic.yaml +11 -1
- package/engines/specs/cleveland.yaml +15 -1
- package/engines/specs/clinicaltrials.yaml +16 -1
- package/engines/specs/cnii.yaml +15 -4
- package/engines/specs/deezer.yaml +12 -1
- package/engines/specs/doaj.yaml +14 -1
- package/engines/specs/endoflife.yaml +16 -1
- package/engines/specs/eu_opendata.yaml +11 -1
- package/engines/specs/europeana.yaml +19 -1
- package/engines/specs/feed.yaml +62 -0
- package/engines/specs/figshare.yaml +12 -1
- package/engines/specs/hackernews.yaml +17 -2
- package/engines/specs/hal.yaml +19 -1
- package/engines/specs/hf_datasets.yaml +59 -0
- package/engines/specs/hf_papers.yaml +17 -1
- package/engines/specs/jikan.yaml +12 -10
- package/engines/specs/kaggle.yaml +5 -3
- package/engines/specs/maven.yaml +61 -0
- package/engines/specs/nasa_cmr.yaml +12 -1
- package/engines/specs/nuget.yaml +57 -0
- package/engines/specs/tatoeba.yaml +14 -1
- package/engines/specs/tvmaze.yaml +5 -1
- package/engines/specs/usda.yaml +14 -1
- package/package.json +2 -1
- package/packages/dsh-plugin/dsh/native-tools.mjs +61 -113
- package/packages/dsh-plugin/dsh/wide-research.js +1 -1
- package/packages/dsh-plugin/package.json +1 -1
- package/scripts/badcase_ledger.py +49 -5
- package/scripts/build_release_assets.sh +43 -15
- package/scripts/dormant_ledger.py +225 -0
- package/scripts/engine_states.py +6 -1
- package/scripts/engine_validate.py +182 -6
- package/scripts/engines.py +0 -36
- package/scripts/engines_base.py +27 -67
- package/scripts/engines_builders.py +0 -36
- package/scripts/engines_builders_batch16.py +6 -179
- package/scripts/engines_builders_batch9.py +0 -204
- package/scripts/engines_builders_feeds.py +148 -30
- package/scripts/engines_builders_intl.py +0 -328
- package/scripts/engines_builders_science.py +0 -85
- package/scripts/engines_builders_tech.py +0 -98
- package/scripts/engines_parsers.py +534 -9
- package/scripts/evidence_loop.py +91 -4
- package/scripts/gen_engine_catalog.py +2 -2
- package/scripts/gen_native_tools.py +2 -1
- package/scripts/local_intent.py +51 -15
- package/scripts/local_seek.py +37 -4
- package/scripts/mcp_handlers.py +124 -72
- package/scripts/mcp_server.py +1 -1
- package/scripts/mcp_tools.py +143 -61
- package/scripts/mcp_transport.py +42 -10
- package/scripts/pre-commit +25 -1
- package/scripts/release.py +20 -11
- package/scripts/release_check.py +1 -1
- package/scripts/route_policy.py +6 -1
- package/scripts/search_cli.py +44 -7
- package/scripts/secret_guard.py +106 -0
- package/scripts/semantic_evidence.py +230 -15
- package/scripts/settings_page.py +80 -8
- package/scripts/source_audit.py +77 -0
- package/scripts/sync_backends.py +7 -0
- package/sub-skills/local-seek/scripts/seek_fts.py +9 -1
- package/README.en.md +0 -826
- package/scripts/image_vision/vision_probe +0 -0
|
@@ -1,186 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
2
|
+
"""批次十六构建器(已按方案 A 架构归一退役)。
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
本批次所涉源已全部迁移至声明式 Spec 与通用自省推断解析器:
|
|
5
|
+
- mwmbl: engines/specs/mwmbl.yaml(type: http + response.parser: mwmbl)
|
|
6
|
+
- kaggle: engines/specs/kaggle.yaml(type: http + output_map 声明)
|
|
7
|
+
- hf_papers: engines/specs/hf_papers.yaml(type: http + 智能自省推断解析器)
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
祖父文件,新引擎的下一站按既有惯例是 batch 模块(同 batch13/14/15)。
|
|
10
|
-
三源均经实测验证(health + quality 准入通过)后入库。
|
|
11
|
-
|
|
12
|
-
接口事实(2026-11-10 本机实测,非文档抄录):
|
|
13
|
-
|
|
14
|
-
Mwmbl: GET https://mwmbl.org/api/v1/search/?s={q}&limit={n}
|
|
15
|
-
返回 [{"url","title":[{"value","is_bold"}],"extract":[{"value","is_bold"}],"source"}]
|
|
16
|
-
title/extract 是 {value,is_bold} 数组,需拍平为字符串。
|
|
17
|
-
与 Marginalia/Wiby/Lieu/Mojeek 同族但索引互补(更偏技术社区与个人站)。
|
|
18
|
-
|
|
19
|
-
Kaggle: GET https://www.kaggle.com/api/v1/datasets/list?search={q}&page=1
|
|
20
|
-
返回 [{"titleNullable","subtitleNullable","urlNullable","licenseNameNullable",
|
|
21
|
-
"totalBytesNullable","usabilityRatingNullable","ref",...}]
|
|
22
|
-
字段名带 Nullable 后缀(Kaggle API 的 Java 序列化遗留)。
|
|
23
|
-
|
|
24
|
-
HF Papers: GET https://huggingface.co/api/papers/search?q={q}&limit={n}
|
|
25
|
-
返回 [{"paper":{"id","title","authors","publishedAt","summary","upvotes"},
|
|
26
|
-
"title","publishedAt","summary","upvotes",...}]
|
|
27
|
-
注意:/api/papers?search= 不过滤(只返回最新),必须用 /api/papers/search?q=。
|
|
28
|
-
与 arXiv/OpenAlex 互补:HF Papers 有社交信号(upvotes)与 AI 论文摘要。
|
|
9
|
+
本文件代码实体已全量清空退役,零运行时引用。
|
|
29
10
|
"""
|
|
30
11
|
|
|
31
12
|
from __future__ import annotations
|
|
32
13
|
|
|
33
|
-
import json
|
|
34
|
-
import logging
|
|
35
|
-
import urllib.parse
|
|
36
|
-
import urllib.request
|
|
37
|
-
from typing import Any
|
|
38
|
-
|
|
39
|
-
from engines_base import http_open, rank_score, safe_search
|
|
40
|
-
|
|
41
|
-
logger = logging.getLogger("unified_search.engines")
|
|
42
|
-
|
|
43
|
-
_UA = "argo-search/2.6 (unified-search@local)"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def _flatten_segments(segments: Any) -> str:
|
|
47
|
-
"""把 Mwmbl 的 [{value, is_bold}] 数组拍平成纯文本。"""
|
|
48
|
-
if not isinstance(segments, list):
|
|
49
|
-
return ""
|
|
50
|
-
return "".join(
|
|
51
|
-
str(seg.get("value", "")) for seg in segments if isinstance(seg, dict)
|
|
52
|
-
).strip()
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def _build_mwmbl_engine(spec: dict[str, Any]) -> Any:
|
|
56
|
-
"""Mwmbl 开源非盈利独立搜索引擎(JSON API,免认证)。
|
|
57
|
-
|
|
58
|
-
与 Marginalia/Wiby/Lieu/Mojeek 同族但索引互补:Mwmbl 更偏技术社区与个人站。
|
|
59
|
-
上游返回的 title/extract 是 {value, is_bold} 数组,需拍平。
|
|
60
|
-
"""
|
|
61
|
-
timeout = spec.get("timeout", 12)
|
|
62
|
-
|
|
63
|
-
@safe_search
|
|
64
|
-
def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
|
|
65
|
-
to = _timeout or timeout
|
|
66
|
-
url = "https://mwmbl.org/api/v1/search/?s=" + urllib.parse.quote(query) + "&limit=" + str(max(1, min(int(n or 5), 50)))
|
|
67
|
-
try:
|
|
68
|
-
with http_open(urllib.request.Request(
|
|
69
|
-
url, headers={"User-Agent": _UA}), timeout=to, engine=spec.get("_name", "")) as resp:
|
|
70
|
-
data = json.loads(resp.read().decode("utf-8", "replace"))
|
|
71
|
-
except Exception as e:
|
|
72
|
-
logger.warning(f"Mwmbl 失败: {e}")
|
|
73
|
-
return []
|
|
74
|
-
if not isinstance(data, list):
|
|
75
|
-
return []
|
|
76
|
-
results = []
|
|
77
|
-
for _rk, r in enumerate(data[:n]):
|
|
78
|
-
if not isinstance(r, dict):
|
|
79
|
-
continue
|
|
80
|
-
title = _flatten_segments(r.get("title"))
|
|
81
|
-
extract = _flatten_segments(r.get("extract"))
|
|
82
|
-
url_ = r.get("url") or ""
|
|
83
|
-
if not title and not url_:
|
|
84
|
-
continue
|
|
85
|
-
results.append({
|
|
86
|
-
"title": title[:200] or url_[:200],
|
|
87
|
-
"url": url_,
|
|
88
|
-
"snippet": extract[:300],
|
|
89
|
-
"source": "mwmbl",
|
|
90
|
-
"score": rank_score(0.7, _rk),
|
|
91
|
-
})
|
|
92
|
-
return results
|
|
93
|
-
return _engine
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
def _build_kaggle_engine(spec: dict[str, Any]) -> Any:
|
|
97
|
-
"""Kaggle 数据集搜索(免认证,结构化元数据)。
|
|
98
|
-
|
|
99
|
-
与 DataCite/Zenodo 互补:Kaggle 是社区数据集,含许可证/大小/版本/URL。
|
|
100
|
-
上游字段名带 Nullable 后缀(Kaggle API 的 Java 序列化遗留)。
|
|
101
|
-
"""
|
|
102
|
-
timeout = spec.get("timeout", 12)
|
|
103
|
-
|
|
104
|
-
@safe_search
|
|
105
|
-
def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
|
|
106
|
-
to = _timeout or timeout
|
|
107
|
-
url = "https://www.kaggle.com/api/v1/datasets/list?search=" + urllib.parse.quote(query) + "&page=1"
|
|
108
|
-
try:
|
|
109
|
-
with http_open(urllib.request.Request(
|
|
110
|
-
url, headers={"User-Agent": _UA}), timeout=to, engine=spec.get("_name", "")) as resp:
|
|
111
|
-
data = json.loads(resp.read().decode("utf-8", "replace"))
|
|
112
|
-
except Exception as e:
|
|
113
|
-
logger.warning(f"Kaggle 失败: {e}")
|
|
114
|
-
return []
|
|
115
|
-
if not isinstance(data, list):
|
|
116
|
-
return []
|
|
117
|
-
results = []
|
|
118
|
-
for _rk, r in enumerate(data[:n]):
|
|
119
|
-
if not isinstance(r, dict):
|
|
120
|
-
continue
|
|
121
|
-
title = r.get("titleNullable") or r.get("title") or ""
|
|
122
|
-
url_ = r.get("urlNullable") or r.get("url") or ""
|
|
123
|
-
if not title and not url_:
|
|
124
|
-
continue
|
|
125
|
-
subtitle = r.get("subtitleNullable") or ""
|
|
126
|
-
license_ = r.get("licenseNameNullable") or ""
|
|
127
|
-
size = r.get("totalBytesNullable")
|
|
128
|
-
parts = [p for p in (license_, f"{size} bytes" if size else "") if p]
|
|
129
|
-
snippet = (subtitle[:200] + " · " + " · ".join(parts)) if parts else subtitle[:300]
|
|
130
|
-
results.append({
|
|
131
|
-
"title": title[:200],
|
|
132
|
-
"url": url_,
|
|
133
|
-
"snippet": snippet,
|
|
134
|
-
"source": "kaggle",
|
|
135
|
-
"score": rank_score(0.7, _rk),
|
|
136
|
-
})
|
|
137
|
-
return results
|
|
138
|
-
return _engine
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
def _build_hf_papers_engine(spec: dict[str, Any]) -> Any:
|
|
142
|
-
"""Hugging Face Papers 论文检索(免认证,含 upvotes/作者/发布日期)。
|
|
143
|
-
|
|
144
|
-
注意:/api/papers?search= 不过滤(只返回最新),必须用 /api/papers/search?q=。
|
|
145
|
-
与 arXiv/OpenAlex 互补:HF Papers 有社交信号(upvotes)与 AI 论文摘要。
|
|
146
|
-
"""
|
|
147
|
-
timeout = spec.get("timeout", 15)
|
|
148
|
-
|
|
149
|
-
@safe_search
|
|
150
|
-
def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
|
|
151
|
-
to = _timeout or timeout
|
|
152
|
-
url = "https://huggingface.co/api/papers/search?q=" + urllib.parse.quote(query) + "&limit=" + str(max(1, min(int(n or 5), 20)))
|
|
153
|
-
try:
|
|
154
|
-
with http_open(urllib.request.Request(
|
|
155
|
-
url, headers={"User-Agent": _UA}), timeout=to, engine=spec.get("_name", "")) as resp:
|
|
156
|
-
data = json.loads(resp.read().decode("utf-8", "replace"))
|
|
157
|
-
except Exception as e:
|
|
158
|
-
logger.warning(f"HF Papers 失败: {e}")
|
|
159
|
-
return []
|
|
160
|
-
if not isinstance(data, list):
|
|
161
|
-
return []
|
|
162
|
-
results = []
|
|
163
|
-
for _rk, r in enumerate(data[:n]):
|
|
164
|
-
if not isinstance(r, dict):
|
|
165
|
-
continue
|
|
166
|
-
paper = r.get("paper") or {}
|
|
167
|
-
pid = paper.get("id") or r.get("id") or ""
|
|
168
|
-
title = paper.get("title") or r.get("title") or ""
|
|
169
|
-
url_ = f"https://huggingface.co/papers/{pid}" if pid else ""
|
|
170
|
-
if not title and not url_:
|
|
171
|
-
continue
|
|
172
|
-
authors = [a.get("name", "") for a in (paper.get("authors") or []) if isinstance(a, dict)][:3]
|
|
173
|
-
published = paper.get("publishedAt") or r.get("publishedAt") or ""
|
|
174
|
-
upvotes = paper.get("upvotes") or r.get("upvotes") or 0
|
|
175
|
-
summary = paper.get("summary") or r.get("summary") or ""
|
|
176
|
-
parts = [p for p in (published[:10], f"upvotes: {upvotes}" if upvotes else "", ", ".join(authors) if authors else "") if p]
|
|
177
|
-
snippet = (summary[:200] + " · " + " · ".join(parts)) if parts else summary[:300]
|
|
178
|
-
results.append({
|
|
179
|
-
"title": title[:200],
|
|
180
|
-
"url": url_,
|
|
181
|
-
"snippet": snippet,
|
|
182
|
-
"source": "hf_papers",
|
|
183
|
-
"score": rank_score(0.7, _rk),
|
|
184
|
-
})
|
|
185
|
-
return results
|
|
186
|
-
return _engine
|
|
@@ -592,212 +592,8 @@ def _build_openligadb_engine(spec: dict[str, Any]) -> Any:
|
|
|
592
592
|
return _engine
|
|
593
593
|
|
|
594
594
|
|
|
595
|
-
# ── 博物馆:AIC + Cleveland(补 art_museum 域)────────────────────────────────
|
|
596
|
-
|
|
597
|
-
def _build_artic_engine(spec: dict[str, Any]) -> Any:
|
|
598
|
-
"""Art Institute of Chicago 馆藏(免认证,含 IIIF 图像)。"""
|
|
599
|
-
timeout = spec.get("timeout", 20)
|
|
600
|
-
|
|
601
|
-
@safe_search
|
|
602
|
-
def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
|
|
603
|
-
to = _timeout or timeout
|
|
604
|
-
q = (query or "").strip()
|
|
605
|
-
if not q:
|
|
606
|
-
return []
|
|
607
|
-
url = ("https://api.artic.edu/api/v1/artworks/search?"
|
|
608
|
-
f"q={urllib.parse.quote(q)}&limit={n}"
|
|
609
|
-
"&fields=id,title,artist_display,date_display,image_id")
|
|
610
|
-
try:
|
|
611
|
-
data = _json(url, to, spec.get("_name", ""))
|
|
612
|
-
except Exception as e:
|
|
613
|
-
logger.warning(f"AIC 失败: {e}")
|
|
614
|
-
return []
|
|
615
|
-
# IIIF 基址取响应自带的 config.iiif_url,不硬编码——上游换域时硬编码会
|
|
616
|
-
# 静默失效。该图床要求带 AIC-User-Agent 头才放行直连(否则 403 HEAD)。
|
|
617
|
-
iiif = str(((data.get("config") or {}).get("iiif_url")) or "").rstrip("/")
|
|
618
|
-
results = []
|
|
619
|
-
for _rk, it in enumerate((data.get("data") or [])[:n]):
|
|
620
|
-
if not isinstance(it, dict):
|
|
621
|
-
continue
|
|
622
|
-
title = (it.get("title") or "").strip()
|
|
623
|
-
if not title:
|
|
624
|
-
continue
|
|
625
|
-
_row = {
|
|
626
|
-
"title": title[:200],
|
|
627
|
-
"url": f"https://www.artic.edu/artworks/{it.get('id','')}",
|
|
628
|
-
"snippet": (f"{it.get('artist_display','')} · {it.get('date_display','')}"
|
|
629
|
-
"(芝加哥艺术博物馆)")[:300],
|
|
630
|
-
"source": "artic",
|
|
631
|
-
"score": rank_score(0.85, _rk),
|
|
632
|
-
}
|
|
633
|
-
# 图片字段:请求里本就取了 image_id(此前取到即丢),这里按 AIC
|
|
634
|
-
# 官方 IIIF 模板拼出可直接打开的图;无 image_id 的藏品不加字段。
|
|
635
|
-
_iid = str(it.get("image_id") or "").strip()
|
|
636
|
-
if _iid and iiif:
|
|
637
|
-
_row["image_url"] = f"{iiif}/{_iid}/full/843,/0/default.jpg"
|
|
638
|
-
_row["image_license"] = "AIC 公开接口(权利状态见作品页)"
|
|
639
|
-
results.append(_row)
|
|
640
|
-
return results
|
|
641
|
-
return _engine
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
def _build_cleveland_engine(spec: dict[str, Any]) -> Any:
|
|
645
|
-
"""克利夫兰艺术博物馆(CC0 开放图像)。"""
|
|
646
|
-
timeout = spec.get("timeout", 20)
|
|
647
|
-
|
|
648
|
-
@safe_search
|
|
649
|
-
def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
|
|
650
|
-
to = _timeout or timeout
|
|
651
|
-
q = (query or "").strip()
|
|
652
|
-
if not q:
|
|
653
|
-
return []
|
|
654
|
-
url = ("https://openaccess-api.clevelandart.org/api/artworks/?"
|
|
655
|
-
f"q={urllib.parse.quote(q)}&limit={n}&has_image=1")
|
|
656
|
-
try:
|
|
657
|
-
data = _json(url, to, spec.get("_name", ""))
|
|
658
|
-
except Exception as e:
|
|
659
|
-
logger.warning(f"Cleveland 失败: {e}")
|
|
660
|
-
return []
|
|
661
|
-
results = []
|
|
662
|
-
for _rk, it in enumerate((data.get("data") or [])[:n]):
|
|
663
|
-
if not isinstance(it, dict):
|
|
664
|
-
continue
|
|
665
|
-
title = (it.get("title") or "").strip()
|
|
666
|
-
if not title:
|
|
667
|
-
continue
|
|
668
|
-
_lic = str(it.get("share_license_status") or "").strip()
|
|
669
|
-
_row = {
|
|
670
|
-
"title": title[:200],
|
|
671
|
-
"url": it.get("url") or "https://www.clevelandart.org/",
|
|
672
|
-
"snippet": (f"{it.get('tombstone','')} · 授权 {_lic}"
|
|
673
|
-
"(克利夫兰艺术博物馆)")[:300],
|
|
674
|
-
"source": "cleveland",
|
|
675
|
-
"score": rank_score(0.85, _rk),
|
|
676
|
-
}
|
|
677
|
-
# 图片字段:请求已带 has_image=1,这里把 images.web.url 一并带上
|
|
678
|
-
# (web 尺寸适合直接展示,full/print 留给需要原图的场景)。
|
|
679
|
-
_img = str((((it.get("images") or {}).get("web") or {}).get("url")) or "").strip()
|
|
680
|
-
if _img:
|
|
681
|
-
_row["image_url"] = _img
|
|
682
|
-
if _lic:
|
|
683
|
-
_row["image_license"] = _lic
|
|
684
|
-
results.append(_row)
|
|
685
|
-
return results
|
|
686
|
-
return _engine
|
|
687
|
-
|
|
688
|
-
|
|
689
595
|
# ── 影视/动漫/音乐 ────────────────────────────────────────────────────────────
|
|
690
596
|
|
|
691
|
-
def _build_tvmaze_engine(spec: dict[str, Any]) -> Any:
|
|
692
|
-
"""TVMaze 电视剧元数据(免认证,补 film_search 的剧集维度)。"""
|
|
693
|
-
timeout = spec.get("timeout", 15)
|
|
694
|
-
|
|
695
|
-
@safe_search
|
|
696
|
-
def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
|
|
697
|
-
to = _timeout or timeout
|
|
698
|
-
q = (query or "").strip()
|
|
699
|
-
if not q:
|
|
700
|
-
return []
|
|
701
|
-
url = f"https://api.tvmaze.com/search/shows?q={urllib.parse.quote(q)}"
|
|
702
|
-
try:
|
|
703
|
-
data = _json(url, to, spec.get("_name", ""))
|
|
704
|
-
except Exception as e:
|
|
705
|
-
logger.warning(f"TVMaze 失败: {e}")
|
|
706
|
-
return []
|
|
707
|
-
results = []
|
|
708
|
-
for _rk, row in enumerate((data or [])[:n]):
|
|
709
|
-
if not isinstance(row, dict):
|
|
710
|
-
continue
|
|
711
|
-
s = row.get("show") or {}
|
|
712
|
-
name = (s.get("name") or "").strip()
|
|
713
|
-
if not name:
|
|
714
|
-
continue
|
|
715
|
-
genres = ", ".join(s.get("genres") or [])
|
|
716
|
-
results.append({
|
|
717
|
-
"title": f"{name}({s.get('premiered','')[:4]})"[:200],
|
|
718
|
-
"url": s.get("url") or "",
|
|
719
|
-
"snippet": (f"{s.get('language','')} · {genres} · "
|
|
720
|
-
f"评分 {((s.get('rating') or {}).get('average')) or '-'}"
|
|
721
|
-
"(TVMaze)")[:300],
|
|
722
|
-
"source": "tvmaze",
|
|
723
|
-
"score": rank_score(0.8, _rk),
|
|
724
|
-
"published_at": s.get("premiered") or "",
|
|
725
|
-
})
|
|
726
|
-
return results
|
|
727
|
-
return _engine
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
def _build_jikan_engine(spec: dict[str, Any]) -> Any:
|
|
731
|
-
"""Jikan(MyAnimeList 非官方 API)动漫元数据。"""
|
|
732
|
-
timeout = spec.get("timeout", 20)
|
|
733
|
-
|
|
734
|
-
@safe_search
|
|
735
|
-
def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
|
|
736
|
-
to = _timeout or timeout
|
|
737
|
-
q = (query or "").strip()
|
|
738
|
-
if not q:
|
|
739
|
-
return []
|
|
740
|
-
url = f"https://api.jikan.moe/v4/anime?q={urllib.parse.quote(q)}&limit={n}"
|
|
741
|
-
try:
|
|
742
|
-
data = _json(url, to, spec.get("_name", ""))
|
|
743
|
-
except Exception as e:
|
|
744
|
-
logger.warning(f"Jikan 失败: {e}")
|
|
745
|
-
return []
|
|
746
|
-
results = []
|
|
747
|
-
for _rk, a in enumerate((data.get("data") or [])[:n]):
|
|
748
|
-
if not isinstance(a, dict):
|
|
749
|
-
continue
|
|
750
|
-
title = a.get("title") or a.get("title_japanese") or ""
|
|
751
|
-
if not title:
|
|
752
|
-
continue
|
|
753
|
-
results.append({
|
|
754
|
-
"title": title[:200],
|
|
755
|
-
"url": a.get("url") or "",
|
|
756
|
-
"snippet": (f"{a.get('type','')} · {a.get('episodes','') or '-'} 集 · "
|
|
757
|
-
f"评分 {a.get('score') or '-'} · {a.get('status','')}"
|
|
758
|
-
"(MyAnimeList)")[:300],
|
|
759
|
-
"source": "jikan",
|
|
760
|
-
"score": rank_score(0.8, _rk),
|
|
761
|
-
})
|
|
762
|
-
return results
|
|
763
|
-
return _engine
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
def _build_deezer_engine(spec: dict[str, Any]) -> Any:
|
|
767
|
-
"""Deezer 音乐艺人/专辑(免认证)。"""
|
|
768
|
-
timeout = spec.get("timeout", 15)
|
|
769
|
-
|
|
770
|
-
@safe_search
|
|
771
|
-
def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
|
|
772
|
-
to = _timeout or timeout
|
|
773
|
-
q = (query or "").strip()
|
|
774
|
-
if not q:
|
|
775
|
-
return []
|
|
776
|
-
url = f"https://api.deezer.com/search/artist?q={urllib.parse.quote(q)}&limit={n}"
|
|
777
|
-
try:
|
|
778
|
-
data = _json(url, to, spec.get("_name", ""))
|
|
779
|
-
except Exception as e:
|
|
780
|
-
logger.warning(f"Deezer 失败: {e}")
|
|
781
|
-
return []
|
|
782
|
-
results = []
|
|
783
|
-
for _rk, a in enumerate((data.get("data") or [])[:n]):
|
|
784
|
-
if not isinstance(a, dict):
|
|
785
|
-
continue
|
|
786
|
-
name = (a.get("name") or "").strip()
|
|
787
|
-
if not name:
|
|
788
|
-
continue
|
|
789
|
-
results.append({
|
|
790
|
-
"title": f"{name}(音乐人)"[:200],
|
|
791
|
-
"url": a.get("link") or "",
|
|
792
|
-
"snippet": (f"Deezer 音乐人 · 专辑 {a.get('nb_album','')} · "
|
|
793
|
-
f"粉丝 {a.get('nb_fan','')}")[:300],
|
|
794
|
-
"source": "deezer",
|
|
795
|
-
"score": rank_score(0.8, _rk),
|
|
796
|
-
})
|
|
797
|
-
return results
|
|
798
|
-
return _engine
|
|
799
|
-
|
|
800
|
-
|
|
801
597
|
def _build_listenbrainz_engine(spec: dict[str, Any]) -> Any:
|
|
802
598
|
"""ListenBrainz 收听趋势(社区收听统计,补 MusicBrainz 元数据的动态维度)。"""
|
|
803
599
|
timeout = spec.get("timeout", 15)
|
|
@@ -21,6 +21,12 @@ hot_trending 排除在通用 combo 回填之外,理由是「产出非『查询
|
|
|
21
21
|
「某个声明被判定为真伪」的查询型内容,用户问的是具体说法,所以本地关键词
|
|
22
22
|
过滤是对的。种子里没有就返回空。
|
|
23
23
|
|
|
24
|
+
**多份种子(spec 的 feeds)** —— 一个引擎订多份固定窗口,过滤后合并。
|
|
25
|
+
每份自己带 url、label、langs。纯中文查询不下载英文种子,纯拉丁查询
|
|
26
|
+
不下载只声明了 zh 的种子;一份下载失败只丢掉这一份。label 非空时,
|
|
27
|
+
标题在输出上加「出处 · 」,不改缓存里的原文。没写 feeds 的旧引擎
|
|
28
|
+
仍是单份 feed_url,标题不加前缀。热榜模式仍然忽略查询、不加前缀。
|
|
29
|
+
|
|
24
30
|
## 匹配口径(filter 模式)
|
|
25
31
|
|
|
26
32
|
拉丁词走词边界,CJK 走子串——汉字全属 \\w,\\b 对中文无效(「俄乌冲突」
|
|
@@ -176,6 +182,64 @@ def _query_terms(query: str) -> list[str]:
|
|
|
176
182
|
return [t for t in raw if t.lower() not in _STOPWORDS]
|
|
177
183
|
|
|
178
184
|
|
|
185
|
+
# 多份种子时单份请求的上限。引擎级 timeout 是「这一次调用」的预算,
|
|
186
|
+
# 四份串行若各吃满 12s 会到 48s。单份引擎不切片,超时与改前一致。
|
|
187
|
+
_MULTI_SLICE_S = 8.0
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def _feed_sources(spec: dict[str, Any]) -> list[dict[str, Any]]:
|
|
191
|
+
"""声明收成种子清单。feeds 非空时用它;否则退回单份 feed_url / url。
|
|
192
|
+
|
|
193
|
+
单份路径的 label 留空、langs 用引擎自己的声明,这样旧引擎的标题
|
|
194
|
+
不加出处前缀,语言守卫仍看得到。
|
|
195
|
+
"""
|
|
196
|
+
sources: list[dict[str, Any]] = []
|
|
197
|
+
raw = spec.get("feeds")
|
|
198
|
+
if isinstance(raw, list):
|
|
199
|
+
for item in raw:
|
|
200
|
+
if not isinstance(item, dict):
|
|
201
|
+
continue
|
|
202
|
+
url = str(item.get("url") or item.get("feed_url") or "").strip()
|
|
203
|
+
if not url:
|
|
204
|
+
continue
|
|
205
|
+
langs = item.get("langs") or []
|
|
206
|
+
sources.append({
|
|
207
|
+
"url": url,
|
|
208
|
+
"label": str(item.get("label") or "").strip(),
|
|
209
|
+
"langs": [str(x) for x in langs] if isinstance(langs, list) else [],
|
|
210
|
+
})
|
|
211
|
+
if sources:
|
|
212
|
+
return sources
|
|
213
|
+
url = str(spec.get("feed_url") or spec.get("url") or "").strip()
|
|
214
|
+
if not url:
|
|
215
|
+
return []
|
|
216
|
+
langs = spec.get("langs") or []
|
|
217
|
+
return [{
|
|
218
|
+
"url": url,
|
|
219
|
+
"label": "",
|
|
220
|
+
"langs": [str(x) for x in langs] if isinstance(langs, list) else [],
|
|
221
|
+
}]
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def _feed_relevant(query: str, feed_langs: list[str]) -> bool:
|
|
225
|
+
"""这份种子值不值得为这次查询下载。
|
|
226
|
+
|
|
227
|
+
没声明语言的一律下载。纯中文只下载声明了 zh 的;纯拉丁跳过
|
|
228
|
+
「语言集合只有 zh」的。中英混写两边都下载。
|
|
229
|
+
"""
|
|
230
|
+
langs = {str(x).lower() for x in feed_langs if x}
|
|
231
|
+
if not langs or "*" in langs:
|
|
232
|
+
return True
|
|
233
|
+
text = query or ""
|
|
234
|
+
cjk = bool(_CJK_RE.search(text))
|
|
235
|
+
latin = bool(_LATIN_RE.search(text))
|
|
236
|
+
if cjk and not latin:
|
|
237
|
+
return "zh" in langs
|
|
238
|
+
if latin and not cjk:
|
|
239
|
+
return not (langs <= {"zh"})
|
|
240
|
+
return True
|
|
241
|
+
|
|
242
|
+
|
|
179
243
|
def _build_rss_feed_engine(spec: dict[str, Any]) -> Any:
|
|
180
244
|
"""静态 RSS/Atom 种子引擎(spec 驱动,新增源只需一个 YAML)。
|
|
181
245
|
|
|
@@ -183,7 +247,9 @@ def _build_rss_feed_engine(spec: dict[str, Any]) -> Any:
|
|
|
183
247
|
需要查询式行为的源(事实核查)显式声明 filter。
|
|
184
248
|
"""
|
|
185
249
|
timeout = float(spec.get("timeout", 12))
|
|
186
|
-
|
|
250
|
+
sources = _feed_sources(spec)
|
|
251
|
+
# 单份保持声明里的 timeout;多份每份封顶,避免一份挂起吃完整段预算。
|
|
252
|
+
req_timeout = timeout if len(sources) <= 1 else min(timeout, _MULTI_SLICE_S)
|
|
187
253
|
name = spec.get("_name", "") or spec.get("engine_id", "") or "rss_feed"
|
|
188
254
|
langs = set(spec.get("langs") or [])
|
|
189
255
|
mode = str(spec.get("feed_mode") or "hot").lower()
|
|
@@ -191,9 +257,13 @@ def _build_rss_feed_engine(spec: dict[str, Any]) -> Any:
|
|
|
191
257
|
snippet_max = int(spec.get("snippet_max", 300))
|
|
192
258
|
hot_base = float(spec.get("hot_base_score", 0.55))
|
|
193
259
|
|
|
194
|
-
def _row(it: dict[str, Any], rank: int, score: float
|
|
260
|
+
def _row(it: dict[str, Any], rank: int, score: float,
|
|
261
|
+
label: str = "") -> dict[str, Any]:
|
|
262
|
+
title = it["title"]
|
|
263
|
+
if label:
|
|
264
|
+
title = f"{label} · {title}"
|
|
195
265
|
return {
|
|
196
|
-
"title":
|
|
266
|
+
"title": title,
|
|
197
267
|
"url": it["url"],
|
|
198
268
|
"snippet": it["text"][:snippet_max],
|
|
199
269
|
"source": name,
|
|
@@ -201,42 +271,88 @@ def _build_rss_feed_engine(spec: dict[str, Any]) -> Any:
|
|
|
201
271
|
"score": rank_score(score, rank),
|
|
202
272
|
}
|
|
203
273
|
|
|
204
|
-
def
|
|
205
|
-
hit = _feed_cache.get(
|
|
274
|
+
def _load_one(url: str, one_timeout: float) -> list[dict[str, Any]]:
|
|
275
|
+
hit = _feed_cache.get(url)
|
|
206
276
|
if hit and (time.monotonic() - hit[0]) < _FEED_TTL_S:
|
|
207
277
|
return hit[1]
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
278
|
+
if one_timeout <= 0:
|
|
279
|
+
return []
|
|
280
|
+
# 实测 lobste.rs 会偶发 TLS EOF,重试一次;仍失败只丢这一份。
|
|
281
|
+
last_exc: Exception | None = None
|
|
282
|
+
for attempt in (1, 2):
|
|
283
|
+
try:
|
|
284
|
+
req = urllib.request.Request(
|
|
285
|
+
url, headers={"User-Agent": _UA, "Accept": "*/*"})
|
|
286
|
+
with http_open(req, timeout=one_timeout, engine=name) as resp:
|
|
287
|
+
# utf-8-sig 去掉美联储 press_all.xml 开头的 BOM。
|
|
288
|
+
# ElementTree 见到 U+FEFF 会整份解析失败。
|
|
289
|
+
raw = resp.read().decode("utf-8-sig", "replace")
|
|
290
|
+
items = _parse_feed(raw)
|
|
291
|
+
_feed_cache[url] = (time.monotonic(), items)
|
|
292
|
+
return items
|
|
293
|
+
except Exception as exc:
|
|
294
|
+
last_exc = exc
|
|
295
|
+
logger.warning("rss 种子失败 %s: %s", url, last_exc)
|
|
296
|
+
return []
|
|
214
297
|
|
|
215
298
|
@safe_search
|
|
216
299
|
def _engine(query: str, n: int = 10, _timeout: float | None = None,
|
|
217
300
|
**kwargs) -> list[dict[str, Any]]:
|
|
218
|
-
|
|
219
|
-
|
|
301
|
+
# 热榜语义:种子即最新流,query 与语言守卫都不参与。
|
|
302
|
+
# 「今日要闻」没有主题词,硬筛只会返回空。
|
|
303
|
+
if mode == "hot":
|
|
304
|
+
chosen = sources
|
|
305
|
+
stamp = False
|
|
306
|
+
else:
|
|
307
|
+
# 引擎级 langs 不含 zh 时,纯中文查询整引擎放弃、一次都不下载。
|
|
308
|
+
# 多份种子要让中文源留下,引擎级 langs 必须含 zh,逐份再筛。
|
|
309
|
+
if langs and "zh" not in langs and _is_pure_cjk(query):
|
|
310
|
+
return []
|
|
311
|
+
chosen = [s for s in sources if _feed_relevant(query, s["langs"])]
|
|
312
|
+
stamp = True
|
|
313
|
+
if not chosen:
|
|
314
|
+
return []
|
|
315
|
+
|
|
316
|
+
# 多份种子时,调用方传入的 _timeout 是整次预算(search 默认 10s),
|
|
317
|
+
# 不是每一份的超时。单份不看它,避免改掉卫报等旧引擎的超时语义。
|
|
318
|
+
deadline = None
|
|
319
|
+
if len(sources) > 1 and _timeout:
|
|
320
|
+
try:
|
|
321
|
+
budget = float(_timeout)
|
|
322
|
+
except (TypeError, ValueError):
|
|
323
|
+
budget = 0.0
|
|
324
|
+
if budget > 0:
|
|
325
|
+
deadline = time.monotonic() + budget
|
|
326
|
+
|
|
327
|
+
rows: list[tuple[dict[str, Any], str]] = []
|
|
328
|
+
pending = list(chosen)
|
|
329
|
+
while pending:
|
|
330
|
+
src = pending.pop(0)
|
|
331
|
+
if deadline is None:
|
|
332
|
+
one_timeout = req_timeout
|
|
333
|
+
else:
|
|
334
|
+
left = deadline - time.monotonic()
|
|
335
|
+
if left < 0.4:
|
|
336
|
+
break
|
|
337
|
+
one_timeout = min(req_timeout, left / (len(pending) + 1))
|
|
338
|
+
label = src["label"] if stamp else ""
|
|
339
|
+
for it in _load_one(src["url"], one_timeout):
|
|
340
|
+
rows.append((it, label))
|
|
341
|
+
if not rows:
|
|
220
342
|
return []
|
|
221
343
|
|
|
222
|
-
# 热榜语义:种子即最新流,query 不参与过滤——返回的就是「此刻的最近条目」。
|
|
223
|
-
# 不在这里做关键词筛选,是因为「今日要闻」这类请求本身没有主题词,
|
|
224
|
-
# 硬筛只会返回空;话题检索应由查询驱动的引擎承担。
|
|
225
344
|
if mode == "hot":
|
|
226
|
-
return [_row(it, i, hot_base
|
|
345
|
+
return [_row(it, i, hot_base, label)
|
|
346
|
+
for i, (it, label) in enumerate(rows[:max(1, n)])]
|
|
227
347
|
|
|
228
|
-
# 纯 CJK 查询打到不含 zh 的英文种子:本地过滤必然全空,直接放弃,
|
|
229
|
-
# 把路由槽位让给中文源(同 GBIF 的 ASCII 守卫)。
|
|
230
|
-
if langs and "zh" not in langs and _is_pure_cjk(query):
|
|
231
|
-
return []
|
|
232
348
|
terms = _query_terms(query)
|
|
233
349
|
if not terms:
|
|
234
|
-
# 全是虚词("the" / "latest news"
|
|
235
|
-
#
|
|
350
|
+
# 全是虚词("the" / "latest news"):没有可依据的主题词,
|
|
351
|
+
# 返回空,不把整份种子当结果交出去。
|
|
236
352
|
return []
|
|
237
353
|
|
|
238
|
-
scored: list[tuple[float, int, dict[str, Any]]] = []
|
|
239
|
-
for rank, it in enumerate(
|
|
354
|
+
scored: list[tuple[float, int, dict[str, Any], str]] = []
|
|
355
|
+
for rank, (it, label) in enumerate(rows):
|
|
240
356
|
low = f"{it['title']} {it['text']}".lower()
|
|
241
357
|
hits = sum(1 for t in terms if _term_hit(t, low))
|
|
242
358
|
if not hits:
|
|
@@ -244,12 +360,14 @@ def _build_rss_feed_engine(spec: dict[str, Any]) -> Any:
|
|
|
244
360
|
ratio = hits / len(terms)
|
|
245
361
|
if ratio < min_ratio:
|
|
246
362
|
continue
|
|
247
|
-
#
|
|
248
|
-
|
|
249
|
-
|
|
363
|
+
# 标题命中额外加权:正文顺带提到的词不如标题直指主题。
|
|
364
|
+
# 用缓存里的原标题,不用加过出处前缀的那份。
|
|
365
|
+
title_bonus = 0.15 if any(
|
|
366
|
+
_term_hit(t, it["title"].lower()) for t in terms) else 0.0
|
|
367
|
+
scored.append((ratio + title_bonus, rank, it, label))
|
|
250
368
|
|
|
251
369
|
scored.sort(key=lambda x: (-x[0], x[1]))
|
|
252
|
-
return [_row(it, rank_i, min(0.6 + score * 0.2, 0.85))
|
|
253
|
-
for score, rank_i, it in scored[:n]]
|
|
370
|
+
return [_row(it, rank_i, min(0.6 + score * 0.2, 0.85), label)
|
|
371
|
+
for score, rank_i, it, label in scored[:n]]
|
|
254
372
|
|
|
255
373
|
return _engine
|