# 新闻语义搜索

- 接口：semantic_search_news_handler
- 路径：/api/v3/market/data/semantic-search-news
- 方法：GET
- 描述：语义搜索新闻接口。根据搜索文字 `query` 转调外部语义检索服务，返回相关新闻列表。支持按 `year`（年份）或 `start_time` / `end_time`（时间区间）限定搜索范围，时间区间需在同一 3 天窗口内。直接返回数组，每条新闻含新闻 ID、来源站点、文章链接、发布/抓取时间、标题、媒体、摘要、正文、匹配分数等。
- 数据范围：依赖外部语义检索服务的数据范围（实时检索，无固定时间维度）
- 单次限量：返回条数由 `limit` 控制，默认由服务端决定
- 提示：
  - `query` 必填。
  - 同时传 `start_time` / `end_time` 时，区间跨度不得超过 3 天。
  - 接口转调外部服务，开放路由，可能受上游可用性与延迟影响。

## 输入参数

| 名称 | 类型 | 必选 | 描述 |
|------|------|------|------|
| query | string | Y | 搜索文字 |
| limit | integer | N | 返回条数，默认由服务端决定 |
| year | integer | N | 年份，限定搜索范围 |
| start_time | string | N | 起始时间（带时区），与 end_time 同传时区间不超过 3 天 |
| end_time | string | N | 结束时间（带时区），与 start_time 同传时区间不超过 3 天 |

## 输出参数

成功响应外层固定为 `code`、`message`、`data`：

| 名称 | 类型 | 默认显示 | 描述 |
|------|------|---------|------|
| code | integer | Y | 状态码。 |
| message | string | Y | 状态信息。 |
| data | array / null | Y | 新闻列表。 |

data 数组：

| 名称 | 类型 | 默认显示 | 描述 |
|------|------|---------|------|
| news_id | integer | Y | 新闻 ID |
| source_site | string | Y | 来源站点 |
| article_url | string | N | 文章链接 |
| publish_time | string | N | 发布时间 |
| fetch_time | string | Y | 抓取时间 |
| title | string | N | 标题 |
| media_name | string | N | 媒体名称 |
| summary | string | N | 摘要 |
| content | string | Y | 正文内容 |
| is_truncated | integer | Y | 是否被截断（0/1） |
| is_reviewed | integer | Y | 是否已审核（0/1） |
| score | number | Y | 搜索匹配分数 |

## 接口示例

```bash
curl -sS "https://market.ft.tech/gateway/api/v3/market/data/semantic-search-news?query=新能源汽车&limit=5"
```

Python（[`ftshare`](https://github.com/FTShare-Lab/FTShare-python-sdk.git) SDK，方法 `market.semantic_search_news`，默认返回 pandas `DataFrame`）：

```python
import ftshare as ft

market = ft.market_api()

# 默认返回 DataFrame（query 为搜索文字，必填）
df = market.semantic_search_news(query="人工智能", limit=3)
print(df[["title", "publish_time", "media_name", "score"]])
#                 title         publish_time media_name  score
# 0    人工智能全面赋能电商大促  2026-06-18T09:11:00       经济日报   ...
# 1  把握人工智能产业化应用大趋势  2026-06-13T08:13:00       经济日报   ...

# 限定年份范围
df = market.semantic_search_news(query="美联储", limit=5, year=2026)

# 返回原始 JSON（未经 DataFrame 抽取，含完整 content 正文）
payload = market.semantic_search_news(query="苹果", limit=3, raw=True)
```

## 数据样例

`query` 转调外部语义检索服务，以下为 `query=苹果` 的一条命中（金十快讯）：

| news_id | source_site | publish_time | summary |
|---------|-------------|--------------|---------|
| 586966128614445057 | 金十_快讯 | 2026-06-09T01:05:33 | 苹果(...) |
| ... | ... | ... | ... |
