mcpField
H
hn-search

hn-search

github.com/dylanfeltus生产力18085 次安装6 周前更新
代码仓库

关于 hn-search

hn-search 是通过 Algolia HN Search API 搜索和监控 Hacker News 故事、评论及用户帖子的技能。它支持按相关性或日期搜索,并可按内容类型、活跃度和时间筛选。

主要功能

  1. 01搜索故事、评论和用户帖子
  2. 02按相关性或日期排序搜索
  3. 03按内容类型和活跃度筛选
  4. 04查找主题的近期提及
  5. 05获取特定故事的评论

适用场景

  1. 01了解 Hacker News 对某主题的讨论
  2. 02追踪产品或公司的近期提及
  3. 03查找 Show HN 或 Ask HN 帖子
  4. 04查看特定故事下的评论

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/dylanfeltus/skills --skill hn-search

安装后在 Claude Code 中输入/hn-search确认已加载。

附带文件README.md

详细介绍

Hacker News 搜索

通过 Algolia HN Search API 搜索并监控 Hacker News 上的帖子、评论和用户。无需 API 密钥。

适用场景

  • 用户询问某个主题在 Hacker News 上的讨论
  • 用户想查找有关某家公司、产品或技术的 HN 帖子
  • 用户想监控 HN 上对某事物的提及
  • 用户询问“HN 上有什么热门内容”或“HN 对 X 有什么看法”
  • 用户想查找 Show HN / Ask HN / Launch HN 帖子

API 概览

基础 URL: https://hn.algolia.com/api/v1

两个搜索端点:

  • /search — 按相关性排序(最适合查找特定主题)
  • /search_by_date — 按日期排序(最适合监控 / 查看近期动态)

速率限制: 每小时 10,000 次请求(额度宽裕,无需身份验证)

如何搜索

步骤 1:构建 URL
https://hn.algolia.com/api/v1/search?query=QUERY&tags=TAG&hitsPerPage=N&numericFilters=FILTERS
步骤 2:使用 web_fetch 获取数据

使用 web_fetch 调用 API。响应为 JSON。

参数
参数描述示例
query搜索词(URL 编码)query=openai+gpt
tags按类型筛选(见下文)tags=story
hitsPerPage每页结果数(最多 1000)hitsPerPage=20
page页码(从 0 开始)page=0
numericFilters数值筛选条件(见下文)numericFilters=points>100
标签筛选

使用 tags 按内容类型筛选:

标签描述
story仅帖子
comment仅评论
show_hnShow HN 帖子
ask_hnAsk HN 帖子
front_page当前位于首页
author_USERNAME特定用户发布的帖子
story_ID特定帖子的评论

组合标签时,使用逗号表示 AND,或使用带逗号的圆括号表示 OR:

  • tags=story,show_hn → Show HN 帖子(AND)
  • tags=(story,comment) → 帖子或评论
数值筛选
筛选条件描述
points>N最低 points/赞数
num_comments>N最少评论数
created_at_i>TIMESTAMP晚于 Unix 时间戳
created_at_i<TIMESTAMP早于 Unix 时间戳

使用逗号组合:numericFilters=points>100,num_comments>50

日期范围

若要搜索某个时间段内的内容,请使用 created_at_i 和 Unix 时间戳:

先计算当前 Unix 时间戳(例如,通过 exec: date +%s),然后减去相应数值:

时间范围从当前时间减去
过去 24 小时- 86400
过去 7 天- 604800
过去 30 天- 2592000

示例:如果当前时间是 1705312200,过去 7 天 = numericFilters=created_at_i>1704707400

响应格式

每条搜索结果包含:

{
  "objectID": "12345",
  "title": "Story Title",
  "url": "https://example.com/article",
  "author": "username",
  "points": 150,
  "num_comments": 42,
  "created_at": "2024-01-15T10:30:00Z",
  "created_at_i": 1705312200,
  "story_text": "Text for Ask HN / Show HN (HTML)",
  "_tags": ["story", "author_username", "story_12345"]
}

