argo-search 1.0.1 → 2.9.7
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/LICENSE +201 -21
- package/README.en.md +822 -0
- package/README.es.md +864 -0
- package/README.ja.md +864 -0
- package/README.ko.md +864 -0
- package/README.md +867 -320
- package/SKILL.md +135 -0
- package/assets/readme/hero.svg +121 -0
- package/assets/readme/made-with-beautify.svg +10 -0
- package/assets/readme/proof-routes.svg +73 -0
- package/assets/readme/settings-keys.png +0 -0
- package/assets/readme/settings-tools.png +0 -0
- package/assets/readme/why-better.svg +104 -0
- package/assets/readme/workflow.svg +83 -0
- package/backends/domain_profiles.json +2308 -96
- package/backends/engine_registry.yaml +3314 -503
- package/backends/query_synonyms_cn.json +35 -0
- package/backends/quota_profiles.json +2409 -161
- package/backends/source_types_cn.json +83 -0
- package/backends/text_lexicon.json +44 -0
- package/bin/argo +703 -0
- package/bin/argo.js +71 -39
- package/config.yaml +4976 -363
- package/cordis.patch.yml +21 -0
- package/data/countries.json +40 -0
- package/data/lang_matrix/lang_capability.json +842 -0
- package/data/lang_matrix/matrix_2026-09-10.json +11921 -0
- package/data/regions_cn.json +1 -0
- package/docs/ADDING_NEW_ENGINE.md +184 -0
- package/docs/ARGO_INTRO.md +124 -0
- package/docs/DATA_SOURCE_GAPS.md +81 -0
- package/docs/DESIGN_LOCAL_DATA_FUSION.md +90 -0
- package/docs/ENGINE_CATALOG.md +564 -0
- package/docs/MCP_SETUP.md +106 -0
- package/docs/PLATFORM_PATHS.md +111 -0
- package/docs/RELEASE_NOTES_v2.8.0.md +71 -0
- package/docs/RELEASE_NOTES_v2.8.2.md +63 -0
- package/docs/RELEASE_NOTES_v2.8.3.md +55 -0
- package/docs/RELEASE_NOTES_v2.8.4.md +79 -0
- package/docs/RELEASE_NOTES_v2.8.5.md +102 -0
- package/docs/RELEASE_NOTES_v2.8.6.md +66 -0
- package/docs/RELEASE_NOTES_v2.8.7.md +65 -0
- package/docs/RELEASE_NOTES_v2.8.8.md +67 -0
- package/docs/RELEASE_NOTES_v2.8.9.md +67 -0
- package/docs/RELEASE_NOTES_v2.9.0.md +64 -0
- package/docs/SEARCH_ARCHIVE.md +115 -0
- package/docs/assets/architecture.svg +104 -0
- package/docs/assets/hero.svg +98 -0
- package/docs/engines/bangumi.md +27 -0
- package/docs/engines/biorxiv.md +27 -0
- package/docs/engines/clawhub.md +27 -0
- package/docs/engines/crt_sh.md +27 -0
- package/docs/engines/datacite.md +27 -0
- package/docs/engines/deps_dev.md +27 -0
- package/docs/engines/douban_movie.md +27 -0
- package/docs/engines/endoflife.md +27 -0
- package/docs/engines/flk_law.md +27 -0
- package/docs/engines/fxtwitter.md +27 -0
- package/docs/engines/google_news.md +27 -0
- package/docs/engines/gov_regulations.md +27 -0
- package/docs/engines/guqian.md +27 -0
- package/docs/engines/hackernews.md +27 -0
- package/docs/engines/iplant.md +27 -0
- package/docs/engines/keenable.md +27 -0
- package/docs/engines/met_museum.md +27 -0
- package/docs/engines/nasa_images.md +27 -0
- package/docs/engines/netease_music.md +27 -0
- package/docs/engines/npm.md +27 -0
- package/docs/engines/nvd.md +27 -0
- package/docs/engines/openreview.md +27 -0
- package/docs/engines/openstd.md +27 -0
- package/docs/engines/parallel_free.md +27 -0
- package/docs/engines/people_daily.md +27 -0
- package/docs/engines/realtime_index.md +27 -0
- package/docs/engines/sec_edgar.md +27 -0
- package/docs/engines/seltz.md +27 -0
- package/docs/engines/skillsmp.md +27 -0
- package/docs/engines/sspai.md +27 -0
- package/docs/engines/std_samr.md +27 -0
- package/docs/engines/train.md +27 -0
- package/docs/engines/un_comtrade.md +27 -0
- package/docs/engines/wikisource.md +27 -0
- package/docs/engines/zdic.md +27 -0
- package/docs/engines/zenodo.md +27 -0
- package/docs/engines/zhihu_hot_app.md +27 -0
- package/docs//344/270/272/344/273/200/344/271/210/351/200/211/346/213/251argo.md +176 -0
- package/engines/README.md +10 -0
- package/engines/_template_cli.yaml +39 -0
- package/engines/_template_http.yaml +37 -0
- package/engines/plugins/_template_plugin.py +50 -0
- package/engines/specs/_cisa_kev.yaml +54 -0
- package/engines/specs/_osv.yaml +63 -0
- package/engines/specs/aljazeera.yaml +43 -0
- package/engines/specs/antara.yaml +43 -0
- package/engines/specs/artic.yaml +20 -0
- package/engines/specs/aviation_weather.yaml +39 -0
- package/engines/specs/bangumi.yaml +21 -0
- package/engines/specs/biorxiv.yaml +24 -0
- package/engines/specs/carbon_intensity.yaml +32 -0
- package/engines/specs/cinii.yaml +44 -0
- package/engines/specs/clawhub.yaml +49 -0
- package/engines/specs/cleveland.yaml +19 -0
- package/engines/specs/cn_ai_news.yaml +43 -0
- package/engines/specs/core.yaml +35 -0
- package/engines/specs/crt_sh.yaml +38 -0
- package/engines/specs/ct24.yaml +43 -0
- package/engines/specs/datacite.yaml +27 -0
- package/engines/specs/datagov_uk.yaml +41 -0
- package/engines/specs/ddgs_images.yaml +45 -0
- package/engines/specs/deepseek_search.yaml +74 -0
- package/engines/specs/deezer.yaml +20 -0
- package/engines/specs/deps_dev.yaml +21 -0
- package/engines/specs/digup.yaml +36 -0
- package/engines/specs/doi.yaml +39 -0
- package/engines/specs/douban_movie.yaml +22 -0
- package/engines/specs/dw_news.yaml +47 -0
- package/engines/specs/egov_law.yaml +21 -0
- package/engines/specs/elpais.yaml +43 -0
- package/engines/specs/endoflife.yaml +21 -0
- package/engines/specs/energy_charts.yaml +21 -0
- package/engines/specs/factcheck_org.yaml +52 -0
- package/engines/specs/faz.yaml +43 -0
- package/engines/specs/federal_register.yaml +57 -0
- package/engines/specs/firecrawl.yaml +53 -0
- package/engines/specs/flk_law.yaml +24 -0
- package/engines/specs/folha.yaml +43 -0
- package/engines/specs/france24.yaml +44 -0
- package/engines/specs/full_fact.yaml +47 -0
- package/engines/specs/fxtwitter.yaml +31 -0
- package/engines/specs/gbfs_nyc.yaml +32 -0
- package/engines/specs/gdacs.yaml +21 -0
- package/engines/specs/gdelt.yaml +64 -0
- package/engines/specs/google_news.yaml +22 -0
- package/engines/specs/gov_regulations.yaml +38 -0
- package/engines/specs/guardian_rss.yaml +59 -0
- package/engines/specs/hurriyet.yaml +43 -0
- package/engines/specs/iplant.yaml +25 -0
- package/engines/specs/jikan.yaml +24 -0
- package/engines/specs/jolpica.yaml +20 -0
- package/engines/specs/k10plus.yaml +20 -0
- package/engines/specs/keenable.yaml +44 -0
- package/engines/specs/lefigaro.yaml +43 -0
- package/engines/specs/listenbrainz.yaml +19 -0
- package/engines/specs/matichon.yaml +43 -0
- package/engines/specs/met_museum.yaml +21 -0
- package/engines/specs/nasa_images.yaml +45 -0
- package/engines/specs/netease_music.yaml +38 -0
- package/engines/specs/nhk.yaml +43 -0
- package/engines/specs/nhtsa_vpic.yaml +20 -0
- package/engines/specs/noaa_swpc.yaml +20 -0
- package/engines/specs/nvd.yaml +38 -0
- package/engines/specs/obis.yaml +20 -0
- package/engines/specs/opencitations.yaml +52 -0
- package/engines/specs/openf1.yaml +21 -0
- package/engines/specs/openfoodfacts.yaml +45 -0
- package/engines/specs/openligadb.yaml +20 -0
- package/engines/specs/openreview.yaml +37 -0
- package/engines/specs/openstd.yaml +21 -0
- package/engines/specs/people_daily.yaml +22 -0
- package/engines/specs/realtime_index.yaml +34 -0
- package/engines/specs/ror.yaml +20 -0
- package/engines/specs/satnogs.yaml +20 -0
- package/engines/specs/sec_edgar.yaml +46 -0
- package/engines/specs/skillsmp.yaml +50 -0
- package/engines/specs/sogou_weixin_browser.yaml +30 -0
- package/engines/specs/soilgrids.yaml +25 -0
- package/engines/specs/sspai.yaml +36 -0
- package/engines/specs/stackexchange.yaml +46 -0
- package/engines/specs/std_samr.yaml +21 -0
- package/engines/specs/tass.yaml +43 -0
- package/engines/specs/tle_mirror.yaml +21 -0
- package/engines/specs/train.yaml +37 -0
- package/engines/specs/tvmaze.yaml +20 -0
- package/engines/specs/twitter_syndication.yaml +31 -0
- package/engines/specs/un_comtrade.yaml +23 -0
- package/engines/specs/unpaywall.yaml +54 -0
- package/engines/specs/vnpress.yaml +43 -0
- package/engines/specs/weather.yaml +32 -0
- package/engines/specs/who_don.yaml +21 -0
- package/engines/specs/who_gho.yaml +20 -0
- package/engines/specs/wikimedia_commons.yaml +34 -0
- package/engines/specs/wikisource.yaml +22 -0
- package/engines/specs/worms.yaml +19 -0
- package/engines/specs/x_trending.yaml +34 -0
- package/engines/specs/yna.yaml +43 -0
- package/engines/specs/ynet.yaml +43 -0
- package/engines/specs/zbmath.yaml +40 -0
- package/engines/specs/zdic.yaml +22 -0
- package/engines/specs/zenodo.yaml +27 -0
- package/engines/specs/zhihu_hot_app.yaml +35 -0
- package/mcp/clients.yaml +74 -0
- package/package.json +51 -12
- package/packages/dsh-plugin/README.md +134 -0
- package/packages/dsh-plugin/cordis.patch.yml +48 -0
- package/packages/dsh-plugin/dsh/client.js +1244 -0
- package/packages/dsh-plugin/dsh/index.js +2290 -0
- package/packages/dsh-plugin/dsh/native-tools.mjs +743 -0
- package/packages/dsh-plugin/package.json +38 -0
- package/packages/dsh-plugin/test/client.test.js +232 -0
- package/packages/dsh-plugin/test/config.test.js +30 -0
- package/packages/dsh-plugin/test/index.test.js +1338 -0
- package/references/query-templates.md +96 -0
- package/references/query-templates.yaml +118 -0
- package/scripts/ab_eval.py +219 -0
- package/scripts/ab_eval_p0p1.py +266 -0
- package/scripts/adaptive.py +271 -70
- package/scripts/answer.py +154 -0
- package/scripts/archive_run.py +591 -0
- package/scripts/argo_engine_registry.py +172 -0
- package/scripts/argo_paths.py +728 -0
- package/scripts/article.py +136 -0
- package/scripts/arxiv_source.py +201 -0
- package/scripts/badcase_ledger.py +252 -0
- package/scripts/batch_probe.py +241 -0
- package/scripts/benchmark.py +19 -0
- package/scripts/bounded_run.py +144 -0
- package/scripts/browser_auth.py +323 -0
- package/scripts/burstiness_detector.py +147 -0
- package/scripts/cache.py +1078 -67
- package/scripts/cache_guard.py +271 -0
- package/scripts/cache_key_vdom.py +56 -0
- package/scripts/cache_similarity.py +170 -0
- package/scripts/caliber_isolation.py +195 -0
- package/scripts/calibrate_lowquality.py +210 -0
- package/scripts/candidate_envelope.py +366 -0
- package/scripts/chrome_cdp.py +871 -0
- package/scripts/circuit_breaker.py +389 -0
- package/scripts/citations.py +334 -0
- package/scripts/cite_cli.py +59 -0
- package/scripts/cjk_tokens.py +95 -0
- package/scripts/clarify.py +47 -24
- package/scripts/cli_io.py +240 -0
- package/scripts/config.py +683 -45
- package/scripts/config_cache.py +402 -0
- package/scripts/conn_pool.py +220 -0
- package/scripts/content_security.py +685 -0
- package/scripts/content_signals.py +730 -0
- package/scripts/crawl.py +74 -35
- package/scripts/daemon.py +866 -0
- package/scripts/digup_bridge.py +214 -0
- package/scripts/engine_admission.py +366 -0
- package/scripts/engine_dispatch.py +1019 -0
- package/scripts/engine_env.py +534 -0
- package/scripts/engine_failure.py +411 -0
- package/scripts/engine_families.py +732 -0
- package/scripts/engine_policy.py +218 -0
- package/scripts/engine_requires.py +190 -0
- package/scripts/engine_status.py +322 -0
- package/scripts/engine_validate.py +638 -0
- package/scripts/engines.py +778 -294
- package/scripts/engines_base.py +1521 -0
- package/scripts/engines_builders.py +298 -0
- package/scripts/engines_builders_batch10.py +159 -0
- package/scripts/engines_builders_batch11.py +174 -0
- package/scripts/engines_builders_batch12.py +103 -0
- package/scripts/engines_builders_batch13.py +340 -0
- package/scripts/engines_builders_batch9.py +1468 -0
- package/scripts/engines_builders_cn.py +2283 -0
- package/scripts/engines_builders_data.py +2923 -0
- package/scripts/engines_builders_data_macro.py +775 -0
- package/scripts/engines_builders_feeds.py +255 -0
- package/scripts/engines_builders_intl.py +1239 -0
- package/scripts/engines_builders_search.py +440 -0
- package/scripts/engines_builders_tech.py +1360 -0
- package/scripts/evidence.py +588 -162
- package/scripts/evidence_loop.py +592 -0
- package/scripts/evidence_tier.py +298 -0
- package/scripts/except_sets.py +25 -0
- package/scripts/extract.py +55 -16
- package/scripts/fact_align.py +207 -0
- package/scripts/fact_crosscheck.py +230 -0
- package/scripts/fetch.py +25 -12
- package/scripts/fetch_browser.py +87 -0
- package/scripts/fetch_jsrun.py +122 -0
- package/scripts/fetch_quality.py +225 -0
- package/scripts/fetch_render_tinyfish.py +117 -0
- package/scripts/fetch_v3.py +1779 -0
- package/scripts/focus_extract.py +350 -0
- package/scripts/fulltext_store.py +169 -0
- package/scripts/fxtwitter_api.py +325 -0
- package/scripts/gen_engine_catalog.py +364 -0
- package/scripts/gen_native_tools.py +91 -0
- package/scripts/gen_routing_snapshot.py +184 -0
- package/scripts/health_check.py +140 -402
- package/scripts/health_probe.py +23 -8
- package/scripts/hot_state.py +134 -0
- package/scripts/http_client.py +1053 -0
- package/scripts/image_ops.py +430 -0
- package/scripts/image_vision/vision_probe +0 -0
- package/scripts/image_vision/vision_probe.swift +126 -0
- package/scripts/install.ps1 +148 -0
- package/scripts/install.sh +206 -0
- package/scripts/job.py +1186 -0
- package/scripts/jump_resolver.py +235 -0
- package/scripts/lang_capability.py +150 -0
- package/scripts/lang_detect.py +289 -0
- package/scripts/lang_matrix_probe.py +329 -0
- package/scripts/lang_pref.py +311 -0
- package/scripts/link_source.py +340 -0
- package/scripts/local_engines.py +321 -0
- package/scripts/local_image.py +970 -0
- package/scripts/local_seek.py +366 -0
- package/scripts/macro_countries.py +82 -0
- package/scripts/matrix_search_eval.py +1105 -0
- package/scripts/mcp_diag.py +8 -3
- package/scripts/mcp_handlers.py +1074 -0
- package/scripts/mcp_handlers_surface.py +157 -0
- package/scripts/mcp_launch.sh +122 -0
- package/scripts/mcp_server.py +118 -417
- package/scripts/mcp_setup.py +407 -0
- package/scripts/mcp_tools.py +330 -0
- package/scripts/mcp_transport.py +191 -0
- package/scripts/min_version_scan.py +335 -0
- package/scripts/net_proxy.py +258 -0
- package/scripts/network_aware.py +152 -0
- package/scripts/paper.py +274 -0
- package/scripts/pdf_extract.py +518 -0
- package/scripts/phrase_filter.py +66 -0
- package/scripts/plan.py +422 -0
- package/scripts/postprocess_signals.py +150 -0
- package/scripts/pre-commit +48 -0
- package/scripts/query_enhance.py +157 -0
- package/scripts/query_operators.py +196 -0
- package/scripts/query_rewriter.py +116 -7
- package/scripts/query_signals.py +300 -0
- package/scripts/query_templates.py +167 -0
- package/scripts/query_understanding.py +411 -0
- package/scripts/query_variants.py +298 -0
- package/scripts/quota.py +488 -76
- package/scripts/rank_signals.py +775 -0
- package/scripts/ranking_eval.py +319 -0
- package/scripts/readability_extract.py +433 -0
- package/scripts/recompute.py +415 -0
- package/scripts/recovery.py +616 -0
- package/scripts/recovery_l0.py +160 -0
- package/scripts/redskill/redskill_engine.py +332 -0
- package/scripts/regression_p0p1.py +318 -0
- package/scripts/replay_eval.py +640 -0
- package/scripts/rerank_tfidf.py +225 -0
- package/scripts/research.py +591 -403
- package/scripts/research_cli.py +361 -0
- package/scripts/research_dossier.py +492 -0
- package/scripts/research_expand.py +146 -0
- package/scripts/research_gates.py +272 -0
- package/scripts/research_report.py +209 -0
- package/scripts/research_strategy.py +37 -0
- package/scripts/research_work_packages.py +195 -0
- package/scripts/result_lang.py +311 -0
- package/scripts/robots_guard.py +259 -0
- package/scripts/route.py +921 -254
- package/scripts/route_bangs.py +40 -0
- package/scripts/route_cache.py +225 -0
- package/scripts/route_combo.py +910 -0
- package/scripts/route_domains.py +328 -0
- package/scripts/route_lang.py +605 -0
- package/scripts/route_log.py +63 -0
- package/scripts/route_policy.py +250 -0
- package/scripts/rrf_classic.py +66 -0
- package/scripts/screenshot.py +73 -0
- package/scripts/search.py +897 -405
- package/scripts/search_attribution.py +88 -0
- package/scripts/search_benchmark.py +407 -0
- package/scripts/search_cli.py +627 -0
- package/scripts/search_entry.py +389 -0
- package/scripts/search_output.py +606 -0
- package/scripts/search_pipeline.py +1077 -0
- package/scripts/search_rank.py +991 -0
- package/scripts/search_types.py +27 -12
- package/scripts/seek_locator.py +68 -0
- package/scripts/semantic_evidence.py +215 -0
- package/scripts/serp_guard.py +228 -0
- package/scripts/serp_kill_log.py +51 -0
- package/scripts/single_flight.py +120 -0
- package/scripts/social_engines/__init__.py +10 -0
- package/scripts/social_engines/bilibili_engine.py +131 -0
- package/scripts/social_engines/hackernews_engine.py +113 -0
- package/scripts/social_engines/reddit_engine.py +172 -0
- package/scripts/social_engines/twitter_engine.py +397 -0
- package/scripts/social_engines/v2ex_engine.py +101 -0
- package/scripts/social_engines/weibo_engine.py +128 -0
- package/scripts/social_engines/xiaohongshu_engine.py +137 -0
- package/scripts/social_engines/zhihu_engine.py +139 -0
- package/scripts/social_research.py +201 -0
- package/scripts/sogou_weixin_browser.py +318 -0
- package/scripts/source_ledger.py +249 -0
- package/scripts/stage_timing.py +58 -0
- package/scripts/stats_cli.py +95 -0
- package/scripts/straggler_policy.py +60 -0
- package/scripts/stylometry_detector.py +231 -0
- package/scripts/sync_backends.py +353 -0
- package/scripts/sync_installs.py +29 -0
- package/scripts/template_cli.py +127 -0
- package/scripts/text_lexicon.py +72 -0
- package/scripts/tfidf_router.py +109 -37
- package/scripts/time_utils.py +233 -0
- package/scripts/topic_research_profiles.py +643 -0
- package/scripts/train.py +737 -0
- package/scripts/tweet.py +596 -0
- package/scripts/url_canon.py +217 -0
- package/scripts/url_optimize.py +56 -0
- package/scripts/url_safety.py +236 -0
- package/scripts/usage_log.py +116 -0
- package/scripts/usage_log_clean.py +113 -0
- package/scripts/v2ex_nodes.py +311 -0
- package/scripts/variant_recall.py +188 -0
- package/scripts/watch.py +205 -0
- package/scripts/wechat_article.py +258 -0
- package/scripts/wide_research.py +402 -0
- package/scripts/wx.py +349 -0
- package/scripts/x_article_fetch.py +141 -0
- package/scripts/x_search.py +234 -0
- package/scripts/x_trending.py +189 -0
- package/scripts/yaml_load.py +67 -0
- package/sub-skills/ego-search/SKILL.md +253 -0
- package/sub-skills/ego-search/references/browser-runtime.md +43 -0
- package/sub-skills/ego-search/references/install.md +67 -0
- package/sub-skills/ego-search/references/original-ego-upgrade.md +51 -0
- package/sub-skills/ego-search/scripts/ego_search.py +800 -0
- package/sub-skills/ego-search/scripts/merge.py +226 -0
- package/sub-skills/ego-search/scripts/quality.py +64 -0
- package/sub-skills/ego-search/scripts/runtime.py +172 -0
- package/sub-skills/ego-search/scripts/safety.py +109 -0
- package/sub-skills/ego-search/scripts/serp_spec.py +109 -0
- package/sub-skills/ego-search/scripts/webbridge_adapter.py +374 -0
- package/sub-skills/ego-search/tests/test_query_normalize.py +68 -0
- package/sub-skills/js-run/SKILL.md +67 -0
- package/sub-skills/js-run/scripts/jsrun.py +112 -0
- package/sub-skills/js-run/scripts/shim.js +188 -0
- package/sub-skills/js-run/tests/fixtures/challenge_like.js +27 -0
- package/sub-skills/js-run/tests/test_jsrun.py +165 -0
- package/sub-skills/local-search/SKILL.md +50 -53
- package/sub-skills/local-search/bm25.py +162 -0
- package/sub-skills/local-search/config.yaml +152 -55
- package/sub-skills/local-search/engine_registry.py +91 -26
- package/sub-skills/local-search/{health_check.py → local_health_check.py} +140 -10
- package/sub-skills/local-search/local_search_adapter.py +13 -2
- package/sub-skills/local-search/parse_maps.yaml +40 -42
- package/sub-skills/local-search/search_v3.py +1182 -65
- package/sub-skills/local-search/smart_router.py +47 -7
- package/sub-skills/local-seek/SKILL.md +110 -0
- package/sub-skills/local-seek/config/domains.yaml +20 -0
- package/sub-skills/local-seek/references/auto-behaviors.md +24 -0
- package/sub-skills/local-seek/references/fd-mdfind-recipes.md +62 -0
- package/sub-skills/local-seek/references/git-integration.md +54 -0
- package/sub-skills/local-seek/references/remote-handoff.md +46 -0
- package/sub-skills/local-seek/references/rg-recipes.md +96 -0
- package/sub-skills/local-seek/references/strategies.md +52 -0
- package/sub-skills/local-seek/references/structural-search.md +59 -0
- package/sub-skills/local-seek/scripts/eval_rank.py +216 -0
- package/sub-skills/local-seek/scripts/eval_seek.py +224 -0
- package/sub-skills/local-seek/scripts/seek.py +1465 -0
- package/sub-skills/local-seek/scripts/seek_frecency.py +126 -0
- package/sub-skills/local-seek/scripts/seek_fts.py +430 -0
- package/sub-skills/local-seek/scripts/seek_rank.py +193 -0
- package/sub-skills/local-seek/tests/test_content_rank.py +222 -0
- package/sub-skills/local-seek/tests/test_determinism_20261006.py +145 -0
- package/sub-skills/local-seek/tests/test_noise_tier.py +101 -0
- package/sub-skills/local-seek/tests/test_pcre2_probe.py +136 -0
- package/sub-skills/local-seek/tests/test_rank_pinyin.py +77 -0
- package/sub-skills/local-seek/tests/test_regression_20261003.py +169 -0
- package/sub-skills/local-seek/tests/test_regression_20261006.py +146 -0
- package/sub-skills/local-seek/tests/test_seek_degradation.py +111 -0
- package/sub-skills/local-seek/tests/test_seek_fts.py +313 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""小红书搜索引擎
|
|
3
|
+
|
|
4
|
+
使用 xhs-cli (xiaohongshu-cli) 工具。
|
|
5
|
+
需要先通过 `xhs login` 登录获取 cookies。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
import subprocess
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# 内部子进程超时(秒)。此前硬编码 15s,比调度层的单引擎墙钟预算(10s)还长,
|
|
14
|
+
# 属「内层白跑」:外层 subprocess 会在预算处 kill,但内层已消耗的时间追不回。
|
|
15
|
+
# 收到 8s —— 与 execution.default_timeout 一致,且短于预算,
|
|
16
|
+
# 使内层能在被 kill 前主动超时返回(走 except 分支),行为更干净。
|
|
17
|
+
# 可用 ARGO_XHS_TIMEOUT 覆盖,便于慢网调试。
|
|
18
|
+
_DEFAULT_TIMEOUT = 8
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _subprocess_timeout() -> int:
|
|
22
|
+
try:
|
|
23
|
+
v = int(os.environ.get("ARGO_XHS_TIMEOUT", "").strip())
|
|
24
|
+
return v if v > 0 else _DEFAULT_TIMEOUT
|
|
25
|
+
except (TypeError, ValueError):
|
|
26
|
+
return _DEFAULT_TIMEOUT
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def search(query: str, n: int = 5) -> list[dict]:
|
|
30
|
+
"""主搜索入口"""
|
|
31
|
+
try:
|
|
32
|
+
result = subprocess.run(
|
|
33
|
+
["xhs", "search", query],
|
|
34
|
+
capture_output=True, text=True, timeout=_subprocess_timeout(),
|
|
35
|
+
encoding="utf-8", errors="replace", # Windows GBK locale 下 UTF-8 输出会解码崩
|
|
36
|
+
)
|
|
37
|
+
if result.returncode == 0 and result.stdout.strip():
|
|
38
|
+
return _parse_xhs_output(result.stdout, n)
|
|
39
|
+
except (FileNotFoundError, subprocess.TimeoutExpired) as e:
|
|
40
|
+
# CLI 未安装/超时不是「平台 0 结果」:带 error 浮上来,与社交引擎
|
|
41
|
+
# 统一范式一致(zhihu_engine 范式,mcp_handlers 的 err=None 设计
|
|
42
|
+
# 依赖引擎抛异常或返 error 占位)。
|
|
43
|
+
return [{"error": f"xhs CLI {type(e).__name__}", "source": "xiaohongshu"}]
|
|
44
|
+
return []
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _parse_xhs_output(raw: str, n: int) -> list[dict]:
|
|
48
|
+
"""解析 xhs-cli 输出"""
|
|
49
|
+
results = []
|
|
50
|
+
try:
|
|
51
|
+
data = json.loads(raw)
|
|
52
|
+
items = data.get("items", data.get("data", []))
|
|
53
|
+
if isinstance(items, dict):
|
|
54
|
+
items = items.get("items", [])
|
|
55
|
+
for item in items[:n]:
|
|
56
|
+
if not isinstance(item, dict):
|
|
57
|
+
continue
|
|
58
|
+
note_card = item.get("note_card", item)
|
|
59
|
+
title = note_card.get("display_title", note_card.get("title", ""))
|
|
60
|
+
desc = note_card.get("desc", "")
|
|
61
|
+
interact = note_card.get("interact_info", {})
|
|
62
|
+
|
|
63
|
+
# URL 可核验性(关键):
|
|
64
|
+
# 小红书强制 xsec_token —— 裸 note_id 拼出的 /explore/<id> 会被
|
|
65
|
+
# 302 拦截,无法打开(实测确认)。因此**优先使用上游返回的原始
|
|
66
|
+
# URL/带 token 的链接**,只有在拿不到时才回退到裸 ID 拼接,
|
|
67
|
+
# 并显式标注 url_verifiable=False,让调用方知道这条链接不可复核
|
|
68
|
+
# (与 V2EX 引擎同一契约:宁可不给链接,也不给打不开的链接)。
|
|
69
|
+
raw_url = (item.get("url") or item.get("note_url")
|
|
70
|
+
or note_card.get("url") or "")
|
|
71
|
+
xsec = (item.get("xsec_token") or note_card.get("xsec_token") or "")
|
|
72
|
+
note_id = item.get("id") or note_card.get("note_id") or ""
|
|
73
|
+
if raw_url:
|
|
74
|
+
url = raw_url
|
|
75
|
+
verifiable = True
|
|
76
|
+
elif note_id and xsec:
|
|
77
|
+
url = (f"https://www.xiaohongshu.com/explore/{note_id}"
|
|
78
|
+
f"?xsec_token={xsec}")
|
|
79
|
+
verifiable = True
|
|
80
|
+
elif note_id:
|
|
81
|
+
url = f"https://www.xiaohongshu.com/explore/{note_id}"
|
|
82
|
+
verifiable = False # 裸 ID 必被 302 拦截
|
|
83
|
+
else:
|
|
84
|
+
continue # 无 ID 无 URL:不可核验,不产出
|
|
85
|
+
|
|
86
|
+
results.append({
|
|
87
|
+
"title": title[:100] + ("..." if len(title) > 100 else ""),
|
|
88
|
+
"url": url,
|
|
89
|
+
"snippet": (desc or title)[:300],
|
|
90
|
+
"source": "xiaohongshu",
|
|
91
|
+
"score": max(1.0 - len(results) * 0.1, 0.1),
|
|
92
|
+
"social_meta": {
|
|
93
|
+
"platform": "xiaohongshu",
|
|
94
|
+
"content_type": "note",
|
|
95
|
+
"author": note_card.get("user", {}).get("nickname", ""),
|
|
96
|
+
"likes": interact.get("liked_count", 0),
|
|
97
|
+
"comments": interact.get("comment_count", 0),
|
|
98
|
+
"collects": interact.get("collected_count", 0),
|
|
99
|
+
"type": note_card.get("type", "normal"), # normal / video
|
|
100
|
+
"note_id": note_id,
|
|
101
|
+
"has_xsec_token": bool(xsec),
|
|
102
|
+
# False = 该链接为裸 ID 拼接,打开会被平台拦截(不可复核)
|
|
103
|
+
"url_verifiable": verifiable,
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
except (json.JSONDecodeError, ValueError):
|
|
107
|
+
# 尝试文本解析
|
|
108
|
+
pass
|
|
109
|
+
return results
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def main():
|
|
113
|
+
import argparse
|
|
114
|
+
parser = argparse.ArgumentParser(description="Xiaohongshu search engine")
|
|
115
|
+
parser.add_argument("action", nargs="?", default="search")
|
|
116
|
+
parser.add_argument("query", nargs="?")
|
|
117
|
+
parser.add_argument("-n", type=int, default=5)
|
|
118
|
+
parser.add_argument("--json", action="store_true")
|
|
119
|
+
args = parser.parse_args()
|
|
120
|
+
|
|
121
|
+
if not args.query:
|
|
122
|
+
print("[]")
|
|
123
|
+
return
|
|
124
|
+
|
|
125
|
+
results = search(args.query, args.n)
|
|
126
|
+
if args.json:
|
|
127
|
+
print(json.dumps(results, ensure_ascii=False))
|
|
128
|
+
else:
|
|
129
|
+
for i, r in enumerate(results, 1):
|
|
130
|
+
print(f"### {i}. {r['title']}")
|
|
131
|
+
print(f"- **URL**: {r['url']}")
|
|
132
|
+
print(f"- {r['snippet'][:200]}")
|
|
133
|
+
print()
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
if __name__ == "__main__":
|
|
137
|
+
main()
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""知乎搜索引擎(知乎开放平台 zhihu_search API)
|
|
3
|
+
|
|
4
|
+
密钥:环境变量 ZHIHU_ACCESS_SECRET(或 ARGO_ZHIHU_ACCESS_SECRET),
|
|
5
|
+
未配置时返回空列表(不抛错、不静默假成功——error 由调用侧显示)。
|
|
6
|
+
保持一致 social_engines 统一 schema,sentiment 聚合按 social_meta 直接可用。
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import os
|
|
13
|
+
import time
|
|
14
|
+
import urllib.parse
|
|
15
|
+
import urllib.request
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
# 出口调度唯一入口(issue #13 同类修复):urlopen 不认 config.yaml 的
|
|
19
|
+
# network.proxy,裸用会在「必须经代理才能出网」的环境里整源连不上。
|
|
20
|
+
import sys as _sys
|
|
21
|
+
_sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
22
|
+
from net_proxy import open_url # noqa: E402
|
|
23
|
+
|
|
24
|
+
ZHIHU_API = "https://developer.zhihu.com/api/v1/content/zhihu_search"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _secret() -> str:
|
|
28
|
+
# 走 engine_env 规范访问器:os.environ 优先,~/.config/argo/env 热读保底
|
|
29
|
+
# (密钥轮换改文件即生效,无需重启)
|
|
30
|
+
try:
|
|
31
|
+
from engine_env import get_env
|
|
32
|
+
return get_env(["ARGO_ZHIHU_ACCESS_SECRET", "ZHIHU_ACCESS_SECRET"])
|
|
33
|
+
except ImportError:
|
|
34
|
+
return os.environ.get("ZHIHU_ACCESS_SECRET") or os.environ.get("ARGO_ZHIHU_ACCESS_SECRET", "")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def search(query: str, n: int = 5) -> list[dict[str, Any]]:
|
|
38
|
+
"""通过知乎开放平台 zhihu_search 搜索站内内容。"""
|
|
39
|
+
if not query or not query.strip():
|
|
40
|
+
return []
|
|
41
|
+
secret = _secret()
|
|
42
|
+
if not secret:
|
|
43
|
+
return []
|
|
44
|
+
|
|
45
|
+
params = urllib.parse.urlencode({
|
|
46
|
+
"Query": query.strip(),
|
|
47
|
+
"Count": str(max(1, min(int(n), 20))),
|
|
48
|
+
"SearchDB": "zhihu",
|
|
49
|
+
})
|
|
50
|
+
url = f"{ZHIHU_API}?{params}"
|
|
51
|
+
headers = {
|
|
52
|
+
"Authorization": f"Bearer {secret}",
|
|
53
|
+
"Content-Type": "application/json",
|
|
54
|
+
"X-Request-Timestamp": str(int(time.time())),
|
|
55
|
+
"User-Agent": "argo-search/2.6 (unified-search@local)",
|
|
56
|
+
}
|
|
57
|
+
try:
|
|
58
|
+
req = urllib.request.Request(url, headers=headers)
|
|
59
|
+
with open_url(req, timeout=10) as resp:
|
|
60
|
+
data = json.loads(resp.read().decode("utf-8", "replace"))
|
|
61
|
+
except urllib.error.HTTPError as e:
|
|
62
|
+
# 密钥无效/过期(401/403)等必须暴露为 auth-failed,而不是静默
|
|
63
|
+
# no-results——调用侧把「没配置」「没结果」区分开才可行动
|
|
64
|
+
return [{"error": f"zhihu API HTTP {e.code}", "source": "zhihu"}]
|
|
65
|
+
except Exception as e:
|
|
66
|
+
return [{"error": f"zhihu API {type(e).__name__}: {e}", "source": "zhihu"}]
|
|
67
|
+
|
|
68
|
+
if data.get("Code") not in (0, None):
|
|
69
|
+
return [{"error": f"zhihu API Code={data.get('Code')} "
|
|
70
|
+
f"{str(data.get('Message') or '')[:100]}",
|
|
71
|
+
"source": "zhihu"}]
|
|
72
|
+
|
|
73
|
+
results: list[dict[str, Any]] = []
|
|
74
|
+
items = (data.get("Data") or {}).get("Items") or []
|
|
75
|
+
for item in items[:n]:
|
|
76
|
+
if not isinstance(item, dict):
|
|
77
|
+
continue
|
|
78
|
+
title = (item.get("Title") or "").strip()
|
|
79
|
+
# API 标题统一带「 - 知乎」尾巴:截断前剥掉(先剥再切,尾巴不占正文)
|
|
80
|
+
if title.endswith(" - 知乎"):
|
|
81
|
+
title = title[: -len(" - 知乎")].rstrip()
|
|
82
|
+
url_ = item.get("Url") or ""
|
|
83
|
+
snippet = (item.get("ContentText") or title or "")[:300]
|
|
84
|
+
if not title and not url_:
|
|
85
|
+
continue
|
|
86
|
+
content_id = str(item.get("ContentID") or "")
|
|
87
|
+
author = item.get("AuthorName") or ""
|
|
88
|
+
likes = item.get("VoteUpCount") or 0
|
|
89
|
+
comments = item.get("CommentCount") or 0
|
|
90
|
+
edit_ts = item.get("EditTime")
|
|
91
|
+
published = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(edit_ts)) if edit_ts else None
|
|
92
|
+
|
|
93
|
+
results.append({
|
|
94
|
+
"title": title[:100] + ("..." if len(title) > 100 else ""),
|
|
95
|
+
"url": url_,
|
|
96
|
+
"snippet": snippet,
|
|
97
|
+
"source": "zhihu",
|
|
98
|
+
"score": max(1.0 - len(results) * 0.1, 0.1),
|
|
99
|
+
"published_at": published,
|
|
100
|
+
"social_meta": {
|
|
101
|
+
"platform": "zhihu",
|
|
102
|
+
"content_type": (item.get("ContentType") or "answer").lower(),
|
|
103
|
+
"id": content_id,
|
|
104
|
+
"author": author,
|
|
105
|
+
"likes": likes,
|
|
106
|
+
"comments": comments,
|
|
107
|
+
"provider": "zhihu_openapi",
|
|
108
|
+
},
|
|
109
|
+
})
|
|
110
|
+
return results
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def main():
|
|
114
|
+
import argparse
|
|
115
|
+
parser = argparse.ArgumentParser(description="Zhihu search engine (zhihu_openapi)")
|
|
116
|
+
parser.add_argument("action", nargs="?", default="search")
|
|
117
|
+
parser.add_argument("query", nargs="?")
|
|
118
|
+
parser.add_argument("-n", type=int, default=5)
|
|
119
|
+
parser.add_argument("--json", action="store_true")
|
|
120
|
+
args = parser.parse_args()
|
|
121
|
+
|
|
122
|
+
if not args.query:
|
|
123
|
+
print("[]")
|
|
124
|
+
return
|
|
125
|
+
results = search(args.query, args.n)
|
|
126
|
+
if args.json:
|
|
127
|
+
print(json.dumps(results, ensure_ascii=False))
|
|
128
|
+
else:
|
|
129
|
+
for i, r in enumerate(results, 1):
|
|
130
|
+
meta = r.get("social_meta") or {}
|
|
131
|
+
print(f"### {i}. {r['title']}")
|
|
132
|
+
print(f"- **URL**: {r['url']}")
|
|
133
|
+
print(f"- {r['snippet'][:200]}")
|
|
134
|
+
print(f"- likes={meta.get('likes')} comments={meta.get('comments')} @{meta.get('author', '')}")
|
|
135
|
+
print()
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
if __name__ == "__main__":
|
|
139
|
+
main()
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
social_research.py — 社交舆情研究模块(从 research.py 拆分)
|
|
4
|
+
|
|
5
|
+
承载跨平台 UGC 情绪与讨论分析:
|
|
6
|
+
- social_sentiment_research:并行抓取多平台 → 互动聚合 → 话题提取
|
|
7
|
+
- aggregate_social_sentiment:MCP argo_social_search mode=sentiment 用
|
|
8
|
+
- _extract_topics:中英文兼容话题提取
|
|
9
|
+
- _print_social_report:终端报告输出
|
|
10
|
+
|
|
11
|
+
从 research.py 拆分以控制文件规模(code-review:单文件 <1k 行)。
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import time
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
from bounded_run import run_bounded, TaskError
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def social_sentiment_research(query: str, platforms: list[str] | None = None,
|
|
23
|
+
max_results: int = 5) -> dict[str, Any]:
|
|
24
|
+
"""社交舆情研究:跨平台 UGC 情绪与讨论分析"""
|
|
25
|
+
if platforms is None:
|
|
26
|
+
platforms = ["twitter", "reddit", "xiaohongshu"]
|
|
27
|
+
|
|
28
|
+
from search import super_search
|
|
29
|
+
|
|
30
|
+
platform_results: dict[str, list] = {}
|
|
31
|
+
all_results: list[dict] = []
|
|
32
|
+
engines_used: set[str] = set()
|
|
33
|
+
t0 = time.time()
|
|
34
|
+
|
|
35
|
+
def _one(platform: str) -> tuple[str, list[dict], set[str]]:
|
|
36
|
+
try:
|
|
37
|
+
result = super_search(query, engine=platform, n=max_results, mode="fast")
|
|
38
|
+
return platform, result.get("results", []), set(result.get("engines_used", []))
|
|
39
|
+
except Exception:
|
|
40
|
+
return platform, [], set()
|
|
41
|
+
|
|
42
|
+
# 并行抓取各平台(串行时 3 平台 × 秒级延迟累积;并行取最慢平台耗时)。
|
|
43
|
+
# 总时限 90s:到点就拿已完成部分返回,没完成的平台记空结果,不再被卡住的
|
|
44
|
+
# 平台拖住、也不会因超时异常中断整次调用。
|
|
45
|
+
social_errors: list[str] = []
|
|
46
|
+
finished, unfinished = run_bounded(
|
|
47
|
+
platforms, _one, 90.0, max_workers=min(max(len(platforms), 1), 4))
|
|
48
|
+
for platform, value in finished:
|
|
49
|
+
if isinstance(value, TaskError):
|
|
50
|
+
platform_results[platform] = []
|
|
51
|
+
social_errors.append(f"{platform}: {type(value.exc).__name__}")
|
|
52
|
+
continue
|
|
53
|
+
_platform, results, used = value
|
|
54
|
+
platform_results[_platform] = results
|
|
55
|
+
all_results.extend(results)
|
|
56
|
+
engines_used.update(used)
|
|
57
|
+
for platform in unfinished:
|
|
58
|
+
platform_results[platform] = []
|
|
59
|
+
social_errors.append(f"{platform}: timeout (>90s)")
|
|
60
|
+
|
|
61
|
+
# 互动数据聚合
|
|
62
|
+
engagement_totals = {"likes": 0, "comments": 0, "shares": 0, "views": 0}
|
|
63
|
+
titles: list[str] = []
|
|
64
|
+
|
|
65
|
+
for r in all_results:
|
|
66
|
+
meta = r.get("social_meta", {})
|
|
67
|
+
if isinstance(meta, dict):
|
|
68
|
+
engagement_totals["likes"] += meta.get("likes", meta.get("upvotes", meta.get("attitudes_count", 0)))
|
|
69
|
+
engagement_totals["comments"] += meta.get("comments", meta.get("num_comments", 0))
|
|
70
|
+
engagement_totals["shares"] += meta.get("shares", meta.get("retweets", meta.get("reposts_count", 0)))
|
|
71
|
+
engagement_totals["views"] += meta.get("views", meta.get("play_count", 0))
|
|
72
|
+
# 收集标题用于话题提取
|
|
73
|
+
title = r.get("title", "")
|
|
74
|
+
if title:
|
|
75
|
+
titles.append(title)
|
|
76
|
+
|
|
77
|
+
# 中英文兼容的话题提取
|
|
78
|
+
top_topics_list = _extract_topics(titles, top_k=10)
|
|
79
|
+
elapsed = int((time.time() - t0) * 1000)
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
"query": query,
|
|
83
|
+
"mode": "social-sentiment",
|
|
84
|
+
"platforms": platforms,
|
|
85
|
+
"total_posts": len(all_results),
|
|
86
|
+
"platform_breakdown": {p: len(r) for p, r in platform_results.items()},
|
|
87
|
+
"engagement_totals": engagement_totals,
|
|
88
|
+
"top_topics": top_topics_list,
|
|
89
|
+
"cross_platform_posts": [
|
|
90
|
+
{
|
|
91
|
+
"platform": r.get("source", ""),
|
|
92
|
+
"title": r.get("title", "")[:100],
|
|
93
|
+
"url": r.get("url", ""),
|
|
94
|
+
"snippet": r.get("snippet", "")[:200],
|
|
95
|
+
"social_meta": r.get("social_meta", {}),
|
|
96
|
+
}
|
|
97
|
+
for r in all_results[:15]
|
|
98
|
+
],
|
|
99
|
+
"engines_used": sorted(engines_used),
|
|
100
|
+
"errors": social_errors,
|
|
101
|
+
"elapsed_ms": elapsed,
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def aggregate_social_sentiment(query: str, platforms: list[str],
|
|
106
|
+
platform_results: dict[str, list]) -> dict[str, Any]:
|
|
107
|
+
"""社交舆情聚合(MCP argo_social_search mode=sentiment 用)。
|
|
108
|
+
|
|
109
|
+
输入为按平台分组的已抓取帖子(social_engines 输出,含 social_meta),
|
|
110
|
+
聚合互动数据汇总与平台分布,限流返回代表性帖子。原为 MCP 分发层的
|
|
111
|
+
内联逻辑,下沉到本模块避免逻辑放错层。
|
|
112
|
+
"""
|
|
113
|
+
all_posts: list = []
|
|
114
|
+
for p in platforms:
|
|
115
|
+
all_posts.extend(platform_results.get(p) or [])
|
|
116
|
+
|
|
117
|
+
engagement_totals = {"likes": 0, "comments": 0, "reposts": 0, "shares": 0}
|
|
118
|
+
for post in all_posts:
|
|
119
|
+
meta = post.get("social_meta", {}) if isinstance(post, dict) else {}
|
|
120
|
+
engagement_totals["likes"] += meta.get("likes", 0) or meta.get("like_count", 0) or 0
|
|
121
|
+
engagement_totals["comments"] += meta.get("comments", 0) or 0
|
|
122
|
+
engagement_totals["reposts"] += meta.get("reposts", 0) or 0
|
|
123
|
+
engagement_totals["shares"] += meta.get("shares", 0) or 0
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
"query": query,
|
|
127
|
+
"platforms": platforms,
|
|
128
|
+
"platform_breakdown": {p: len(platform_results.get(p) or []) for p in platforms},
|
|
129
|
+
"total_posts": len(all_posts),
|
|
130
|
+
"engagement_totals": engagement_totals,
|
|
131
|
+
"posts": all_posts[:30], # 限流
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _extract_topics(titles: list[str], top_k: int = 10) -> list[dict]:
|
|
136
|
+
"""从标题列表提取话题(中英文兼容)。
|
|
137
|
+
|
|
138
|
+
英文用 split() 分词,中文用字符级 bigram。
|
|
139
|
+
过滤单字停用词,返回 top_k 个话题。
|
|
140
|
+
"""
|
|
141
|
+
import re
|
|
142
|
+
from collections import Counter
|
|
143
|
+
|
|
144
|
+
chinese_stopwords = set(
|
|
145
|
+
'的了是在和我你她他它这就也不很但而或如果因为所以而且或者虽然但是可以应该需要已经正在'
|
|
146
|
+
'之前之后时候地方问题工作生活东西事情时间今天昨天明天今年去年明年个些吗呢啊吧哦嗯哈'
|
|
147
|
+
'呀嘛哪谁什么怎么多少几样种类下上里中后前时来回过开给让把被对从向比跟和与及当比'
|
|
148
|
+
'如例包括相关关于根据通过进行使用作为成为具有属于位于来自获得达到实现完成产生形成'
|
|
149
|
+
'存在发生发展提供包含涉及适用于'
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
topic_counter = Counter()
|
|
153
|
+
|
|
154
|
+
for title in titles:
|
|
155
|
+
# 英文分词(仅保留长度 >= 3 的词)
|
|
156
|
+
en_words = re.findall(r'[a-zA-Z]{2,}', title.lower())
|
|
157
|
+
for w in en_words:
|
|
158
|
+
if len(w) >= 3:
|
|
159
|
+
topic_counter[w] += 1
|
|
160
|
+
|
|
161
|
+
# 中文 bigram(连续 2 个中文字符)
|
|
162
|
+
chinese_chars = re.findall(r'[一-鿿]', title)
|
|
163
|
+
for i in range(len(chinese_chars) - 1):
|
|
164
|
+
bigram = chinese_chars[i] + chinese_chars[i + 1]
|
|
165
|
+
if bigram[0] not in chinese_stopwords and bigram[1] not in chinese_stopwords:
|
|
166
|
+
topic_counter[bigram] += 1
|
|
167
|
+
|
|
168
|
+
return [{"topic": t, "mentions": c} for t, c in topic_counter.most_common(top_k)]
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _print_social_report(report: dict):
|
|
172
|
+
"""打印社交舆情报告"""
|
|
173
|
+
print(f"\n{'='*60}")
|
|
174
|
+
print(f"社交舆情分析:{report['query']}")
|
|
175
|
+
print(f"{'='*60}")
|
|
176
|
+
print(f"平台:{', '.join(report['platforms'])} | 引擎:{', '.join(report['engines_used'])}")
|
|
177
|
+
print(f"抓取帖子:{report['total_posts']} | 耗时:{report['elapsed_ms']}ms")
|
|
178
|
+
print()
|
|
179
|
+
print("── 平台分布 ──")
|
|
180
|
+
for platform, count in report["platform_breakdown"].items():
|
|
181
|
+
print(f" {platform}: {count} 条")
|
|
182
|
+
print()
|
|
183
|
+
print("── 互动数据汇总 ──")
|
|
184
|
+
eng = report["engagement_totals"]
|
|
185
|
+
print(f" 点赞/投票:{eng['likes']:,} | 评论:{eng['comments']:,} | 转发:{eng['shares']:,} | 观看:{eng['views']:,}")
|
|
186
|
+
print()
|
|
187
|
+
print("── 高频讨论话题 ──")
|
|
188
|
+
for topic in report["top_topics"]:
|
|
189
|
+
print(f" 「{topic['topic']}」 ({topic['mentions']} 次)")
|
|
190
|
+
print()
|
|
191
|
+
print("── 代表性内容 ──")
|
|
192
|
+
for post in report["cross_platform_posts"][:5]:
|
|
193
|
+
meta = post.get("social_meta", {})
|
|
194
|
+
engagement = ""
|
|
195
|
+
if isinstance(meta, dict):
|
|
196
|
+
likes = meta.get("likes", meta.get("upvotes", meta.get("attitudes_count", 0)))
|
|
197
|
+
comments = meta.get("comments", meta.get("num_comments", 0))
|
|
198
|
+
engagement = f" | 👍{likes} 💬{comments}"
|
|
199
|
+
print(f" [{post['platform']}] {post['title'][:60]}{engagement}")
|
|
200
|
+
print(f" {post['url']}")
|
|
201
|
+
print()
|