hn-search
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseHacker News Search
Hacker News 搜索
Search and monitor Hacker News stories, comments, and users via the Algolia HN Search API. No API key required.
通过Algolia HN Search API搜索和监控Hacker News的帖子、评论和用户。无需API密钥。
When to Use
使用场景
- User asks about Hacker News discussions on a topic
- User wants to find HN posts about a company, product, or technology
- User wants to monitor HN for mentions of something
- User asks "what's trending on HN" or "what did HN think about X"
- User wants to find Show HN / Ask HN / Launch HN posts
- 用户询问特定主题的Hacker News讨论内容
- 用户想要查找关于某家公司、产品或技术的HN帖子
- 用户想要监控HN上对某事物的提及
- 用户询问“HN上现在有什么热门内容”或“HN对X的评价如何”
- 用户想要查找Show HN / Ask HN / Launch HN类型的帖子
API Overview
API概述
Base URL:
https://hn.algolia.com/api/v1Two search endpoints:
- — Relevance-sorted (best for finding specific topics)
/search - — Date-sorted (best for monitoring / recent activity)
/search_by_date
Rate Limits: 10,000 requests/hour (generous, no auth needed)
基础URL:
https://hn.algolia.com/api/v1两个搜索端点:
- — 按相关性排序(最适合查找特定主题)
/search - — 按日期排序(最适合监控/查看近期动态)
/search_by_date
请求限制: 每小时10000次请求(额度充足,无需身份验证)
How to Search
搜索方法
Step 1: Build the URL
步骤1:构建URL
https://hn.algolia.com/api/v1/search?query=QUERY&tags=TAG&hitsPerPage=N&numericFilters=FILTERShttps://hn.algolia.com/api/v1/search?query=QUERY&tags=TAG&hitsPerPage=N&numericFilters=FILTERSStep 2: Fetch with web_fetch
web_fetch步骤2:使用web_fetch
发起请求
web_fetchUse to call the API. Response is JSON.
web_fetch使用调用API,返回结果为JSON格式。
web_fetchParameters
参数说明
| Parameter | Description | Example |
|---|---|---|
| Search terms (URL-encoded) | |
| Filter by type (see below) | |
| Results per page (max 1000) | |
| Page number (0-indexed) | |
| Numeric filters (see below) | |
| 参数 | 说明 | 示例 |
|---|---|---|
| 搜索关键词(需URL编码) | |
| 按类型过滤(见下文) | |
| 每页结果数量(最大1000) | |
| 页码(从0开始) | |
| 数值过滤条件(见下文) | |
Tag Filters
标签过滤规则
Use to filter by content type:
tags| Tag | Description |
|---|---|
| Stories only |
| Comments only |
| Show HN posts |
| Ask HN posts |
| Currently on front page |
| Posts by a specific user |
| Comments on a specific story |
Combine tags with commas (AND) or parentheses with commas (OR):
- → Show HN stories (AND)
tags=story,show_hn - → Stories OR comments
tags=(story,comment)
使用参数按内容类型过滤:
tags| 标签 | 说明 |
|---|---|
| 仅显示帖子 |
| 仅显示评论 |
| Show HN类型的帖子 |
| Ask HN类型的帖子 |
| 当前首页的内容 |
| 特定用户发布的内容 |
| 特定帖子下的评论 |
组合标签时使用逗号(逻辑与)或带逗号的括号(逻辑或):
- → 仅显示Show HN类型的帖子(逻辑与)
tags=story,show_hn - → 显示帖子或评论(逻辑或)
tags=(story,comment)
Numeric Filters
数值过滤条件
| Filter | Description |
|---|---|
| Minimum points/upvotes |
| Minimum comments |
| After Unix timestamp |
| Before Unix timestamp |
Combine with commas:
numericFilters=points>100,num_comments>50| 过滤条件 | 说明 |
|---|---|
| 最小点赞数 |
| 最小评论数 |
| 晚于指定Unix时间戳 |
| 早于指定Unix时间戳 |
使用逗号组合多个条件:
numericFilters=points>100,num_comments>50Date Ranges
日期范围搜索
To search within a time window, use Unix timestamps with :
created_at_iCalculate the current Unix timestamp first (e.g., via ), then subtract:
exec: date +%s| Window | Subtract from now |
|---|---|
| Last 24 hours | |
| Last 7 days | |
| Last 30 days | |
Example: if now is , last 7 days =
1705312200numericFilters=created_at_i>1704707400要在特定时间窗口内搜索,可结合使用Unix时间戳:
created_at_i先计算当前Unix时间戳(例如通过),再进行减法计算:
exec: date +%s| 时间窗口 | 从当前时间减去 |
|---|---|
| 过去24小时 | |
| 过去7天 | |
| 过去30天 | |
示例:如果当前时间戳是,那么过去7天的条件为
1705312200numericFilters=created_at_i>1704707400Response Format
响应格式
Each hit contains:
json
{
"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"]
}For comments, hits also include:
json
{
"comment_text": "The comment body (HTML)",
"story_id": 12345,
"story_title": "Parent Story Title",
"story_url": "https://example.com",
"parent_id": 12344
}The response wrapper includes:
json
{
"hits": [...],
"nbHits": 1000,
"page": 0,
"nbPages": 50,
"hitsPerPage": 20
}每个搜索结果(hit)包含以下字段:
json
{
"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"]
}对于评论结果,还会包含以下字段:
json
{
"comment_text": "The comment body (HTML)",
"story_id": 12345,
"story_title": "Parent Story Title",
"story_url": "https://example.com",
"parent_id": 12344
}响应包装器包含以下字段:
json
{
"hits": [...],
"nbHits": 1000,
"page": 0,
"nbPages": 50,
"hitsPerPage": 20
}Constructing HN Links
构建HN链接
- Story:
https://news.ycombinator.com/item?id={objectID} - Comment:
https://news.ycombinator.com/item?id={objectID} - User:
https://news.ycombinator.com/user?id={author}
- 帖子链接:
https://news.ycombinator.com/item?id={objectID} - 评论链接:
https://news.ycombinator.com/item?id={objectID} - 用户主页链接:
https://news.ycombinator.com/user?id={author}
Step-by-Step Instructions
分步操作指南
Searching for Stories on a Topic
搜索特定主题的帖子
- URL-encode the query
- Fetch:
https://hn.algolia.com/api/v1/search?query=YOUR_QUERY&tags=story&hitsPerPage=10 - Parse the JSON response
- For each hit, present: title, points, num_comments, author, date, HN link, and original URL
- 对搜索关键词进行URL编码
- 发起请求:
https://hn.algolia.com/api/v1/search?query=YOUR_QUERY&tags=story&hitsPerPage=10 - 解析JSON响应结果
- 对每个结果,展示:标题、点赞数、评论数、作者、发布日期、HN链接及原始文章链接
Finding Recent/Trending Discussions
查找近期/热门讨论
- Calculate Unix timestamp for your time window (e.g., 7 days ago)
- Fetch:
https://hn.algolia.com/api/v1/search?query=YOUR_QUERY&tags=story&numericFilters=points>50,created_at_i>TIMESTAMP&hitsPerPage=10 - Sort results by points or comments for "trending"
- 计算目标时间窗口对应的Unix时间戳(例如7天前)
- 发起请求:
https://hn.algolia.com/api/v1/search?query=YOUR_QUERY&tags=story&numericFilters=points>50,created_at_i>TIMESTAMP&hitsPerPage=10 - 按点赞数或评论数对结果排序,筛选“热门”内容
Getting Comments on a Story
获取某帖子下的评论
- Get the story's objectID from a search
- Fetch:
https://hn.algolia.com/api/v1/search?tags=comment,story_STORYID&hitsPerPage=20 - Present comment_text, author, points for each
- 通过搜索获取目标帖子的objectID
- 发起请求:
https://hn.algolia.com/api/v1/search?tags=comment,story_STORYID&hitsPerPage=20 - 展示每条评论的内容、作者及点赞数
Monitoring a Topic (Show Recent Mentions)
监控特定主题(查看近期提及内容)
- Use instead of
/search_by_date/search - Fetch:
https://hn.algolia.com/api/v1/search_by_date?query=YOUR_QUERY&tags=(story,comment)&hitsPerPage=20 - Results are newest-first — useful for "what's new about X on HN"
- 使用端点替代
/search_by_date/search - 发起请求:
https://hn.algolia.com/api/v1/search_by_date?query=YOUR_QUERY&tags=(story,comment)&hitsPerPage=20 - 结果按最新排序——适用于查看“HN上关于X的最新动态”
Finding a User's Posts
查找某用户的发布内容
- Fetch:
https://hn.algolia.com/api/v1/search?tags=author_USERNAME,story&hitsPerPage=20 - For their comments:
tags=author_USERNAME,comment
- 发起请求:
https://hn.algolia.com/api/v1/search?tags=author_USERNAME,story&hitsPerPage=20 - 若要查找该用户的评论:使用
tags=author_USERNAME,comment
Output Format
输出格式
Present results as a clean list:
undefined将结果整理为清晰的列表:
undefinedHN Results for "query" (N total)
关键词“query”的HN搜索结果(共N条)
-
Story Title (150 pts, 42 comments) By username · Jan 15, 2024 🔗 https://example.com/article 💬 https://news.ycombinator.com/item?id=12345
-
...
For comments:-
帖子标题(150赞,42条评论) 作者:username · 2024年1月15日 🔗 https://example.com/article 💬 https://news.ycombinator.com/item?id=12345
-
...
评论结果格式:HN Comments on "Story Title"
帖子“Story Title”的HN评论
- username (12 pts) · Jan 15, 2024
First ~200 chars of the comment text... 💬 https://news.ycombinator.com/item?id=12345
undefined- username(12赞)· 2024年1月15日
评论内容前200字符... 💬 https://news.ycombinator.com/item?id=12345
undefinedError Handling
错误处理
- Empty results: Tell the user no results were found. Suggest broadening the query or removing filters.
- API error / timeout: Retry once. If still failing, inform the user the HN search API may be temporarily down.
- Rate limited (429): Unlikely at 10k/hr, but if hit, wait 60 seconds and retry.
- Malformed response: Check the URL construction — common issues are unencoded special characters in the query.
- 无结果: 告知用户未找到结果,建议放宽搜索条件或移除过滤规则。
- API错误/超时: 重试一次。若仍失败,告知用户HN搜索API可能暂时无法访问。
- 请求受限(429状态码): 每小时10000次的额度很难触发,但如果遇到,等待60秒后重试。
- 响应格式异常: 检查URL构建是否正确——常见问题是搜索关键词中的特殊字符未编码。
Examples
使用示例
Example 1: "What's HN saying about Rust?"
示例1:“HN上关于Rust的讨论有哪些?”
Fetch: https://hn.algolia.com/api/v1/search?query=rust+programming&tags=story&hitsPerPage=5&numericFilters=points>50Fetch: https://hn.algolia.com/api/v1/search?query=rust+programming&tags=story&hitsPerPage=5&numericFilters=points>50Example 2: "Find Show HN posts about AI agents from the last month"
示例2:“查找过去一个月内关于AI Agent的Show HN帖子”
undefinedundefinedCalculate timestamp for 30 days ago, then:
计算30天前的时间戳,然后发起请求:
undefinedExample 3: "What has pg posted recently?"
示例3:“pg最近发布了什么内容?”
Fetch: https://hn.algolia.com/api/v1/search_by_date?tags=author_pg&hitsPerPage=10Fetch: https://hn.algolia.com/api/v1/search_by_date?tags=author_pg&hitsPerPage=10Data Source
数据来源
Algolia HN Search API — Free, no authentication required.
Indexes all public Hacker News content in near real-time.
Algolia HN Search API — 免费,无需身份验证。
近乎实时地索引所有公开的Hacker News内容。