argo-search 2.14.1 → 2.16.0
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 +8 -6
- package/README.es.md +57 -813
- package/README.ja.md +56 -814
- package/README.ko.md +56 -812
- package/README.md +160 -754
- package/README.zh.md +152 -872
- package/SKILL.md +22 -23
- package/assets/readme/counts.json +1 -1
- package/assets/readme/hero.svg +23 -23
- package/backends/concept_vectors.bin +0 -0
- package/backends/domain_profiles.json +149 -6
- package/backends/engine_concept_vectors.json +1525 -1525
- package/backends/engine_registry.yaml +139 -30
- package/backends/quota_profiles.json +83 -3
- package/bin/argo +33 -17
- package/config.yaml +189 -33
- package/docs/ADDING_NEW_ENGINE.md +10 -0
- package/docs/ARGO_INTRO.md +1 -1
- package/docs/CHANGELOG.md +38 -0
- package/docs/ENGINE_CATALOG.md +102 -89
- package/docs/MCP_SETUP.md +10 -1
- package/docs/RELEASE_NOTES_v2.14.1.md +4 -4
- package/docs/RELEASE_NOTES_v2.15.0.md +50 -0
- package/docs/RELEASE_NOTES_v2.16.0.md +58 -0
- package/docs/RELEASING.md +1 -1
- package/engines/specs/ai_labs.yaml +89 -0
- package/engines/specs/archive_org.yaml +1 -1
- package/engines/specs/bilibili_hot.yaml +11 -1
- package/engines/specs/brave.yaml +3 -3
- package/engines/specs/carbon_intensity.yaml +1 -1
- package/engines/specs/cisa_alerts.yaml +40 -0
- package/engines/specs/cn_ai_news.yaml +10 -8
- package/engines/specs/crates.yaml +1 -1
- package/engines/specs/crossref.yaml +4 -2
- package/engines/specs/crt_sh.yaml +1 -1
- package/engines/specs/dblp.yaml +1 -1
- package/engines/specs/devto.yaml +1 -1
- package/engines/specs/digup.yaml +11 -6
- package/engines/specs/docker_hub.yaml +1 -1
- package/engines/specs/douyin_hot.yaml +11 -1
- package/engines/specs/dw_news.yaml +4 -2
- package/engines/specs/eng_blogs.yaml +63 -0
- package/engines/specs/europeana.yaml +3 -4
- package/engines/specs/europepmc.yaml +1 -1
- package/engines/specs/felo.yaml +3 -3
- package/engines/specs/firecrawl.yaml +3 -0
- package/engines/specs/fourget.yaml +5 -2
- package/engines/specs/france24.yaml +6 -4
- package/engines/specs/fxtwitter.yaml +30 -7
- package/engines/specs/gbfs_nyc.yaml +1 -1
- package/engines/specs/gleif.yaml +1 -1
- package/engines/specs/gov_regulations.yaml +1 -1
- package/engines/specs/grepapp_mcp.yaml +62 -0
- package/engines/specs/guardian_rss.yaml +6 -4
- package/engines/specs/hf_datasets.yaml +1 -1
- package/engines/specs/huggingface.yaml +1 -1
- package/engines/specs/itotii.yaml +13 -1
- package/engines/specs/keenable.yaml +7 -1
- package/engines/specs/linux_do.yaml +63 -0
- package/engines/specs/lobsters.yaml +41 -0
- package/engines/specs/local_crossref.yaml +3 -1
- package/engines/specs/local_github.yaml +1 -1
- package/engines/specs/local_npm.yaml +6 -0
- package/engines/specs/local_openstreetmap.yaml +1 -1
- package/engines/specs/local_seek.yaml +6 -0
- package/engines/specs/maven.yaml +1 -1
- package/engines/specs/mdn.yaml +1 -1
- package/engines/specs/musicbrainz.yaml +1 -1
- package/engines/specs/nasa_images.yaml +1 -1
- package/engines/specs/nhtsa_vpic.yaml +6 -3
- package/engines/specs/npm.yaml +1 -1
- package/engines/specs/nuget.yaml +1 -1
- package/engines/specs/nvd.yaml +1 -1
- package/engines/specs/open_meteo.yaml +1 -1
- package/engines/specs/openalex.yaml +4 -2
- package/engines/specs/openreview.yaml +1 -1
- package/engines/specs/polymarket.yaml +1 -1
- package/engines/specs/redskill.yaml +2 -0
- package/engines/specs/searxng.yaml +4 -2
- package/engines/specs/sec_edgar.yaml +9 -4
- package/engines/specs/steam.yaml +1 -1
- package/engines/specs/tinyfish.yaml +2 -0
- package/engines/specs/tinyfish_news.yaml +2 -0
- package/engines/specs/tinyfish_paper.yaml +2 -0
- package/engines/specs/toutiao_hot.yaml +11 -1
- package/engines/specs/train.yaml +3 -0
- package/engines/specs/twitter.yaml +4 -0
- package/engines/specs/unpaywall.yaml +6 -0
- package/engines/specs/vam.yaml +17 -3
- package/engines/specs/weibo_hot.yaml +11 -1
- package/engines/specs/wikidata.yaml +1 -1
- package/engines/specs/wikipedia.yaml +1 -1
- package/engines/specs/wolframalpha.yaml +3 -3
- package/engines/specs/xiaohongshu.yaml +2 -0
- package/engines/specs/zhihu.yaml +3 -18
- package/engines/specs/zhihu_hot_app.yaml +1 -1
- package/engines/specs/zhihu_kb.yaml +18 -0
- package/engines/specs/zhihu_questions.yaml +19 -0
- package/package.json +4 -2
- package/packages/dsh-plugin/README.md +9 -14
- package/packages/dsh-plugin/dsh/client.js +481 -1037
- package/packages/dsh-plugin/dsh/diagnostics.js +71 -20
- package/packages/dsh-plugin/dsh/index.js +6 -0
- package/packages/dsh-plugin/dsh/runner.js +3 -1
- package/packages/dsh-plugin/dsh/workbench-client.js +796 -0
- package/packages/dsh-plugin/dsh/workbench-md.js +386 -0
- package/packages/dsh-plugin/dsh/workbench-suggestions.js +148 -0
- package/packages/dsh-plugin/dsh/workbench.js +966 -0
- package/packages/dsh-plugin/icon.svg +23 -0
- package/packages/dsh-plugin/package.json +10 -3
- package/packages/dsh-plugin/scripts/sync-local.mjs +87 -0
- package/packages/dsh-plugin/scripts/sync-local.sh +13 -1
- package/packages/dsh-plugin/test/diagnostics.test.js +38 -1
- package/packages/dsh-plugin/test/size-gate.test.js +2 -9
- package/packages/dsh-plugin/test/workbench.test.js +92 -0
- package/scripts/adaptive.py +7 -1
- package/scripts/archive_run.py +112 -53
- package/scripts/argo_paths.py +42 -5
- package/scripts/badcase_ledger.py +117 -9
- package/scripts/build_concept_table.py +112 -55
- package/scripts/cache.py +6 -2
- package/scripts/caliber_isolation.py +60 -23
- package/scripts/circuit_breaker.py +72 -11
- package/scripts/cli_io.py +20 -2
- package/scripts/config_cache.py +44 -1
- package/scripts/daemon.py +151 -51
- package/scripts/dormant_ledger.py +23 -9
- package/scripts/engine_dispatch.py +8 -5
- package/scripts/engine_env.py +191 -1
- package/scripts/engine_families.py +50 -7
- package/scripts/engine_states.py +3 -50
- package/scripts/engine_validate.py +13 -45
- package/scripts/engines.py +15 -31
- package/scripts/engines_base.py +66 -61
- package/scripts/engines_builders.py +0 -15
- package/scripts/engines_builders_archive.py +4 -3
- package/scripts/engines_builders_batch10.py +346 -100
- package/scripts/engines_builders_batch11.py +4 -76
- package/scripts/engines_builders_batch13.py +4 -3
- package/scripts/engines_builders_batch14.py +2 -1
- package/scripts/engines_builders_batch15.py +2 -1
- package/scripts/engines_builders_batch9.py +16 -25
- package/scripts/engines_builders_cn.py +7 -201
- package/scripts/engines_builders_data.py +12 -11
- package/scripts/engines_builders_data_macro.py +5 -4
- package/scripts/engines_builders_dsh.py +2 -1
- package/scripts/engines_builders_feeds.py +76 -11
- package/scripts/engines_builders_finance.py +2 -1
- package/scripts/engines_builders_intl.py +18 -117
- package/scripts/engines_builders_media.py +59 -12
- package/scripts/engines_builders_pixiv.py +2 -16
- package/scripts/engines_builders_science.py +8 -7
- package/scripts/engines_builders_search.py +7 -14
- package/scripts/engines_builders_skill.py +2 -1
- package/scripts/engines_builders_tech.py +8 -17
- package/scripts/engines_builders_weather.py +241 -0
- package/scripts/engines_fields.py +91 -0
- package/scripts/engines_http.py +184 -0
- package/scripts/engines_mcp.py +405 -0
- package/scripts/engines_parsers.py +13 -369
- package/scripts/engines_schema_drift.py +260 -0
- package/scripts/evidence.py +13 -0
- package/scripts/evidence_loop.py +19 -4
- package/scripts/extend_route_labels.py +6 -0
- package/scripts/fetch_jina.py +98 -0
- package/scripts/fetch_jsrun.py +15 -11
- package/scripts/fetch_v3.py +79 -120
- package/scripts/fulltext_store.py +42 -1
- package/scripts/fxtwitter_api.py +8 -7
- package/scripts/gen_engine_catalog.py +2 -2
- package/scripts/general_pool.py +15 -4
- package/scripts/health_check.py +1 -1
- package/scripts/image_vision/vision_probe +0 -0
- package/scripts/install.sh +2 -0
- package/scripts/link_source.py +65 -24
- package/scripts/local_seek_adapter.py +57 -17
- package/scripts/matrix_search_eval.py +8 -10
- package/scripts/mcp_handlers.py +53 -31
- package/scripts/mcp_handlers_surface.py +6 -18
- package/scripts/mcp_transport.py +10 -5
- package/scripts/min_version_scan.py +7 -3
- package/scripts/network_aware.py +7 -13
- package/scripts/numeric_verify.py +3 -2
- package/scripts/output_transparency.py +3 -0
- package/scripts/pre-commit +45 -43
- package/scripts/query_understanding.py +30 -6
- package/scripts/quota.py +36 -30
- package/scripts/rank_signals.py +9 -0
- package/scripts/recompute.py +15 -5
- package/scripts/recovery.py +38 -29
- package/scripts/recovery_runner.py +29 -10
- package/scripts/redskill/redskill_engine.py +2 -1
- package/scripts/release.py +14 -26
- package/scripts/release_check.py +5 -25
- package/scripts/replay_eval.py +2 -2
- package/scripts/research_cli.py +40 -0
- package/scripts/research_notes.py +368 -0
- package/scripts/route.py +40 -70
- package/scripts/route_audit.py +259 -0
- package/scripts/route_combo.py +21 -6
- package/scripts/route_domains.py +150 -23
- package/scripts/route_lang.py +20 -7
- package/scripts/route_log.py +26 -9
- package/scripts/route_policy.py +85 -6
- package/scripts/route_telemetry_export.py +199 -0
- package/scripts/rrf_classic.py +5 -22
- package/scripts/search.py +2 -1
- package/scripts/search_attribution.py +53 -10
- package/scripts/search_entry.py +32 -1
- package/scripts/search_output.py +23 -11
- package/scripts/search_pipeline.py +15 -3
- package/scripts/search_rank.py +21 -11
- package/scripts/semantic_evidence.py +394 -178
- package/scripts/serp_guard.py +13 -1
- package/scripts/settings_page.py +4 -3
- package/scripts/single_flight.py +1 -1
- package/scripts/social_engines/hackernews_engine.py +2 -1
- package/scripts/social_engines/reddit_engine.py +2 -1
- package/scripts/social_engines/xiaohongshu_engine.py +2 -1
- package/scripts/social_engines/zhihu_engine.py +252 -43
- package/scripts/sogou_weixin_browser.py +5 -6
- package/scripts/source_audit.py +44 -9
- package/scripts/source_ledger.py +2 -15
- package/scripts/source_selection.py +45 -20
- package/scripts/straggler_policy.py +1 -2
- package/scripts/sync_backends.py +17 -0
- package/scripts/tfidf_router.py +23 -11
- package/scripts/time_utils.py +54 -1
- package/scripts/train.py +68 -2
- package/scripts/usage_log.py +50 -10
- package/scripts/watch.py +3 -3
- package/scripts/zhihu_quota.py +2 -1
- package/sub-skills/argo-wide-research/SKILL.md +70 -0
- package/sub-skills/ego-search/{SKILL.md → README.md} +15 -47
- package/sub-skills/ego-search/scripts/ego_search.py +13 -4
- package/sub-skills/js-run/{SKILL.md → README.md} +3 -20
- package/sub-skills/local-search/{SKILL.md → README.md} +3 -8
- package/sub-skills/local-search/engine_registry.py +32 -7
- package/sub-skills/local-seek/SKILL.md +20 -22
- package/sub-skills/local-seek/scripts/seek_fts.py +58 -3
- package/scripts/caliber_dedupe.py +0 -66
- package/scripts/engines_builders_batch16.py +0 -13
- package/scripts/health_probe.py +0 -253
- package/scripts/social_engines/twitter_engine.py +0 -514
- package/scripts/sync_installs.py +0 -29
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
2
|
+
"""批次十构建器:知乎开放平台引擎簇(zhihu_global / zhihu / zhihu_questions / zhihu_kb)。
|
|
3
3
|
|
|
4
|
-
为什么不在 engines_builders_cn.py
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
不是把数字往上调」,故按 batch9 命名先例落新文件(新增文件天然合规)。
|
|
8
|
-
|
|
9
|
-
zhihu_global 说明:cn 里的旧实现与本文件同名实现并存,engines.py 注册表已
|
|
10
|
-
指向本文件版本(候选池取满 + 错误文案行动提示两处补强);cn 旧版仅在
|
|
11
|
-
engines_builders 聚合层保留转出,属被取代代码。
|
|
4
|
+
为什么不在 engines_builders_cn.py 里加:该文件被 test_module_size_gate.py
|
|
5
|
+
祖父清单冻结在 2319 行(只能减不能增),故统一收敛在本模块维护(远低于
|
|
6
|
+
1000 行上限)。
|
|
12
7
|
"""
|
|
13
8
|
|
|
14
9
|
from __future__ import annotations
|
|
@@ -16,7 +11,6 @@ from __future__ import annotations
|
|
|
16
11
|
import json
|
|
17
12
|
import re
|
|
18
13
|
import sys
|
|
19
|
-
import time
|
|
20
14
|
import urllib.error
|
|
21
15
|
import urllib.parse
|
|
22
16
|
import urllib.request
|
|
@@ -24,50 +18,27 @@ from datetime import datetime
|
|
|
24
18
|
from typing import Any
|
|
25
19
|
|
|
26
20
|
from engine_env import get_env
|
|
27
|
-
|
|
28
21
|
from engines_base import (
|
|
29
22
|
http_open,
|
|
30
23
|
rank_score,
|
|
31
24
|
safe_search,
|
|
32
25
|
)
|
|
33
26
|
from engines_builders_cn import _parse_site_filter
|
|
27
|
+
from social_engines import zhihu_engine as _ze
|
|
34
28
|
|
|
35
29
|
|
|
36
|
-
|
|
37
|
-
"""延迟创建 logger,避免 import logging 的重量级 import 链(traceback→dataclasses→inspect)。"""
|
|
38
|
-
_logger = None
|
|
39
|
-
|
|
40
|
-
def __getattr__(self, name: str):
|
|
41
|
-
if _LazyLogger._logger is None:
|
|
42
|
-
import logging
|
|
43
|
-
_LazyLogger._logger = logging.getLogger("unified_search.engines")
|
|
44
|
-
if not _LazyLogger._logger.handlers:
|
|
45
|
-
_LazyLogger._logger.setLevel(logging.WARNING)
|
|
46
|
-
_LazyLogger._logger.addHandler(logging.StreamHandler(sys.stderr))
|
|
47
|
-
return getattr(_LazyLogger._logger, name)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
logger = _LazyLogger()
|
|
51
|
-
|
|
30
|
+
from engines_http import lazy_logger
|
|
52
31
|
|
|
53
|
-
|
|
32
|
+
logger = lazy_logger()
|
|
54
33
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
def _zhihu_error_item(code: Any, message: Any) -> dict[str, Any]:
|
|
66
|
-
"""非成功响应的 error item:保留原始 code/message,时钟类追加行动提示。"""
|
|
67
|
-
text = f"zhihu_global Code={code} {str(message or '')[:100]}"
|
|
68
|
-
if _ZHIHU_CLOCK_HINT_RE.search(str(message or "")):
|
|
69
|
-
text = f"{text};hint: {_ZHIHU_CLOCK_HINT}"
|
|
70
|
-
return {"error": text, "source": "zhihu_global"}
|
|
34
|
+
_ZHIHU_COUNT_MAX = 20 # global_search / question_recommendations 官方上限
|
|
35
|
+
_ZHIHU_KB_LIMIT_MAX = 10 # knowledge/search 官方上限
|
|
36
|
+
_ZHIHU_QUESTION_URL_RE = re.compile(r"(https?://(?:www\.)?zhihu\.com/question/\d+)")
|
|
37
|
+
_ZHIHU_QUESTION_ID_RE = re.compile(r"(?:^|\s)(?:q|question):(\d+)(?=\s|$)", re.I)
|
|
38
|
+
_KB_LIST_QUERY_RE = re.compile(r"^(?:bases?|list|知识库列表|我的知识库)(?::\s*(.*))?$", re.I)
|
|
39
|
+
_KB_SCOPE_OP_RE = re.compile(r"(?:^|\s)scope:(personal|subscription|public|all|created|subscribed)(?=\s|$)", re.I)
|
|
40
|
+
_KB_ID_OP_RE = re.compile(r"(?:^|\s)kb:(\d+)(?=\s|$)", re.I)
|
|
41
|
+
_DB_OPERATOR_RE = re.compile(r"(?:^|\s)db:(all|realtime|static)(?=\s|$)", re.I)
|
|
71
42
|
|
|
72
43
|
|
|
73
44
|
def _zhihu_epoch(value: Any) -> int | None:
|
|
@@ -81,9 +52,6 @@ def _zhihu_epoch(value: Any) -> int | None:
|
|
|
81
52
|
return None
|
|
82
53
|
|
|
83
54
|
|
|
84
|
-
_DB_OPERATOR_RE = re.compile(r"(?:^|\s)db:(all|realtime|static)(?=\s|$)", re.I)
|
|
85
|
-
|
|
86
|
-
|
|
87
55
|
def _parse_db_operator(query: str) -> tuple[str, str]:
|
|
88
56
|
"""解析 `db:realtime|static|all` 查询操作符,返回 (db, 剩余查询)。"""
|
|
89
57
|
match = _DB_OPERATOR_RE.search(query or "")
|
|
@@ -106,18 +74,40 @@ def _build_zhihu_publish_filter(since: Any, until: Any) -> str:
|
|
|
106
74
|
return " AND ".join(parts)
|
|
107
75
|
|
|
108
76
|
|
|
77
|
+
def _zhihu_http_json(
|
|
78
|
+
url: str,
|
|
79
|
+
secret: str,
|
|
80
|
+
source: str,
|
|
81
|
+
timeout: float,
|
|
82
|
+
engine_name: str,
|
|
83
|
+
*,
|
|
84
|
+
method: str = "GET",
|
|
85
|
+
body: dict[str, Any] | None = None,
|
|
86
|
+
) -> tuple[dict[str, Any] | None, dict[str, Any] | None]:
|
|
87
|
+
"""统一执行知乎开放平台 JSON 请求并收敛 HTTP/业务错误为 error item。"""
|
|
88
|
+
headers = _ze.zhihu_headers(secret)
|
|
89
|
+
data_bytes = json.dumps(body, ensure_ascii=False).encode("utf-8") if body is not None else None
|
|
90
|
+
req = urllib.request.Request(url, data=data_bytes, headers=headers, method=method)
|
|
91
|
+
try:
|
|
92
|
+
with http_open(req, timeout=timeout, engine=engine_name) as resp:
|
|
93
|
+
payload = json.loads(resp.read().decode("utf-8", "replace"))
|
|
94
|
+
except urllib.error.HTTPError as e:
|
|
95
|
+
return None, {"error": f"{source} API HTTP {e.code}", "source": source}
|
|
96
|
+
except Exception as e:
|
|
97
|
+
logger.warning(f"{source} 失败: {e}")
|
|
98
|
+
return None, {"error": f"{source} {type(e).__name__}: {e}", "source": source}
|
|
99
|
+
if not isinstance(payload, dict):
|
|
100
|
+
return None, {"error": f"{source} 响应格式异常", "source": source}
|
|
101
|
+
if payload.get("Code") not in (0, None):
|
|
102
|
+
logger.warning(f"{source} 返回码异常: {payload.get('Code')} {payload.get('Message')}")
|
|
103
|
+
return None, _ze.zhihu_error_item(source, payload.get("Code"), payload.get("Message"))
|
|
104
|
+
return payload, None
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
# ── 1. zhihu_global:知乎开放平台全网搜索 ────────────────────────────────────
|
|
108
|
+
|
|
109
109
|
def _build_zhihu_global_engine(spec: dict[str, Any]) -> Any:
|
|
110
|
-
"""知乎开放平台全网搜索(developer.zhihu.com global_search)。
|
|
111
|
-
|
|
112
|
-
在 cn 旧版语义之上的两处微机制补强(2026-09-26):
|
|
113
|
-
1. 候选池取满再截断:Filter host== 是服务端在候选池上后筛,只取 n 条
|
|
114
|
-
会把「过滤后恰好命中」的候选一并筛掉,空结果会被模型读成「知乎没有
|
|
115
|
-
相关内容」;带站点限定或时间下限(since)时取满端点 Count 上限,
|
|
116
|
-
客户端再截断到 n。since 的时间 Filter 语法官方未文档化,先只承担
|
|
117
|
-
「取满候选池」语义。
|
|
118
|
-
2. 错误码 → 行动提示:时钟偏差类错误给「校时」提示而非裸错误。
|
|
119
|
-
查询语法与 cn 版一致:site:/host: → Filter host==,普通查询 SearchDB=all。
|
|
120
|
-
"""
|
|
110
|
+
"""知乎开放平台全网搜索(developer.zhihu.com global_search)。"""
|
|
121
111
|
timeout = spec.get("timeout", 10)
|
|
122
112
|
|
|
123
113
|
@safe_search
|
|
@@ -127,16 +117,11 @@ def _build_zhihu_global_engine(spec: dict[str, Any]) -> Any:
|
|
|
127
117
|
if not secret:
|
|
128
118
|
return []
|
|
129
119
|
|
|
130
|
-
# 解析 site:/host: 站点限定语法 → Filter: host=="..."(实现单点在 cn)
|
|
131
120
|
filter_expr, search_query = _parse_site_filter(query)
|
|
132
|
-
# db:realtime|static|all:官方 SearchDB 选择(默认 all)
|
|
133
121
|
db, search_query = _parse_db_operator(search_query or query)
|
|
134
|
-
|
|
135
|
-
_time_filter = _build_zhihu_publish_filter(kwargs.get("since"),
|
|
136
|
-
kwargs.get("until"))
|
|
122
|
+
_time_filter = _build_zhihu_publish_filter(kwargs.get("since"), kwargs.get("until"))
|
|
137
123
|
if _time_filter:
|
|
138
|
-
filter_expr =
|
|
139
|
-
if filter_expr else _time_filter)
|
|
124
|
+
filter_expr = f"{filter_expr} AND {_time_filter}" if filter_expr else _time_filter
|
|
140
125
|
|
|
141
126
|
filtered = bool(filter_expr or db != "all")
|
|
142
127
|
params: dict[str, Any] = {
|
|
@@ -147,43 +132,25 @@ def _build_zhihu_global_engine(spec: dict[str, Any]) -> Any:
|
|
|
147
132
|
if filter_expr:
|
|
148
133
|
params["Filter"] = filter_expr
|
|
149
134
|
url = "https://developer.zhihu.com/api/v1/content/global_search?" + urllib.parse.urlencode(params)
|
|
150
|
-
|
|
151
|
-
"
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
data = json.loads(resp.read().decode("utf-8", "replace"))
|
|
159
|
-
except urllib.error.HTTPError as e:
|
|
160
|
-
# 401/403 等必须暴露为 error item 而非静默空——调用侧把
|
|
161
|
-
# 「没配置」「鉴权失败」「没结果」区分开才可行动
|
|
162
|
-
return [{"error": f"zhihu_global API HTTP {e.code}", "source": "zhihu_global"}]
|
|
163
|
-
except Exception as e:
|
|
164
|
-
logger.warning(f"zhihu_global 失败: {e}")
|
|
165
|
-
return [{"error": f"zhihu_global {type(e).__name__}: {e}", "source": "zhihu_global"}]
|
|
166
|
-
if data.get("Code") not in (0, None):
|
|
167
|
-
# 30001=频率限制 30002=配额限制,显式暴露供配额状态机归类
|
|
168
|
-
logger.warning(f"zhihu_global 返回码异常: {data.get('Code')} {data.get('Message')}")
|
|
169
|
-
return [_zhihu_error_item(data.get("Code"), data.get("Message"))]
|
|
170
|
-
items = (data.get("Data") or {}).get("Items") or []
|
|
171
|
-
results = []
|
|
172
|
-
for _rk3, item in enumerate(items[:n]):
|
|
135
|
+
data, err = _zhihu_http_json(
|
|
136
|
+
url, secret, "zhihu_global", to, spec.get("_name", "zhihu_global")
|
|
137
|
+
)
|
|
138
|
+
if err:
|
|
139
|
+
return [err]
|
|
140
|
+
items = ((data or {}).get("Data") or {}).get("Items") or []
|
|
141
|
+
results: list[dict[str, Any]] = []
|
|
142
|
+
for rk, item in enumerate(items[:n]):
|
|
173
143
|
if not isinstance(item, dict):
|
|
174
144
|
continue
|
|
175
|
-
title = (item.get("Title")
|
|
176
|
-
# API 标题统一带「 - 知乎」尾巴:截断前剥掉(先剥再切,尾巴不占正文)
|
|
177
|
-
if title.endswith(" - 知乎"):
|
|
178
|
-
title = title[: -len(" - 知乎")].rstrip()
|
|
145
|
+
title = _ze.clean_zhihu_title(item.get("Title"))
|
|
179
146
|
url_ = item.get("Url") or ""
|
|
180
|
-
snippet = item.get("ContentText") or ""
|
|
181
|
-
# 去 <em> 高亮标签
|
|
182
|
-
snippet = re.sub(r"<[^>]+>", "", snippet).strip()
|
|
147
|
+
snippet = _ze.strip_html_tags(item.get("ContentText") or "")
|
|
183
148
|
if not title and not url_:
|
|
184
149
|
continue
|
|
185
|
-
|
|
186
|
-
|
|
150
|
+
upstream_auth = _ze.parse_authority_level(item.get("AuthorityLevel"))
|
|
151
|
+
badge_text = str(item.get("AuthorBadgeText") or "").strip()
|
|
152
|
+
top_comments = _ze.extract_comment_snippets(item.get("CommentInfoList"))
|
|
153
|
+
social_meta: dict[str, Any] = {
|
|
187
154
|
"author": item.get("AuthorName") or "",
|
|
188
155
|
"content_type": item.get("ContentType") or "",
|
|
189
156
|
"vote_up": item.get("VoteUpCount") or 0,
|
|
@@ -191,14 +158,293 @@ def _build_zhihu_global_engine(spec: dict[str, Any]) -> Any:
|
|
|
191
158
|
"authority_level": item.get("AuthorityLevel") or "",
|
|
192
159
|
"edit_time": item.get("EditTime") or 0,
|
|
193
160
|
}
|
|
194
|
-
|
|
161
|
+
if badge_text:
|
|
162
|
+
social_meta["author_badge_text"] = badge_text
|
|
163
|
+
if top_comments:
|
|
164
|
+
social_meta["top_comments"] = top_comments
|
|
165
|
+
|
|
166
|
+
entry: dict[str, Any] = {
|
|
195
167
|
"title": title[:200],
|
|
196
168
|
"url": url_,
|
|
197
169
|
"snippet": snippet[:300],
|
|
198
170
|
"source": "zhihu_global",
|
|
199
|
-
"score": rank_score(0.7,
|
|
200
|
-
"
|
|
171
|
+
"score": rank_score(0.7, rk),
|
|
172
|
+
"published_at": _ze.epoch_to_iso(item.get("EditTime")),
|
|
201
173
|
"social_meta": social_meta,
|
|
174
|
+
}
|
|
175
|
+
# 只在有效 0-4 时透传 upstream_authority;空值交给 rank_signals/search_output 兜底
|
|
176
|
+
if upstream_auth is not None:
|
|
177
|
+
entry["upstream_authority"] = upstream_auth
|
|
178
|
+
results.append(entry)
|
|
179
|
+
return results
|
|
180
|
+
|
|
181
|
+
return _engine
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
# ── 2. zhihu:知乎站内结构化搜索(含问题下钻 + AuthorityLevel)──────────────
|
|
185
|
+
|
|
186
|
+
def _build_zhihu_engine(spec: dict[str, Any]) -> Any:
|
|
187
|
+
"""知乎站内搜索(复用 social_engines/zhihu_engine.py 结构化解析与问题下钻)。"""
|
|
188
|
+
timeout = float(spec.get("timeout", 10))
|
|
189
|
+
|
|
190
|
+
@safe_search
|
|
191
|
+
def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
|
|
192
|
+
to = float(_timeout or timeout)
|
|
193
|
+
secret = get_env(["ARGO_ZHIHU_ACCESS_SECRET", "ZHIHU_ACCESS_SECRET"])
|
|
194
|
+
if not secret:
|
|
195
|
+
return []
|
|
196
|
+
expand_questions = bool(kwargs.get("expand_questions", True))
|
|
197
|
+
return _ze.search(
|
|
198
|
+
query,
|
|
199
|
+
n=int(n or 5),
|
|
200
|
+
expand_questions=expand_questions,
|
|
201
|
+
_secret_override=secret,
|
|
202
|
+
_timeout=to,
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
return _engine
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
# ── 3. zhihu_questions:母问题发现与同题回答摘要(只读,explicit_only)────────
|
|
209
|
+
|
|
210
|
+
def _build_zhihu_questions_engine(spec: dict[str, Any]) -> Any:
|
|
211
|
+
"""知乎问题发现(question_recommendations)与问题下回答摘要(question_answers)。"""
|
|
212
|
+
timeout = float(spec.get("timeout", 10))
|
|
213
|
+
|
|
214
|
+
@safe_search
|
|
215
|
+
def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
|
|
216
|
+
to = float(_timeout or timeout)
|
|
217
|
+
secret = get_env(["ARGO_ZHIHU_ACCESS_SECRET", "ZHIHU_ACCESS_SECRET"])
|
|
218
|
+
if not secret:
|
|
219
|
+
return []
|
|
220
|
+
q = (query or "").strip()
|
|
221
|
+
if not q:
|
|
222
|
+
return []
|
|
223
|
+
|
|
224
|
+
m_url = _ZHIHU_QUESTION_URL_RE.search(q)
|
|
225
|
+
m_qid = _ZHIHU_QUESTION_ID_RE.search(q) if not m_url else None
|
|
226
|
+
if m_url or m_qid:
|
|
227
|
+
clean_qurl = m_url.group(1) if m_url else f"https://www.zhihu.com/question/{m_qid.group(1)}"
|
|
228
|
+
params = urllib.parse.urlencode({
|
|
229
|
+
"QuestionUrl": clean_qurl,
|
|
230
|
+
"Limit": str(max(1, min(int(n or 5), 50))),
|
|
231
|
+
"Offset": "0",
|
|
232
|
+
})
|
|
233
|
+
url = f"https://developer.zhihu.com/api/v1/content/question_answers?{params}"
|
|
234
|
+
data, err = _zhihu_http_json(
|
|
235
|
+
url, secret, "zhihu_questions", to, spec.get("_name", "zhihu_questions")
|
|
236
|
+
)
|
|
237
|
+
if err:
|
|
238
|
+
return [err]
|
|
239
|
+
items = ((data or {}).get("Data") or {}).get("Items") or []
|
|
240
|
+
results: list[dict[str, Any]] = []
|
|
241
|
+
for rk, item in enumerate(items[:n]):
|
|
242
|
+
if not isinstance(item, dict):
|
|
243
|
+
continue
|
|
244
|
+
summary = _ze.strip_html_tags(item.get("Summary") or "")
|
|
245
|
+
ans_url = item.get("Url") or ""
|
|
246
|
+
token = str(item.get("ContentToken") or "")
|
|
247
|
+
ctype = str(item.get("ContentType") or "answer").lower()
|
|
248
|
+
if not summary and not ans_url:
|
|
249
|
+
continue
|
|
250
|
+
head = summary[:60] + ("..." if len(summary) > 60 else "")
|
|
251
|
+
results.append({
|
|
252
|
+
"title": head or f"回答 {token}",
|
|
253
|
+
"url": ans_url or clean_qurl,
|
|
254
|
+
"snippet": summary[:500],
|
|
255
|
+
"source": "zhihu_questions",
|
|
256
|
+
"score": rank_score(0.85, rk),
|
|
257
|
+
"social_meta": {
|
|
258
|
+
"platform": "zhihu",
|
|
259
|
+
"content_type": ctype,
|
|
260
|
+
"token": token,
|
|
261
|
+
"question_url": clean_qurl,
|
|
262
|
+
"mode": "question_answers",
|
|
263
|
+
},
|
|
264
|
+
})
|
|
265
|
+
return results
|
|
266
|
+
|
|
267
|
+
# 主题推荐模式:按关键词荐题(画像推荐属创作侧选题,2026-11-15 移出搜索面)
|
|
268
|
+
count = max(1, min(int(n or 5), _ZHIHU_COUNT_MAX))
|
|
269
|
+
rec_params: dict[str, str] = {"Count": str(count), "Query": q}
|
|
270
|
+
url = (
|
|
271
|
+
"https://developer.zhihu.com/api/v1/user/question_recommendations?"
|
|
272
|
+
+ urllib.parse.urlencode(rec_params)
|
|
273
|
+
)
|
|
274
|
+
data, err = _zhihu_http_json(
|
|
275
|
+
url, secret, "zhihu_questions", to, spec.get("_name", "zhihu_questions")
|
|
276
|
+
)
|
|
277
|
+
if err:
|
|
278
|
+
return [err]
|
|
279
|
+
items = ((data or {}).get("Data") or {}).get("Items") or []
|
|
280
|
+
results = []
|
|
281
|
+
for rk, item in enumerate(items[:n]):
|
|
282
|
+
if not isinstance(item, dict):
|
|
283
|
+
continue
|
|
284
|
+
title = _ze.clean_zhihu_title(item.get("Title"))
|
|
285
|
+
q_url = item.get("Url") or ""
|
|
286
|
+
if not title and not q_url:
|
|
287
|
+
continue
|
|
288
|
+
# 上游荐题实测只回 Title/Url(2026-11-15 抓包),无源摘要就不造 snippet
|
|
289
|
+
results.append({
|
|
290
|
+
"title": title[:200] or q_url,
|
|
291
|
+
"url": q_url,
|
|
292
|
+
"source": "zhihu_questions",
|
|
293
|
+
"score": rank_score(0.8, rk),
|
|
294
|
+
"social_meta": {
|
|
295
|
+
"platform": "zhihu",
|
|
296
|
+
"content_type": "question",
|
|
297
|
+
"mode": "query",
|
|
298
|
+
},
|
|
202
299
|
})
|
|
203
300
|
return results
|
|
301
|
+
|
|
302
|
+
return _engine
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
# ── 4. zhihu_kb:知乎知识库只读 RAG 检索与列库(explicit_only)──────────────
|
|
306
|
+
|
|
307
|
+
def _parse_kb_query(query: str) -> tuple[list[str], list[str], str]:
|
|
308
|
+
"""解析 `scope:` 与 `kb:<id>` 操作符,返回 (scopes, base_ids, 剩余查询)。"""
|
|
309
|
+
scopes: list[str] = []
|
|
310
|
+
base_ids: list[str] = []
|
|
311
|
+
text = (query or "").strip()
|
|
312
|
+
|
|
313
|
+
for m in _KB_SCOPE_OP_RE.finditer(text):
|
|
314
|
+
sc = m.group(1).lower()
|
|
315
|
+
if sc == "all":
|
|
316
|
+
for s in ("personal", "subscription", "public"):
|
|
317
|
+
if s not in scopes:
|
|
318
|
+
scopes.append(s)
|
|
319
|
+
elif sc in ("personal", "subscription", "public") and sc not in scopes:
|
|
320
|
+
scopes.append(sc)
|
|
321
|
+
text = _KB_SCOPE_OP_RE.sub(" ", text).strip()
|
|
322
|
+
|
|
323
|
+
for m in _KB_ID_OP_RE.finditer(text):
|
|
324
|
+
bid = m.group(1)
|
|
325
|
+
if bid not in base_ids:
|
|
326
|
+
base_ids.append(bid)
|
|
327
|
+
text = _KB_ID_OP_RE.sub(" ", text).strip()
|
|
328
|
+
return scopes, base_ids, text
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
def _build_zhihu_kb_engine(spec: dict[str, Any]) -> Any:
|
|
332
|
+
"""知乎知识库只读检索(/api/v1/knowledge/bases 与 /api/v1/knowledge/search)。"""
|
|
333
|
+
timeout = float(spec.get("timeout", 10))
|
|
334
|
+
|
|
335
|
+
@safe_search
|
|
336
|
+
def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
|
|
337
|
+
to = float(_timeout or timeout)
|
|
338
|
+
secret = get_env(["ARGO_ZHIHU_ACCESS_SECRET", "ZHIHU_ACCESS_SECRET"])
|
|
339
|
+
if not secret:
|
|
340
|
+
return []
|
|
341
|
+
q = (query or "").strip()
|
|
342
|
+
if not q:
|
|
343
|
+
return []
|
|
344
|
+
|
|
345
|
+
m_list = _KB_LIST_QUERY_RE.match(q)
|
|
346
|
+
if m_list:
|
|
347
|
+
scope_arg = (m_list.group(1) or "").strip().lower()
|
|
348
|
+
scope = scope_arg if scope_arg in ("all", "created", "subscribed") else "all"
|
|
349
|
+
url = f"https://developer.zhihu.com/api/v1/knowledge/bases?Scope={scope}"
|
|
350
|
+
data, err = _zhihu_http_json(
|
|
351
|
+
url, secret, "zhihu_kb", to, spec.get("_name", "zhihu_kb")
|
|
352
|
+
)
|
|
353
|
+
if err:
|
|
354
|
+
return [err]
|
|
355
|
+
items = ((data or {}).get("Data") or {}).get("Items") or []
|
|
356
|
+
results: list[dict[str, Any]] = []
|
|
357
|
+
for rk, item in enumerate(items[:n]):
|
|
358
|
+
if not isinstance(item, dict):
|
|
359
|
+
continue
|
|
360
|
+
kb_id = str(item.get("KnowledgeBaseID") or "")
|
|
361
|
+
name = str(item.get("Name") or kb_id).strip()
|
|
362
|
+
desc = str(item.get("Description") or "").strip()
|
|
363
|
+
rel = str(item.get("Relation") or "")
|
|
364
|
+
cnt = item.get("ContentCount") or 0
|
|
365
|
+
vis = str(item.get("Visibility") or "")
|
|
366
|
+
results.append({
|
|
367
|
+
"title": f"{name} (ID={kb_id})",
|
|
368
|
+
"url": f"https://www.zhihu.com/knowledge-base/{kb_id}" if kb_id else "https://developer.zhihu.com/profile",
|
|
369
|
+
"snippet": f"[{rel}/{vis}] 内容数={cnt}。{desc}"[:400],
|
|
370
|
+
"source": "zhihu_kb",
|
|
371
|
+
"score": rank_score(0.8, rk),
|
|
372
|
+
"published_at": _ze.epoch_to_iso(item.get("UpdatedAt")),
|
|
373
|
+
"social_meta": {
|
|
374
|
+
"platform": "zhihu_kb",
|
|
375
|
+
"knowledge_base_id": kb_id,
|
|
376
|
+
"relation": rel,
|
|
377
|
+
"visibility": vis,
|
|
378
|
+
"content_count": cnt,
|
|
379
|
+
"is_knowledge_base": True,
|
|
380
|
+
},
|
|
381
|
+
})
|
|
382
|
+
return results
|
|
383
|
+
|
|
384
|
+
scopes, base_ids, clean_q = _parse_kb_query(q)
|
|
385
|
+
if not clean_q:
|
|
386
|
+
return []
|
|
387
|
+
if not scopes and not base_ids:
|
|
388
|
+
scopes = ["personal"]
|
|
389
|
+
body: dict[str, Any] = {
|
|
390
|
+
"Query": clean_q,
|
|
391
|
+
"Limit": max(1, min(int(n or 5), _ZHIHU_KB_LIMIT_MAX)),
|
|
392
|
+
}
|
|
393
|
+
if scopes:
|
|
394
|
+
body["RecallScopes"] = scopes
|
|
395
|
+
if base_ids:
|
|
396
|
+
body["KnowledgeBaseIDs"] = base_ids
|
|
397
|
+
|
|
398
|
+
# POST 检索不自动重试,严格单次调用
|
|
399
|
+
data, err = _zhihu_http_json(
|
|
400
|
+
"https://developer.zhihu.com/api/v1/knowledge/search",
|
|
401
|
+
secret,
|
|
402
|
+
"zhihu_kb",
|
|
403
|
+
to,
|
|
404
|
+
spec.get("_name", "zhihu_kb"),
|
|
405
|
+
method="POST",
|
|
406
|
+
body=body,
|
|
407
|
+
)
|
|
408
|
+
if err:
|
|
409
|
+
return [err]
|
|
410
|
+
items = ((data or {}).get("Data") or {}).get("Items") or []
|
|
411
|
+
results = []
|
|
412
|
+
for rk, item in enumerate(items[:n]):
|
|
413
|
+
if not isinstance(item, dict):
|
|
414
|
+
continue
|
|
415
|
+
kb_id = str(item.get("KnowledgeBaseID") or "")
|
|
416
|
+
recall_id = str(item.get("RecallContentID") or "")
|
|
417
|
+
doc_name = str(item.get("DocName") or item.get("Title") or f"知识库片段 {recall_id}").strip()
|
|
418
|
+
origin_url = str(item.get("OriginUrl") or "").strip()
|
|
419
|
+
chunks = item.get("Content")
|
|
420
|
+
if isinstance(chunks, list):
|
|
421
|
+
text = "\n".join(_ze.strip_html_tags(c) for c in chunks if str(c or "").strip())
|
|
422
|
+
else:
|
|
423
|
+
text = _ze.strip_html_tags(chunks or "")
|
|
424
|
+
if not text and not doc_name:
|
|
425
|
+
continue
|
|
426
|
+
if origin_url:
|
|
427
|
+
item_url = origin_url
|
|
428
|
+
elif kb_id:
|
|
429
|
+
# knowledge-base 页公开可达(2026-11-15 实测 200);recall_id 属
|
|
430
|
+
# 服务端检索定位符,不是页面参数,留 social_meta 不进 URL
|
|
431
|
+
item_url = f"https://www.zhihu.com/knowledge-base/{kb_id}"
|
|
432
|
+
else:
|
|
433
|
+
item_url = "https://developer.zhihu.com/profile"
|
|
434
|
+
results.append({
|
|
435
|
+
"title": doc_name[:200],
|
|
436
|
+
"url": item_url,
|
|
437
|
+
"snippet": text[:800],
|
|
438
|
+
"source": "zhihu_kb",
|
|
439
|
+
"score": rank_score(0.85, rk),
|
|
440
|
+
"social_meta": {
|
|
441
|
+
"platform": "zhihu_kb",
|
|
442
|
+
"knowledge_base_id": kb_id,
|
|
443
|
+
"recall_content_id": recall_id,
|
|
444
|
+
"has_origin_url": bool(origin_url),
|
|
445
|
+
"is_knowledge_base": True,
|
|
446
|
+
},
|
|
447
|
+
})
|
|
448
|
+
return results
|
|
449
|
+
|
|
204
450
|
return _engine
|
|
@@ -21,32 +21,20 @@ import urllib.parse
|
|
|
21
21
|
import urllib.request
|
|
22
22
|
from typing import Any
|
|
23
23
|
|
|
24
|
+
from engines_http import UA
|
|
24
25
|
from engines_base import (
|
|
25
26
|
finalize_image_fields,
|
|
26
27
|
rank_score,
|
|
27
28
|
safe_search,
|
|
28
29
|
http_open,
|
|
29
|
-
_http_get_raw,
|
|
30
30
|
)
|
|
31
31
|
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
"""延迟创建 logger,避免 import logging 的重量级 import 链(traceback→dataclasses→inspect)。"""
|
|
35
|
-
_logger = None
|
|
33
|
+
from engines_http import lazy_logger
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
if _LazyLogger._logger is None:
|
|
39
|
-
import logging
|
|
40
|
-
_LazyLogger._logger = logging.getLogger("unified_search.engines")
|
|
41
|
-
if not _LazyLogger._logger.handlers:
|
|
42
|
-
_LazyLogger._logger.setLevel(logging.WARNING)
|
|
43
|
-
_LazyLogger._logger.addHandler(logging.StreamHandler(sys.stderr))
|
|
44
|
-
return getattr(_LazyLogger._logger, name)
|
|
35
|
+
logger = lazy_logger()
|
|
45
36
|
|
|
46
|
-
|
|
47
|
-
logger = _LazyLogger()
|
|
48
|
-
|
|
49
|
-
_UA = "argo-search/2.9 (+batch11; wikimedia_commons)"
|
|
37
|
+
_UA = UA
|
|
50
38
|
_API = "https://commons.wikimedia.org/w/api.php"
|
|
51
39
|
|
|
52
40
|
# Commons 的 extmetadata 是一层「字段 → {value, source, hidden}」的包装,
|
|
@@ -174,63 +162,3 @@ def _build_wikimedia_commons_engine(spec: dict[str, Any]) -> Any:
|
|
|
174
162
|
return finalize_image_fields(results, spec.get("image_license") or "")
|
|
175
163
|
|
|
176
164
|
return _engine
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
def _build_vam_engine(spec: dict[str, Any]) -> Any:
|
|
180
|
-
"""V&A 博物馆馆藏(api.vam.ac.uk/v2/objects/search,免 key,单跳)。
|
|
181
|
-
|
|
182
|
-
装饰艺术/设计垂直,与 met/artic/cleveland 同面。records._images 只给 IIIF
|
|
183
|
-
base 与 !100,100 缩略图,800px 直链按 IIIF 尺寸语法组装:
|
|
184
|
-
`{base}full/!800,800/0/default.jpg`(实测 2026-11-08 200 可取图)。
|
|
185
|
-
落地页用短链 `collections.vam.ac.uk/item/{systemNumber}/`(自带 O 前缀,无 slug 200 直开)。
|
|
186
|
-
上游不逐件给许可字段,不造 image_license;商用判定照 ddgs_images 口径(未判定)。
|
|
187
|
-
"""
|
|
188
|
-
timeout = spec.get("timeout", 15)
|
|
189
|
-
|
|
190
|
-
@safe_search
|
|
191
|
-
def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
|
|
192
|
-
q = query.strip()
|
|
193
|
-
if not q:
|
|
194
|
-
return []
|
|
195
|
-
to = _timeout or timeout
|
|
196
|
-
engine_name = spec.get("_name", "vam")
|
|
197
|
-
headers = {"User-Agent": "argo-search/1.0 (+vam)", "Accept": "application/json"}
|
|
198
|
-
url = (f"https://api.vam.ac.uk/v2/objects/search?q={urllib.parse.quote(q)}"
|
|
199
|
-
f"&images_exist=1&page_size={min(max(int(n), 1), 8)}")
|
|
200
|
-
raw = _http_get_raw(url, headers, to, engine=engine_name)
|
|
201
|
-
if raw is None:
|
|
202
|
-
return []
|
|
203
|
-
try:
|
|
204
|
-
d = json.loads(raw) or {}
|
|
205
|
-
except (json.JSONDecodeError, ValueError):
|
|
206
|
-
return []
|
|
207
|
-
out = []
|
|
208
|
-
for r in d.get("records") or []:
|
|
209
|
-
if not isinstance(r, dict):
|
|
210
|
-
continue
|
|
211
|
-
title = str(r.get("_primaryTitle") or "").strip()
|
|
212
|
-
imgs = r.get("_images") or {}
|
|
213
|
-
base = str(imgs.get("_iiif_image_base_url") or "").strip()
|
|
214
|
-
if not title and not base:
|
|
215
|
-
continue
|
|
216
|
-
row: dict[str, Any] = {}
|
|
217
|
-
if title:
|
|
218
|
-
row["title"] = title[:80]
|
|
219
|
-
maker = r.get("_primaryMaker") or {}
|
|
220
|
-
row["snippet"] = " · ".join(b for b in (
|
|
221
|
-
str(maker.get("name") or "").strip(),
|
|
222
|
-
str(r.get("_primaryDate") or "").strip(),
|
|
223
|
-
str(r.get("objectType") or "").strip()) if b)[:300]
|
|
224
|
-
if base:
|
|
225
|
-
row["image_url"] = base + "full/!800,800/0/default.jpg"
|
|
226
|
-
# systemNumber 自带 O 前缀(如 O417199);再拼一个 O 会变成
|
|
227
|
-
# OO417199(302 跳转),直接用原值才是 200 的规范落地页。
|
|
228
|
-
sn = str(r.get("systemNumber") or "").strip()
|
|
229
|
-
if sn:
|
|
230
|
-
row["url"] = f"https://collections.vam.ac.uk/item/{sn}/"
|
|
231
|
-
row["source"] = engine_name
|
|
232
|
-
out.append(row)
|
|
233
|
-
if len(out) >= max(int(n), 1):
|
|
234
|
-
break
|
|
235
|
-
return out
|
|
236
|
-
return _engine
|
|
@@ -19,6 +19,7 @@ import time
|
|
|
19
19
|
import urllib.request
|
|
20
20
|
from typing import Any
|
|
21
21
|
|
|
22
|
+
from engines_http import UA, UA_EDGAR
|
|
22
23
|
from engines_base import http_open, safe_search
|
|
23
24
|
|
|
24
25
|
|
|
@@ -140,7 +141,7 @@ def _sec_cf_ticker_map(to: float, state_dir: str = "") -> dict[str, str]:
|
|
|
140
141
|
pass
|
|
141
142
|
try:
|
|
142
143
|
req = urllib.request.Request("https://www.sec.gov/files/company_tickers.json",
|
|
143
|
-
headers={"User-Agent":
|
|
144
|
+
headers={"User-Agent": UA_EDGAR,
|
|
144
145
|
"Accept": "application/json"})
|
|
145
146
|
with http_open(req, timeout=max(to, 10), engine="sec_companyfacts") as resp:
|
|
146
147
|
raw = json.loads(resp.read().decode("utf-8", "replace"))
|
|
@@ -186,7 +187,7 @@ def _build_sec_companyfacts_engine(spec: dict[str, Any]) -> Any:
|
|
|
186
187
|
全文回答「哪些文件提到 X」,本引擎回答「这家公司历年财务数字」。
|
|
187
188
|
"""
|
|
188
189
|
timeout = spec.get("timeout", 15)
|
|
189
|
-
ua =
|
|
190
|
+
ua = UA_EDGAR
|
|
190
191
|
|
|
191
192
|
def _ticker_candidates(query: str) -> list[str]:
|
|
192
193
|
q = (query or "").strip()
|
|
@@ -314,7 +315,7 @@ def _build_frankfurter_engine(spec: dict[str, Any]) -> Any:
|
|
|
314
315
|
+ up.urlencode({"base": base, "symbols": ",".join(symbols)}))
|
|
315
316
|
try:
|
|
316
317
|
req = urllib.request.Request(url, headers={
|
|
317
|
-
"User-Agent":
|
|
318
|
+
"User-Agent": UA,
|
|
318
319
|
"Accept": "application/json"})
|
|
319
320
|
with http_open(req, timeout=to, engine=spec.get("_name", "")) as resp:
|
|
320
321
|
data = json.loads(resp.read().decode("utf-8", "replace"))
|
|
@@ -28,9 +28,10 @@ import urllib.request
|
|
|
28
28
|
from datetime import datetime, timedelta, timezone
|
|
29
29
|
from typing import Any
|
|
30
30
|
|
|
31
|
+
from engines_http import UA
|
|
31
32
|
from engines_base import http_open, safe_search
|
|
32
33
|
|
|
33
|
-
_UA =
|
|
34
|
+
_UA = UA
|
|
34
35
|
_CST = timezone(timedelta(hours=8)) # 三个中国市场源都按北京时间取「今天」
|
|
35
36
|
|
|
36
37
|
|