关于 hn-search
hn-search 是通过 Algolia HN Search API 搜索和监控 Hacker News 故事、评论及用户帖子的技能。它支持按相关性或日期搜索,并可按内容类型、活跃度和时间筛选。
主要功能
- 01搜索故事、评论和用户帖子
- 02按相关性或日期排序搜索
- 03按内容类型和活跃度筛选
- 04查找主题的近期提及
- 05获取特定故事的评论
适用场景
- 01了解 Hacker News 对某主题的讨论
- 02追踪产品或公司的近期提及
- 03查找 Show HN 或 Ask HN 帖子
- 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_hn | Show HN 帖子 |
ask_hn | Ask 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}
分步说明
搜索某个主题的帖子
- 对查询词进行 URL 编码
- 获取:
https://hn.algolia.com/api/v1/search?query=YOUR_QUERY&tags=story&hitsPerPage=10 - 解析 JSON 响应
- 对每条搜索结果,展示:标题、points、num_comments、作者、日期、HN 链接和原始 URL
查找近期 / 热门讨论
- 计算所需时间范围的 Unix 时间戳(例如,7 天前)
- 获取:
https://hn.algolia.com/api/v1/search?query=YOUR_QUERY&tags=story&numericFilters=points>50,created_at_i>TIMESTAMP&hitsPerPage=10 - 按 points 或评论数对结果排序,以查找“热门”内容
获取帖子的评论
- 从搜索结果中获取帖子的 objectID
- 获取:
https://hn.algolia.com/api/v1/search?tags=comment,story_STORYID&hitsPerPage=20 - 展示每条评论的 comment_text、作者和 points
监控某个主题(查看近期提及)
- 使用
/search_by_date,而不是/search - 获取:
https://hn.algolia.com/api/v1/search_by_date?query=YOUR_QUERY&tags=(story,comment)&hitsPerPage=20 - 结果按时间从新到旧排列,适用于了解“HN 上关于 X 的最新消息”
查找某位用户的帖子
- 获取:
https://hn.algolia.com/api/v1/search?tags=author_USERNAME,story&hitsPerPage=20 - 查找其评论:
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