小宿智能搜索(短摘要版)
公共信息
参数说明
| 参数 | 描述 |
|---|---|
| BasePath | 调用 API 的基础路径 |
| Endpoint | 调用 API 时生成的一段随机路径 |
| AccessKey | 调用 API 的 AccessKey |
请求路径
https://{BasePath}/search/{Endpoint}/smart
请求方法
GET
请求头
| 参数 | 类型 | 描述 |
|---|---|---|
| Authorization | String | 输入值:Bearer {AK},其中 AK 即 AccessKey |
| Pragma | String | 输入值:no-cache。输入no-cache返回结果不开启缓存、每次独立请求;不输入则相同查询词的返回结果会有10分钟的缓存 |
请求体参数
| 参数 | 是否必填 | 类型 | 描述 |
|---|---|---|---|
| q | Y | String | 用户的搜索查询词,该词不能为空。 |
| count | N | Short | 返回结果中包含的搜索结果数量。默认值为10,最大50。 枚举值: - 10 - 20 - 30 - 40 - 50 实际返回的数量可能少于请求的数量。使用此参数和偏移量参数一起分页结果。 |
| freshness | N | String | 按以下值筛选不同时间段的搜索结果: - Day (近一天) - Week(近一周) - Month(近一个月) |
| offset | N | Short | 从0开始的偏移量,指示在返回结果之前要跳过的搜索结果数量。默认值为0。使用此参数与 count 参数一起分页显示结果。 offset 不设范围,设置较大时,会导致搜索结果为空。 |
| sites | N | String | 该字段的值需填写 host 地址格式(示例:baijiahao.baidu.com),填写后返回指定站点的结果 |
| blockWebsites | N | String | 该字段的值需填写 host 地址格式(示例:baijiahao.baidu.com),填写后去除指定站点的结果 |
⚠ 请求参数及枚举值,均大小写敏感
返回值说明
| 字段 | 类型 | 描述 |
|---|---|---|
| queryContext.originalQuery | String | 请求中的用户查询词 |
| webPages.value | Array | 返回的详细结果数据 |
| webPages.value.name | String | 网页标题 |
| webPages.value.snippet | String | 描述网页内容的文本短摘要 |
| webPages.value.url | String | 网页 URL |
| webPages.value.datePublished | String | 网页发布时间(部分网页包含) |
| webPages.value.siteName | String | 网站名称(部分网页包含) |
| webPages.value.score | Float | 内容相关性分数 |
请求示例
cURL 示例
curl --location --request GET 'https://{BasePath}/search/{Endpoint}/smart?q=cat' \
--header 'Authorization: Bearer {AK}' \
--header 'pragma: no-cache'
Python(Requests)示例
import requests
BasePath = 'xxxxxx' # 请替换为您获取到的 BasePath
Endpoint = 'xxxxxx' # 请替换为您获取到的 Endpoint
AK = 'xxxxxx' # 请替换为您获取到的 AK
url = f"https://{BasePath}/search/{Endpoint}/smart"
payload = {
"q": "cat"
}
headers = {
'Authorization': f'Bearer {AK}',
'Pragma': 'no-cache'
}
response = requests.get(url, headers=headers, params=payload)
print(response.text)
返回示例
{
"queryContext": {
"originalQuery": "cat"
},
"webPages": {
"value": [
{
"name": "Cat -xxxx",
"url": "https://xxx/xxx",
"snippet": "The cat (Felis catus), also referred to as the domestic cat or house cat, is a small domesticated carnivorous mammal. It is the only domesticated species of the family Felidae. Advances in archaeology and genetics have shown that the domestication of the cat occurred in the Near East around 7500 BC. It is commonly kept as a pet and working cat, but also ranges freely as a feral cat avoiding ...",
"siteName": "xxxxx"
}
]
}
}