搜索API
获取搜索结果
请求
| HTTP方法 | GET |
| 端点 | /api/v1/documents |
向 Fess 发送 http://<Server Name>/api/v1/documents?q=搜索词 形式的请求, 可以获取 Fess 的搜索结果的JSON格式数据。 要使用搜索API,需要在管理界面的”系统 > 常规设置”中启用JSON响应。
请求参数
通过指定 http://<Server Name>/api/v1/documents?q=搜索词&num=50&fields.label=fess 等请求参数,可以执行更高级的搜索。 可用的请求参数如下:
| q | 搜索词。需要进行URL编码。 |
| start | 起始位置。从0开始。 |
| num | 显示数量。默认为20条。最多可显示100条。 |
| sort | 排序。用于对搜索结果进行排序。 |
| fields.label | 标签值。用于指定标签。 |
| facet.field | 分面字段指定。 (示例) facet.field=label |
| facet.query | 分面查询指定。 (示例) facet.query=timestamp:[now/d-1d TO *] |
| facet.size | 获取分面的最大数量。当指定了facet.field时有效。 |
| facet.minDocCount | 获取数量大于等于此值的分面。当指定了facet.field时有效。 |
| geo.location.point | 经纬度指定。 (示例) geo.location.point=35.0,139.0 |
| geo.location.distance | 从中心点的距离指定。 (示例) geo.location.distance=10km |
| lang | 搜索语言指定。 (示例) lang=en |
| preference | 搜索时指定分片的字符串。 (示例) preference=abc |
| callback | 使用JSONP时的回调名称。不使用JSONP时无需指定。 |
表: 请求参数
响应
将返回以下响应。
(已格式化)
{
"q": "Fess",
"query_id": "bd60f9579a494dfd8c03db7c8aa905b0",
"exec_time": 0.21,
"query_time": 0,
"page_size": 20,
"page_number": 1,
"record_count": 31625,
"page_count": 1,
"highlight_params": "&hq=n2sm&hq=Fess",
"next_page": true,
"prev_page": false,
"start_record_number": 1,
"end_record_number": 20,
"page_numbers": [
"1",
"2",
"3",
"4",
"5"
],
"partial": false,
"search_query": "(Fess OR n2sm)",
"requested_time": 1507822131845,
"related_query": [
"aaa"
],
"related_contents": [],
"data": [
{
"filetype": "html",
"title": "Open Source Enterprise Search Server: Fess — Fess 11.0 documentation",
"content_title": "Open Source Enterprise Search Server: Fess — Fe...",
"digest": "Docs » Open Source Enterprise Search Server: Fess Commercial Support Open Source Enterprise Search Server: Fess What is Fess ? Fess is very powerful and easily deployable Enterprise Search Server. ...",
"host": "fess.codelibs.org",
"last_modified": "2017-10-09T22:28:56.000Z",
"content_length": "29624",
"timestamp": "2017-10-09T22:28:56.000Z",
"url_link": "https://fess.codelibs.org/",
"created": "2017-10-10T15.30:48.609Z",
"site_path": "fess.codelibs.org/",
"doc_id": "e79fbfdfb09d4bffb58ec230c68f6f7e",
"url": "https://fess.codelibs.org/",
"content_description": "Enterprise Search Server: <strong>Fess</strong> Commercial Support Open...Search Server: <strong>Fess</strong> What is <strong>Fess</strong> ? <strong>Fess</strong> is very powerful...You can install and run <strong>Fess</strong> quickly on any platforms...Java runtime environment. <strong>Fess</strong> is provided under Apache...Apache license. Demo <strong>Fess</strong> is OpenSearch-based search",
"site": "fess.codelibs.org/",
"boost": "10.0",
"mimetype": "text/html"
}
]
}
各元素说明如下:
搜索所有文档
要搜索所有目标文档,请发送以下请求: http://<Server Name>/api/v1/documents/all?q=搜索词
要使用此功能,需要在fess_config.properties中将api.search.scroll设置为true。
请求参数
可用的请求参数如下:
| q | 搜索词。需要进行URL编码。 |
| num | 显示数量。默认为20条。最多可显示100条。 |
| sort | 排序。用于对搜索结果进行排序。 |
表: 请求参数
错误响应
当搜索API失败时,将返回以下错误响应:
| 状态码 | 说明 |
| 400 Bad Request | 请求参数无效 |
| 500 Internal Server Error | 服务器内部错误 |
错误响应示例:
{
"message": "Invalid request parameter",
"status": 400
}