培训
模块
将更多数据引入 Microsoft 搜索 - Training
了解 Microsoft Graph 和联合连接器可以如何帮助你将组织的更多数据引入 Microsoft 搜索。 使用自定义垂直搜索、结果群集和其他自定义项来增强用户的搜索体验。
可以使用 Microsoft Graph 中的 Microsoft 搜索 API 来优化搜索结果并在索引中显示其分布。
若要优化结果,请在 搜索请求中指定 aggregationOption。 每个 aggregationOption 指定要计算聚合的属性,以及响应中要返回的 searchBucket 项数。
以下示例搜索 listItem 资源,并按其文件类型、内容类和上次修改时间聚合结果,所有这些都是字符串值。
响应包括两个 searchBucket 对象,用于两个聚合:
contentclass
或 lastModifiedTime
) (的匹配 listItem 对象的实际fileType
值,这些匹配的 listItem 对象由该值聚合在同一存储桶中。docx
、 xlsx
和 pptx
。STS_ListItem_DocumentLibrary
的所有匹配对象。Before 2021-09-01T09:08:19.6224752Z
、 From 2021-09-01T09:08:19.6224752Z up to 2021-11-09T09:08:19.6224752Z
和 2021-11-09T09:08:19.6224752Z or later
。POST https://graph.microsoft.com/beta/search/query
Content-Type: application/json
{
"requests": [
{
"entityTypes": [
"listItem"
],
"query": {
"queryString": "test"
},
"from": 0,
"size": 25,
"aggregations": [
{
"field": "fileType",
"size": 20,
"bucketDefinition": {
"sortBy": "count",
"isDescending": "true",
"minimumCount": 0
}
},
{
"field": "contentclass",
"size": 15,
"bucketDefinition": {
"sortBy": "keyAsString",
"isDescending": "true",
"minimumCount": 0
}
},
{
"field": "lastModifiedTime",
"size": 2,
"bucketDefinition": {
"sortBy": "KeyAsString",
"isDescending": "true",
"minimumCount": 0,
"ranges": [
{
"to": "2021-09-01T09:08:19.6224752Z"
},
{
"from": "2021-09-01T09:08:19.6224752Z",
"to": "2021-11-09T09:08:19.6224752Z"
},
{
"from": "2021-11-09T09:08:19.6224752Z"
}
]
}
}
]
}
]
}
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.type": "#microsoft.graph.searchResponse",
"hitsContainers": [
{
"@odata.type": "#microsoft.graph.searchHitsContainer",
"hits": [
"..."
],
"total": 9,
"moreResultsAvailable": false,
"aggregations": [
{
"@odata.type": "#microsoft.substrateSearch.searchAggregation",
"field": "fileType",
"buckets": [
{
"@odata.type": "#microsoft.substrateSearch.searchBucket",
"key": "docx",
"count": 5,
"aggregationFilterToken": "\"ǂǂ646f6378\""
},
{
"@odata.type": "#microsoft.substrateSearch.searchBucket",
"key": "xlsx",
"count": 3,
"aggregationFilterToken": "\"ǂǂ786c7378\""
},
{
"@odata.type": "#microsoft.substrateSearch.searchBucket",
"key": "pptx",
"count": 1,
"aggregationFilterToken": "\"ǂǂ70707478\""
}
]
},
{
"@odata.type": "#microsoft.substrateSearch.searchAggregation",
"field": "contentclass",
"buckets": [
{
"@odata.type": "#microsoft.substrateSearch.searchBucket",
"key": "STS_ListItem_DocumentLibrary",
"count": 9,
"aggregationFilterToken": "\"ǂǂ5354535f4c6973744974656d5f446f63756d656e744c696272617279\""
}
]
},
{
"@odata.type": "#microsoft.substrateSearch.searchAggregation",
"field": "lastModifiedTime",
"buckets": [
{
"key": "Before 2021-09-01T09:08:19.6224752Z",
"count": 5,
"aggregationFilterToken": "range(min, 2021-09-01T09:08:19.6224752Z)"
},
{
"key": "From 2021-09-01T09:08:19.6224752Z up to 2021-11-09T09:08:19.6224752Z",
"count": 3,
"aggregationFilterToken": "range(2021-09-01T09:08:19.6224752Z, 2021-11-09T09:08:19.6224752Z)"
},
{
"key": "2021-11-09T09:08:19.6224752Z or later",
"count": 1,
"aggregationFilterToken": "range(2021-11-09T09:08:19.6224752Z, max, to=\"le\")"
}
]
}
]
}
]
}
本示例应用一个聚合筛选器,该筛选器基于返回的 aggregationFilterToken 作为docx
fileType
字段和From 2021-09-01T09:08:19.6224752Z up to 2021-11-09T09:08:19.6224752Z
lastModifiedTime
示例 1 中的字段。
分配给 aggregationFilters 属性的字符串值遵循格式“{field}:\”{aggregationFilterToken}\“”。 如果同一筛选器需要多个值,则分配给 aggregationFilters 属性的字符串值应遵循以下格式:“{field}:或 (\”{aggregationFilterToken1}\“,\”{aggregationFilterToken2}\“) ”。
分配给 aggregationFilters 属性的 datetime 格式字符串值遵循格式“{field}:{aggregationFilterToken}”。
POST https://graph.microsoft.com/beta/search/query
Content-Type: application/json
{
"requests": [
{
"entityTypes": [
"driveItem"
],
"query": {
"queryString": "test"
},
"from": 0,
"size": 20,
"aggregations": [
{
"field": "fileType",
"size": 10,
"bucketDefinition": {
"sortBy": "count",
"isDescending": "true",
"minimumCount": 0
}
}
],
"aggregationFilters": [
"fileType:\"ǂǂ68746d6c\"",
"lastModifiedTime:range(2021-09-01T09:08:19.6224752Z, 2021-11-09T09:08:19.6224752Z)"
]
}
]
}
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.type": "#microsoft.graph.searchResponse",
"hitsContainers": [
{
"@odata.type": "#microsoft.graph.searchHitsContainer",
"hits": [
"..."
],
"total": 69960,
"moreResultsAvailable": true,
"aggregations": [
{
"@odata.type": "#microsoft.substrateSearch.searchAggregation",
"field": "fileType",
"buckets": [
{
"@odata.type": "#microsoft.substrateSearch.searchBucket",
"key": "html",
"count": 69960,
"aggregationFilterToken": "\"ǂǂ68746d6c\""
}
]
},
{
"@odata.type": "#microsoft.substrateSearch.searchAggregation",
"field": "lastModifiedTime",
"buckets": [
{
"key": "Before 2021-09-01T09:08:19.6224752Z",
"count": 0,
"aggregationFilterToken": "range(min, 2021-09-01T09:08:19.6224752Z)"
},
{
"key": "From 2021-09-01T09:08:19.6224752Z up to 2021-11-09T09:08:19.6224752Z",
"count": 69960,
"aggregationFilterToken": "range(2021-09-01T09:08:19.6224752Z, 2021-11-09T09:08:19.6224752Z)"
},
{
"key": "2021-11-09T09:08:19.6224752Z or later",
"count": 0,
"aggregationFilterToken": "range(2021-11-09T09:08:19.6224752Z, max, to=\"le\")"
}
]
}
]
}
]
}
以下示例搜索 driveItem 资源,并按其大小(数值)聚合结果。 请求按 3 个大小范围指定聚合:
响应包括 3 个 searchBucket 对象,每个大小范围聚合各一个:
POST https://graph.microsoft.com/beta/search/query
Content-Type: application/json
{
"requests": [
{
"entityTypes": [
"driveItem"
],
"query": {
"queryString": "test"
},
"from": 0,
"size": 10,
"aggregations": [
{
"field": "Size",
"size": 5,
"bucketDefinition": {
"sortBy": "keyAsNumber",
"isDescending": "true",
"minimumCount": 0,
"ranges": [
{
"to": "100"
},
{
"from": "100",
"to": "1000"
},
{
"from": "1000"
}
]
}
}
]
}
]
}
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.type": "#microsoft.graph.searchResponse",
"hitsContainers": [
{
"@odata.type": "#microsoft.graph.searchHitsContainer",
"hits": [
"..."
],
"total": 9,
"moreResultsAvailable": false,
"aggregations": [
{
"@odata.type": "#microsoft.substrateSearch.searchAggregation",
"field": "Size",
"buckets": [
{
"@odata.type": "#microsoft.substrateSearch.searchBucket",
"key": "Less than 100",
"count": 0,
"aggregationFilterToken": "range(min, 100)"
},
{
"@odata.type": "#microsoft.substrateSearch.searchBucket",
"key": "100 up to 1000",
"count": 0,
"aggregationFilterToken": "range(100, 1000)"
},
{
"@odata.type": "#microsoft.substrateSearch.searchBucket",
"key": "1000 and up",
"count": 9,
"aggregationFilterToken": "range(1000, max, to=\"le\")"
}
]
}
]
}
]
}
仅 SharePoint、OneDrive 或外部项支持聚合。 消息或事件类型不支持它们。
培训
模块
将更多数据引入 Microsoft 搜索 - Training
了解 Microsoft Graph 和联合连接器可以如何帮助你将组织的更多数据引入 Microsoft 搜索。 使用自定义垂直搜索、结果群集和其他自定义项来增强用户的搜索体验。