对于评论,搜索结果还包含:

{
  "comment_text": "The comment body (HTML)",
  "story_id": 12345,
  "story_title": "Parent Story Title",
  "story_url": "https://example.com",
  "parent_id": 12344
}

响应封装包含:

{
  "hits": [...],
  "nbHits": 1000,
  "page": 0,
  "nbPages": 50,
  "hitsPerPage": 20
}

构建 HN 链接

  • 帖子: https://news.ycombinator.com/item?id={objectID}
  • 评论: https://news.ycombinator.com/item?id={objectID}
  • 用户: https://news.ycombinator.com/user?id={author}

分步说明

搜索某个主题的帖子
  1. 对查询词进行 URL 编码
  2. 获取:https://hn.algolia.com/api/v1/search?query=YOUR_QUERY&tags=story&hitsPerPage=10
  3. 解析 JSON 响应
  4. 对每条搜索结果,展示:标题、points、num_comments、作者、日期、HN 链接和原始 URL
查找近期 / 热门讨论
  1. 计算所需时间范围的 Unix 时间戳(例如,7 天前)
  2. 获取:https://hn.algolia.com/api/v1/search?query=YOUR_QUERY&tags=story&numericFilters=points>50,created_at_i>TIMESTAMP&hitsPerPage=10
  3. 按 points 或评论数对结果排序,以查找“热门”内容
获取帖子的评论
  1. 从搜索结果中获取帖子的 objectID
  2. 获取:https://hn.algolia.com/api/v1/search?tags=comment,story_STORYID&hitsPerPage=20
  3. 展示每条评论的 comment_text、作者和 points
监控某个主题(查看近期提及)
  1. 使用 /search_by_date,而不是 /search
  2. 获取:https://hn.algolia.com/api/v1/search_by_date?query=YOUR_QUERY&tags=(story,comment)&hitsPerPage=20
  3. 结果按时间从新到旧排列,适用于了解“HN 上关于 X 的最新消息”
查找某位用户的帖子
  1. 获取:https://hn.algolia.com/api/v1/search?tags=author_USERNAME,story&hitsPerPage=20
  2. 查找其评论:tags=author_USERNAME,comment

输出格式

将结果整理为清晰的列表:

### HN Results for "query" (N total)

1. **Story Title** (150 pts, 42 comments)
   By username · Jan 15, 2024
   🔗 https://example.com/article
   💬 https://news.ycombinator.com/item?id=12345

2. ...

评论格式:

### HN Comments on "Story Title"

1. **username** (12 pts) · Jan 15, 2024
   > First ~200 chars of the comment text...
   💬 https://news.ycombinator.com/item?id=12345

错误处理

  • 结果为空: 告知用户未找到结果。建议扩大查询范围或移除筛选条件。
  • API 错误/超时: 重试一次。如果仍然失败,告知用户 HN 搜索 API 可能暂时不可用。
  • 受到速率限制(429): 每小时 10k 次请求的限制不太可能触发,但如果触发,请等待 60 秒后重试。
  • 响应格式错误: 检查 URL 的构造方式。常见问题是查询中的特殊字符未编码。

示例

示例 1:“HN 上关于 Rust 有什么讨论?”
Fetch: https://hn.algolia.com/api/v1/search?query=rust+programming&tags=story&hitsPerPage=5&numericFilters=points>50
示例 2:“查找过去一个月关于 AI Agent 的 Show HN 帖子”
# Calculate timestamp for 30 days ago, then:
Fetch: https://hn.algolia.com/api/v1/search_by_date?query=ai+agents&tags=show_hn&numericFilters=created_at_i>TIMESTAMP&hitsPerPage=10
示例 3:“pg 最近发布了什么?”
Fetch: https://hn.algolia.com/api/v1/search_by_date?tags=author_pg&hitsPerPage=10

数据源

Algolia HN 搜索 API — 免费,无需身份验证。 近乎实时地索引所有公开的 Hacker News 内容。

评论

支持 Markdown