本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
篩選和平面搜尋
您可以使用篩選器改善查詢 API 的搜尋結果或回應。篩選器會將回應中的文件限制為直接套用至查詢的文件。若要建立多面向搜尋建議,請使用布林邏輯從回應或不符合特定條件的文件中篩選出特定文件屬性。您可以使用 Query
API 中的Facets
參數來指定刻面。
若要搜尋已編製索引的文件 Amazon Lex, Amazon Kendra 請使用 AMAZON。 KendraSearchIntent。如需 Amazon Kendra
使用配置的範例 Amazon Lex,請參閱建立 Amazon Kendra 索引的常見問題集機器人。您也可以使用提供回應的篩選器AttributeFilter。這是配置時 JSON 中的查詢過濾器AMAZON.KendraSearchIntent
。若要在主控台中設定搜尋意圖時提供屬性篩選器,請前往意圖編輯器,然後選擇 Amazon Kendra
查詢以 JSON 提供查詢篩選器。如需相關資訊AMAZON.KendraSearchIntent
,請參閱Amazon Lex
文件指南。
面向
Facet 是一組搜尋結果的範圍檢視。例如,您可以為世界各地的城市提供搜尋結果,文件會根據與其關聯的特定城市進行篩選。或者,您可以建立刻面以顯示特定作者的結果。
您可以使用與文件相關聯的文件屬性或中繼資料欄位做為 Facet,以便您的使用者可以依該 Facet 中的類別或值進行搜尋。您還可以在搜索結果中顯示嵌套 Facet,以便您的用戶不僅可以按類別或字段進行搜索,還可以通過子類別或子字段進行搜索。
下列範例顯示如何取得「城市」自訂屬性的 Facet 資訊。
response=kendra.query( QueryText = query, IndexId = index, Facets = [ { "DocumentAttributeKey" : "City" } ] )
您可以使用巢狀刻面來進一步縮小搜尋範圍。例如,文件屬性或多面「城市」包含稱為「西雅圖」的值。此外,文件屬性或 Facet "CityRegion" 包括指派給「西雅圖」之文件的「北」與「南」值。您可以在搜尋結果中顯示巢狀 Facet 及其計數,以便不僅可以依城市搜尋文件,還可以依城市內的區域搜尋文件。
請注意,巢狀 Facet 可能會影響查詢延遲。一般規則是您使用的巢狀 Facet 越多,對延遲的潛在影響就越大。影響延遲的其他因素包括索引文件的平均大小、索引的大小、高度複雜的查詢,以及索 Amazon Kendra 引的整體負載。
下列範例顯示如何取得 "CityRegion" 自訂屬性的 Facet 資訊,做為「City」內的巢狀 Facet。
response=kendra.query( QueryText = query, IndexId = index, Facets = [ { "DocumentAttributeKey" : "City", "Facets": [ { "DocumentAttributeKey" : "CityRegion" } ] } ] )
Facet 資訊 (例如文件計數) 會在回FacetResults
應陣列中傳回。您可以使用內容在應用程式中顯示多面搜尋建議。例如,如果文件屬性「City」包含可套用搜尋的城市,請使用該資訊來顯示城市搜尋清單。用戶可以選擇一個城市來過濾他們的搜索結果。若要進行多面搜尋,請呼叫 Query API,並使用選擇的文件屬性來篩選結果。
查詢的每個 Facet 最多可以顯示 10 個 Facet 值,而一個多面內只能顯示一個巢狀 Facet。如果您想要提高這些限制,請聯絡 Sup portFacet
下列範例 JSON 回應顯示範圍為「城市」文件屬性的方面。回應包括 Facet 值的文件計數。
{ 'FacetResults': [ { 'DocumentAttributeKey': 'City', 'DocumentAttributeValueCountPairs': [ { 'Count': 3, 'DocumentAttributeValue': { 'StringValue': 'Dubai' } }, { 'Count': 3, 'DocumentAttributeValue': { 'StringValue': 'Seattle' } }, { 'Count': 1, 'DocumentAttributeValue': { 'StringValue': 'Paris' } } ] } ]
您也可以顯示巢狀 Facet (例如城市中的區域) 的刻面資訊,以進一步篩選搜尋結果。
下列範例 JSON 回應顯示範圍為 "CityRegion" 文件屬性的 Facet,做為「City」內的巢狀 Facet。回應包括巢狀 Facet 值的文件計數。
{ 'FacetResults': [ { 'DocumentAttributeKey': 'City', 'DocumentAttributeValueCountPairs': [ { 'Count': 3, 'DocumentAttributeValue': { 'StringValue': 'Dubai' }, 'FacetResults': [ { 'DocumentAttributeKey': 'CityRegion', 'DocumentAttributeValueCountPairs': [ { 'Count': 2, 'DocumentAttributeValue': { 'StringValue': 'Bur Dubai' } }, { 'Count': 1, 'DocumentAttributeValue': { 'StringValue': 'Deira' } } ] } ] }, { 'Count': 3, 'DocumentAttributeValue': { 'StringValue': 'Seattle' }, 'FacetResults': [ { 'DocumentAttributeKey': 'CityRegion', 'DocumentAttributeValueCountPairs': [ { 'Count': 1, 'DocumentAttributeValue': { 'StringValue': 'North' } }, { 'Count': 2, 'DocumentAttributeValue': { 'StringValue': 'South' } } ] } ] }, { 'Count': 1, 'DocumentAttributeValue': { 'StringValue': 'Paris' }, 'FacetResults': [ { 'DocumentAttributeKey': 'CityRegion', 'DocumentAttributeValueCountPairs': [ { 'Count': 1, 'DocumentAttributeValue': { 'StringValue': 'City center' } } ] } ] } } ] }
當您使用字串清單欄位建立 Facet 時,傳回的 Facet 結果會根據字串清單的內容而定。例如,如果您有一個包含兩個項目的字符串列表字段,其中一個包含「臘腸犬」,「香腸狗」列表和一個值為「赫斯基」,則可以獲得FacetResults
三個方面。
如需詳細資訊,請參閱 查詢回應和回應類型。
使用文件屬性篩選搜尋結果
依預設,Query
會傳回所有搜尋結果。若要篩選回應,您可以對文件屬性執行邏輯作業。例如,如果您只想要特定城市的文件,您可以篩選「城市」和「州/省」自訂文件屬性。您可AttributeFilter以使用在您提供的篩選器上建立布林運算。
大多數屬性都可用來篩選所有回應類型的回應。不過,此_excerpt_page_number
屬性只適用於篩選回應時的回ANSWER
應類型。
下列範例顯示如何透過篩選特定城市 (西雅圖) 和華盛頓州,來執行邏輯 AND 作業。
response=kendra.query( QueryText = query, IndexId = index, AttributeFilter = {'AndAllFilters': [ {"EqualsTo": {"Key": "City","Value": {"StringValue": "Seattle"}}}, {"EqualsTo": {"Key": "State","Value": {"StringValue": "Washington"}}} ] } )
下列範例會示範如何在任何Fileformat
、Author
或SourceURI
索引鍵符合指定值時執行邏輯 OR 作業。
response=kendra.query( QueryText = query, IndexId = index, AttributeFilter = {'OrAllFilters': [ {"EqualsTo": {"Key": "Fileformat","Value": {"StringValue": "AUTO_DETECT"}}}, {"EqualsTo": {"Key": "Author","Value": {"StringValue": "Ana Carolina"}}}, {"EqualsTo": {"Key": "SourceURI","Value": {"StringValue": "https://aws.amazonaws.com/234234242342"}}} ] } )
對於StringList
欄位,請使用ContainsAny
或ContainsAll
屬性篩選器來傳回具有指定字串的文件。下列範例顯示如何傳回其Locations
自訂屬性中具有「Seattle」或「Portland」值的所有文件。
response=kendra.query( QueryText = query, IndexId = index, AttributeFilter = { "ContainsAny": { "Key": "Locations", "Value": { "StringListValue": [ "Seattle", "Portland"] }} } )
篩選搜尋結果中每個文件的屬性
Amazon Kendra 會傳回搜尋結果中每個文件的文件屬性。您可以篩選要包含在回應中作為搜尋結果一部份的某些文件屬性。依預設,指派給文件的所有文件屬性都會在回應中傳回。
在下列範例中,只有_source_uri
和_author
文件屬性會包含在文件的回應中。
response=kendra.query( QueryText = query, IndexId = index, RequestedDocumentAttributes = ["_source_uri", "_author"] )