基本信息
接口名称: 文章全文搜索
接口类型: 数据获取
接口说明: 通过关键字搜索文章
详细信息
URL
https://www.baklib.com/api/v1/articles/search
完整URL示例
https://wwwbaklib.com/api/v1/articles/search?tenant_id=aaa24dbe-a17b-4439-911d-176e0149cf76&from=frontend&keywords=%E6%B5%8B%E8%AF%95&_page=1&_per_page=10
HTTP请求方式
GET
授权认证方式
默认方式,需要添加请求header
Authorization: Bearer <token>
请求参数
参数 | 必选 | 类型及范围 | 说明 |
---|---|---|---|
tenant_id | true | Integer | 站点id |
from | true | String | 从哪里发起搜索, frontend 表示前端,admin 表示管理端 |
keywords | true | String | 搜索关键字 |
user_access_level | false | Integer | 显示特定用户访问等级可见的内容, 值范围 0~10 |
_page | false | Integer | 需要显示的页码, 默认1 |
_per_page | false | Integer | 每页显示数量, 默认10, 最大不能超过50 |
示例代码
var data = "";
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://www.baklib.com/api/v1/articles/search?tenant_id=aaa24dbe-a17b-4439-911d-176e0149cf76&from=frontend&keywords=%25E6%25B5%258B%25E8%25AF%2595&_page=1&_per_page=10");
xhr.setRequestHeader("Authorization", "Bearer 8486df9cb8a93ea843702141065c4a8b714602b45e7c4a6bb26a26ea3d69de6");
xhr.send(data);
返回结果
{
"code": 0,
"status": "success",
"message": {
"meta": {
"current_page": 1,
"total_pages": 1,
"total_count": 3
},
"items": [
{
"id": "0d1d9707-4949-4bb7-85c2-ec6fe90061c5",
"name": "测试1",
"frontend_url": "XXX",
"slug": "bfc9/afad",
"identifier": "afad",
"name_highlight": "<b class=\"highlight\">测试</b>1",
"search_highlight": "<b class=\"highlight\">测试</b>1.1,",
"access_level": 0,
"channels": [
{
"id": "38a4383f-9249-44b7-8531-6c9c35529aac",
"slug": "",
"url": "XXX",
"name": "首页",
"access_level": 0
},
{
"id": "9fca4e37-ce6d-4ddb-8082-896cebb509ce",
"slug": "bfc9",
"url": "XXX",
"name": "栏目1",
"access_level": 0
}
]
},
{
"id": "e0a4f846-f090-4901-aff3-66362ab51ffd",
"name": "测试1053",
"frontend_url": "XXX",
"slug": "xiaohui4/6cba",
"identifier": "6cba",
"name_highlight": "<b class=\"highlight\">测试</b>1053",
"search_highlight": "10点53分创建",
"access_level": 1,
"channels": [
{
"id": "38a4383f-9249-44b7-8531-6c9c35529aac",
"slug": "",
"url": "XXX",
"name": "首页",
"access_level": 0
},
{
"id": "1dfbdd9d-5b9d-4961-8fae-eed05f6563ce",
"slug": "xiaohui4",
"url": "XXX",
"name": "baba",
"access_level": 0
}
]
},
{
"id": "53aa7f47-c642-45e0-8ab2-9c7e0b905595",
"name": "测试1710",
"frontend_url": "XXX",
"slug": "bfc9/3a07",
"identifier": "3a07",
"name_highlight": "<b class=\"highlight\">测试</b>1710",
"search_highlight": "",
"access_level": 0,
"channels": [
{
"id": "38a4383f-9249-44b7-8531-6c9c35529aac",
"slug": "",
"url": "XXX",
"name": "首页",
"access_level": 0
},
{
"id": "9fca4e37-ce6d-4ddb-8082-896cebb509ce",
"slug": "bfc9",
"url": "XXX",
"name": "栏目1",
"access_level": 0
}
]
}
]
}
}
返回字段说明
返回值字段 | 字段类型 | 说明 |
---|---|---|
code | Integer | 状态码 |
status | String | 返回状态 |
message | Hash | 返回数据 |
meta | Hash | 列表元数据 |
current_page | Intger | 当前页码 |
total_pages | Intger | 总页数 |
total_count | Intger | 总记录数 |
items | Array | 结果集 |
id | String | 文章编号 |
name | String | 文章标题 |
frontend_url | String | 文章前端访问的链接 |
slug | String | 文章相对路径 |
identifier | String | 文章标识符 |
name_highlight | String | 关键字高亮的文章标题 |
search_highlight | String | 关键字高亮的内容描述 |
access_level | Integer | 文章访问等级 |
channels | Array | 文章所属栏目,从大到小 |
id | String | 栏目编号 |
slug | String | 栏目相对路径 |
url | String | 栏目前端访问链接 |
name | String | 栏目标题 |
access_level | Integer | 栏目访问等级 |