

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 精选搜索结果
<a name="featured-results"></a>

**注意**  
功能支持因所用索引类型和搜索 API 而异。要查看您使用的索引类型和搜索 API 是否支持此功能，请参阅[索引类型](https://docs.aws.amazon.com/kendra/latest/dg/hiw-index-types.html)。

当您的用户发出某些查询时，您可以在搜索结果中突出显示特定文档。这有助于让用户更清楚地看到和突出显示结果。精选结果与通常的结果列表分开，并显示在搜索页面的顶部。您可以尝试为不同的查询提供不同的文档，或者确保某些文档获得应有的知名度。

您可以将特定查询映射到特定的文档，以便出现在结果中。如果查询包含完全匹配项，则搜索结果中会显示一个或多个特定文档。

例如，您可以指定，如果您的用户发布查询“2023 年新产品”，则选择标题为“最新动态”和“即将推出”的文档以显示在搜索结果页面的顶部。这有助于确保这些关于新产品的文档获得应有的知名度。

Amazon Kendra 如果搜索结果已被选中显示在搜索结果页面的顶部，则不会重复搜索结果。如果精选结果已经高于所有其他结果，则该结果不会再次被列为第一个结果。

为了显示某些结果，您必须使用查询中包含的关键字或短语来指定全文查询的精确匹配，而不是指定查询的部分匹配。例如，如果您仅在精选结果集中指定查询“Kendra”，则诸如“Kendra 在语义上如何对结果进行排名？”之类的查询 不会呈现精选结果。精选结果专为特定的查询而设计，而不是范围过于宽泛的查询。 Amazon Kendra 自然会处理关键字类型查询，以在搜索结果中对最有用的文档进行排名，从而避免根据简单关键字对结果进行过度精选。

如果您的用户经常使用某些查询，则可以为精选结果指定这些查询。例如，如果您使用 [Amazon Kendra Analytics](https://docs.aws.amazon.com/kendra/latest/dg/search-analytics.html) 查看热门查询，然后发现特定的查询，例如“kendra 在语义上如何对结果进行排名？” 和 “kendra 语义搜索” 经常被使用，那么这些查询对于指定标题为 “search 101” 的文档可能很有用。Amazon Kendra 

Amazon Kendra 将对精选结果的查询视为不区分大小写。 Amazon Kendra 将查询转换为小写，并将尾随的空格字符替换为单个空格。 Amazon Kendra 匹配所有其他字符，就像您为精选结果指定查询时一样。

您可以使用 [CreateFeaturedResultsSet](https://docs.aws.amazon.com/kendra/latest/APIReference/API_CreateFeaturedResultsSet.html)API 创建一组精选结果，将其映射到某些查询。如果您使用控制台，则可以选择您的索引，然后在导航菜单中选择**精选结果**来创建精选结果集。每个索引最多可以创建 50 组精选结果，每组最多可以创建 4 个精选文档，每个精选结果集最多可以创建 49 个查询文本。您可以联系 AWS [支持部门](https://aws.amazon.com/contact-us/)以提高这些限制。

您可以在多组精选结果中选择同一个文档。但是，不得在多个集合中使用相同的完全匹配查询文本。对于每个索引的每个精选结果集，您为精选结果指定的查询必须是唯一的。

在最多选择四个精选文档时，您可以排列文档的顺序。如果您使用 API，则列出精选文档的顺序与精选结果中显示的顺序相同。如果您使用控制台，则在选择要在结果中显示的文档时，只需拖放文档顺序即可。

配置精选结果时，仍然可以进行访问控制，即某些用户和群组可以访问某些文档，而其他用户和群组则不能。对于用户上下文筛选也是如此。例如，用户 A 属于“实习生”公司群组，该群组不应访问有关公司机密的文档。如果用户 A 输入包含公司机密文档的查询，则用户 A 不会在搜索结果中看到该文档。搜索结果页面上的任何其他结果也是如此。您还可以使用标签来控制对精选结果集的访问权限，该结果集是您可以控制访问权限的 Amazon Kendra 资源。

以下是创建一组精选结果的示例，其中查询“2023 年新产品”、“新产品上市”映射到标题为“最新动态”（doc-id-1）和“即将推出”（doc-id-2）的文档。

------
#### [ CLI ]

```
aws kendra create-featured-results-set \
 --featured-results-set-name 'New product docs to feature' \
 --description "Featuring What's new and Coming soon docs" \
 --index-id index-id \
 --query-texts 'new products 2023' 'new products available' \
 --featured-documents '{"Id":"doc-id-1", "Id":"doc-id-2"}'
```

------
#### [ Python ]

```
import boto3
from botocore.exceptions import ClientError
import pprint
import time

kendra = boto3.client("kendra")

print("Create a featured results set.")

# Provide a name for the featured results set
featured_results_name = "New product docs to feature"
# Provide an optional decription for the featured results set
description = "Featuring What's new and Coming soon docs"
# Provide the index ID for the featured results set
index = "index-id"
# Provide a list of query texts for the featured results set
queries = ['new products 2023', 'new products available']
# Provide a list of document IDs for the featured results set
featured_doc_ids = [{"Id":"doc-id-1"}, {"Id":"doc-id-2"}]

try:
    featured_results_set_response = kendra.create_featured_results_set(
        FeaturedResultsSetName = featured_results_name,
        Decription = description,
        Index = index,
        QueryTexts = queries,
        FeaturedDocuments = featured_doc_ids
    )

    pprint.pprint(featured_results_set_response)

    featured_results_set_id = featured_results_set_response["FeaturedResultsSetId"]

    while True:
        # Get the details of the featured results set, such as the status
        featured_results_set_description = kendra.describe_featured_results_set(
            Id = featured_results_set_id
        )
        status = featured_results_set_description["Status"]
        print(" Featured results set status: "+status)
            
except  ClientError as e:
        print("%s" % e)

print("Program ends.")
```

------