带高亮和字段选择的搜索结果
构建一个带有突出显示的术语、字段选择和多个过滤器的搜索界面
输入参数
| 参数 | 描述 | 类型 | 默认 | 必需 |
|---|---|---|---|---|
| title | 搜索查询。 | string | 是 | |
| fl | 用于优化的字段选择。 | string | 是 | |
| hl | 启用高亮显示。 | boolean | true | 是 |
| hl.fl | 要突出显示的字段。 | string | 是 | |
| per_page | 要检索的最大文章数 | integer | 20 | 是 |
| sort.by | 按相关性排序。 | string | 是 | |
| sort.order | 降序。 | string | 是 | |
| api_key | 您的 API 密钥 | string | 是 |
工作流程示例
带高亮的搜索结果:
curl -X GET "https://api.apitube.io/v1/news/everything?title=AI&fl=id,title,description,published_at,source.domain&hl=true&hl.fl=title,description&per_page=10&sort.by=published_at&sort.order=desc&api_key=YOUR_API_KEY"
HTML 的自定义高亮标签:
curl -X GET "https://api.apitube.io/v1/news/everything?title=Tesla&hl=true&hl.tag.pre=<mark>&hl.tag.post=</mark>&api_key=YOUR_API_KEY"
更大的摘要和更多结果:
curl -X GET "https://api.apitube.io/v1/news/everything?title=climate%20change&hl=true&hl.fragsize=300&hl.snippets=5&api_key=YOUR_API_KEY"
结合过滤器的请求:
curl -X GET "https://api.apitube.io/v1/news/everything?title=Apple&organization.name=Apple&hl=true&hl.fl=title,description&sentiment.overall.polarity=positive&published_at.start=2024-01-01&published_at.end=2024-01-31&api_key=YOUR_API_KEY"
相关示例
食谱 cURL
curl --location --globoff --request POST 'https://api.apitube.io/v1/news/everything?title=AI&fl=id%2Ctitle%2Cdescription%2Cpublished_at%2Csource.domain&hl=1&hl.fl=title%2Cdescription&per_page=10&sort.by=published_at&sort.order=desc&api_key=YOUR_API_KEY' \
--header 'Content-Type: application/json'
食谱 Python
import requests
url = "https://api.apitube.io/v1/news/everything"
querystring = {
"title": "AI",
"fl": "id,title,description,published_at,source.domain",
"hl": true,
"hl.fl": "title,description",
"per_page": 10,
"sort.by": "published_at",
"sort.order": "desc",
"api_key": "YOUR_API_KEY"
}
response = requests.request("GET", url, params=querystring)
print(response.text)
食谱 Javascript
import axios from "axios"
const options = {
method: 'GET',
url: 'https://api.apitube.io/v1/news/everything',
params: {
"title": "AI",
"fl": "id,title,description,published_at,source.domain",
"hl": true,
"hl.fl": "title,description",
"per_page": 10,
"sort.by": "published_at",
"sort.order": "desc",
"api_key": "YOUR_API_KEY"
}};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
食谱 PHP
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client();
$response = $client->request('GET', 'https://api.apitube.io/v1/news/everything', [
'query' => [
'title' => 'AI',
'fl' => 'id,title,description,published_at,source.domain',
'hl' => 1,
'hl.fl' => 'title,description',
'per_page' => 10,
'sort.by' => 'published_at',
'sort.order' => 'desc',
'api_key' => 'YOUR_API_KEY',
],
]);
echo $response->getBody();
食谱 Java
OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "");
Request request = new Request.Builder()
.url("https://api.apitube.io/v1/news/everything?title=AI&fl=id%2Ctitle%2Cdescription%2Cpublished_at%2Csource.domain&hl=1&hl.fl=title%2Cdescription&per_page=10&sort.by=published_at&sort.order=desc&api_key=YOUR_API_KEY")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();