本部分将详细讨论搜索功能的细微差别和高级主题。
自定义同义词
Document AI Warehouse 提供了一项名为“自定义同义词”的功能,使客户能够为其特定网域提供自己的同义词。顾名思义,同义词是指在搜索过程中使用的相似字词。如果用户搜索“television”,则可以在用户不知情的情况下无缝添加以下同义词:“TV”“Video Monitor”“Video Screen”。系统将使用用户的原始搜索字词和同义词来执行搜索查询。
此功能有助于扩展用户的搜索范围并返回预期结果。典型用法包括公司或行业术语、首字母缩略词、行话和方言。
Synonym、Context 和 SynonymSet
Document AI Warehouse 引入了三个用于同义词自定义的主要术语:
Synonym。同义词表示一组含义相似的字词。Context。Context 表示一组用户(例如行业、部门或组织用户),这些用户具有其他组不使用的特定同义词。例如,财务部门和医疗保健部门可能使用完全不同的SynonymSet。可以在 Search API 的queryContext字段中指定上下文。因此,对相同的搜索查询字词使用不同的上下文可能会产生不同的搜索结果。SynonymSet。SynonymSet 是特定上下文的同义词集合。
{
"name": string,
"context": string,
"synonyms": [
{
object (Synonym)
}
]
}
用例示例
SynonymSet 及其上下文:“finance”
| "Currency","Foreign exchange","dollar","euro","yen" |
| "Inflation","CPI","economic expansion","economic boom","higher prices" |
| "IRS","Internal Revenue Service","US Treasury" |
| "Tax return","1040","1120","1099","W-2" |
在前面的示例中,当用户查询“Currency”且 queryContext 为“finance”时,该行中的其他同义词(即 Foreign exchange、dollar、euro、yen)会隐式添加到搜索查询中。同样,如果用户查询该行中的任何字词,所有其他字词都会添加到最终查询中。同样以上述示例为例,如果用户查询“欧元”,则“货币”“外汇”“美元”和“日元”都会添加到最终查询中。
SynonymSet 及其上下文:“healthcare”
| "provider","clinic","hospital","doctor","therapist","specialist" |
| "Medical claim","Claim","1500","Diagnosis","ICD-9","ICD9","ICD-10","ICD10","CPT","HCPCS" |
| "injury","trauma","hurt","wound","sore","bruise","cut","laceration","lesion","abrasion","contusion" |
使用自定义同义词扩展功能进行搜索
当客户想要使用自定义同义词扩展功能搜索文档时,他们需要指定一个或多个 query_context,您可以查看 SearchDocuments API 中的文档。
文件夹搜索
顾名思义,folder search 仅在特定文件夹及其子文件夹中搜索。
搜索请求示例如下所示:
{
document_query {
query: "songs";,
folderNameFilter: "projects/PROJECT_NUM/locations/LOCATION/documents/888"
}
}
直方图
直方图是一项高级功能,可汇总指定数据的计数。例如,每个架构中有多少文档与用户的查询匹配?对于与政府相关的数据库,如果用户搜索“Orange County”,数据架构直方图可能会返回与搜索条件匹配的驾照、结婚证或契约的数量。直方图会遵循请求用户的访问权限,因此只有请求用户有权访问的文档才会被统计。
直方图是一种强大的资源,但收集和汇总所有数据需要时间。
直方图不受搜索请求的分页字段影响。
常规直方图查询格式
HistogramQuery 的定义如下:
{
"histogramQuery": string,
"requirePreciseResultSize": boolean,
"filters": {
object (HistogramQueryPropertyNameFilter)
}
}
histogram_query 字段的格式为:COUNT('<item to count>')。此字段是重复字段,可让您拥有多个直方图查询。
require_precise_result_size 字段未实现。
filters 字段在“过滤条件”部分中进行了讨论。
文档架构直方图
您可以通过添加以下直方图查询来创建文档架构或文档类型直方图:
{
document_query {
query: "test"
},
histogram_queries: [
{
histogram_query: "count('DocumentSchemaId')"
}
]
}
例如,此查询的 HistogramQueryResult 中的映射如下所示:
histogramQueryResults: [
{
histogramQuery: "DocumentSchemaId",
histogram:
{
"projects/1234/locations/us-west/documentSchemas/5543": "22",
"projects/1234/locations/us-west/documentSchemas/5544": "2",
"projects/1234/locations/us-west/documentSchemas/5545": "4",
"projects/1234/locations/us-west/documentSchemas/5546": "122",
"projects/1234/locations/us-west/documentSchemas/5547": "256",
"projects/1234/locations/us-west/documentSchemas/5548": "1",
"projects/1234/locations/us-west/documentSchemas/5549": "5",
"projects/1234/locations/us-west/documentSchemas/5550": "15",
}
}
]
此示例显示有三个文档架构与给定的搜索查询匹配,并显示了每个文档架构的文档数量。
属性直方图
属性直方图会显示指定的可过滤属性的计数。属性直方图采用以下格式:
COUNT('SomeSchema.SomeProp')
// Also, you can try with:
COUNT('SomeSchema.ParentProp.SubProp')
请求示例如下:
histogramQueryResults: [
{
histogramQuery: "5678.text_prop",
histogram: {
some_text: "1",
More_text: "55",
Additional_text: "19"
}
}
]
此直方图会根据 HistogramQueryPropertyNameFilter 条件显示所有可过滤的属性直方图。这将返回属性使用次数(而非值数量)。
HistogramQueryPropertyNameFilter 的定义如下:
{
"documentSchemas": [
string
],
"propertyNames": [
string
],
"yAxis": enum (HistogramYAxis)
}
您可以通过填写名为 document_schemas 的可重复字段(最多 10 个 schema_ID 字段),将结果限制为一组文档架构。您可以选择使用可重复的 property_names 字段来减少汇总的属性。
y_axis 字段决定了如何统计属性。如果未设置或设置为 HISTOGRAM_YAXIS_DOCUMENT,则直方图功能仅统计唯一属性的使用情况。如果 y_axis 设置为 HISTOGRAM_YAXIS_PROPERTY,则直方图会统计所有属性的使用情况。例如:
文档 1: Payments_property: [AMEX, VISA]
文档 2: Payments_property: [MC]
`HISTOGRAM_YAXIS_DOCUMENT` would return:
Payments_property: 2
_Explanation_: The `Payments_property` is found in two documents
`HISTOGRAM_YAXIS_PROPERTY` would return:
Payments_property: 3
_Explanation_: The `Payments_property` has three values in the documents found
以下是一个简单的示例查询:
{
document_query {
},
histogram_queries: [
{
histogramQuery: "count('FilterableProperties')";
}
]
}
以下是上述查询的示例响应:
histogramQueryResults: [
{
histogramQuery: "FilterableProperties",
histogram: {
456.int_prop: "4",
456.text_prop: "26"
}
}
]
如需按架构过滤 count('FilterableProperties')) 结果,请参阅以下请求:
{
document_query: {
},
histogram_queries: [
{
histogram_query: "count('FilterableProperties')",
filters: {
document_schemas: [
"projects/1234/locations/us-west/documentSchemas/678",
"projects/1234/locations/us-west/documentSchemas/456"
]
}
}
]
}
如需过滤 count('FilterableProperties') 结果以查找特定属性,请参阅以下请求:
{
document_query: {
},
histogram_queries: [
{
histogram_query: "count('FilterableProperties')",
filters: {
property_names: [
"678.MORTAGE_TYPE",
"456.language_code"
]
}
}
]
}
如需查看 count("FilterableProperties") 的属性数量,请将 y_axis 更改为 HISTOGRAM_YAXIS_PROPERTY,如下所示:
{
document_query: {
},
histogram_queries: [
{
histogram_query: "count('FilterableProperties')",
filters: {
y_axis: "HISTOGRAM_YAXIS_PROPERTY"
}
}
]
}