

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用建議和反白顯示相符查詢詞彙的能力來選擇路由
<a name="suggest-highlight-matched-query-terms"></a>

使用建議 API，您可以在使用者輸入位置或類別的搜尋查詢時，取得即時自動完成建議。結果會依相關性排名，最可能的相符項目會先出現。API 回應包含反白資訊，顯示每個建議如何符合使用者的查詢。

## 潛在的使用案例
<a name="suggest-disambiguate-results-potential-use"></a>

使用反白來向使用者顯示每個建議中的哪些部分符合他們的輸入，讓您更輕鬆地快速選取所需的結果。

## 範例
<a name="suggest-hightlight-results-examples"></a>

向使用者顯示結果清單時，回應中的**醒目提示**欄位可用來協助使用者識別輸入與結果的比對方式。在以下範例中，使用者會查詢「Effel tow」。這符合**標題**為 “Tour Eiffel (Eiffel Tower)” 的結果。使用醒目提示結果欄位，結果可以設計樣式以顯示輸入查詢與輸出的相符位置，導致向使用者顯示的文字為「Tour Eiffel (**Eiffel Tow** er)」。

### 使用建議 API 反白顯示查詢結果
<a name="suggest-hightlight-example"></a>

此範例示範如何使用建議 API 來查詢拼寫錯誤的興趣點。

------
#### [ Sample request ]

```
{
  "QueryText": "Effel tow",
  "Filter": {
    "Circle": {
      "Radius": 10000,
      "Center": [
        2.3431932014695382, 48.858844492141145
      ]
    },
    "IncludeCountries": [
      "FRA"
    ]
  },
  "AdditionalFeatures": [
    "Core"
  ]
}
```

------
#### [ Sample response ]

```
{
    "ResultItems": [
        {
            "Title": "Tour Eiffel (Eiffel Tower)",
            "SuggestResultItemType": "Place",
            "Place": {
                "PlaceId": "<Redacted>",
                "PlaceType": "PointOfInterest",
                "Address": {
                    "Label": "Tour Eiffel, * Avenue Anatole France, ***** Paris, France",
                    "Country": {
                        "Code2": "FR",
                        "Code3": "FRA",
                        "Name": "France"
                    },
                    "Region": {
                        "Code": "IDF",
                        "Name": "Île-de-France"
                    },
                    "SubRegion": {
                        "Name": "Paris"
                    },
                    "Locality": "Paris",
                    "District": "*e Arrondissement",
                    "PostalCode": "*****",
                    "Street": "Avenue Anatole France",
                    "StreetComponents": [
                        {
                            "BaseName": "Anatole France",
                            "Type": "Avenue",
                            "TypePlacement": "BeforeBaseName",
                            "TypeSeparator": " ",
                            "Language": "fr"
                        }
                    ],
                    "AddressNumber": "5"
                },
                "Position": [
                    2.2945,
                    48.85824
                ],
                "Distance": 3563,
                "Categories": [
                    {
                        "Id": "historical_monument",
                        "Name": "Historical Monument",
                        "LocalizedName": "Monument historique",
                        "Primary": true
                    },
                    {
                        "Id": "landmark-attraction",
                        "Name": "Landmark-Attraction",
                        "LocalizedName": "Lieu d'intérêt/Attraction",
                        "Primary": false
                    },
                    {
                        "Id": "tourist_attraction",
                        "Name": "Tourist Attraction",
                        "LocalizedName": "Attraction touristique",
                        "Primary": false
                    },
                    {
                        "Id": "sports_complex-stadium",
                        "Name": "Sports Complex-Stadium",
                        "LocalizedName": "Stade ou complexe sportif",
                        "Primary": false
                    }
                ]
            },
            "Highlights": {
                "Title": [
                    {
                        "StartIndex": 13,
                        "EndIndex": 23,
                        "Value": "Eiffel Tow"
                    }
                ],
                "Address": {}
            }
        }
    ],
    "QueryRefinements": []
}
```

------
#### [ cURL ]

```
curl --request POST \
  --url 'https://places.geo.eu-central-1.amazonaws.com/v2/suggest?key=Your_Key' \
  --header 'Content-Type: application/json' \
  --data '{
  "QueryText": "Effel tow",
  "Filter": {
    "Circle": {
      "Radius": 10000,
      "Center": [
        2.3431932014695382, 48.858844492141145
      ]
    },
    "IncludeCountries": [
      "FRA"
    ]
  },
  "AdditionalFeatures": [
    "Core"
  ]
}'
```

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

```
aws geo-places suggest --key ${YourKey} \
--query-text "Effel tow" \
--filter '{"Circle": {"Radius": 10000, "Center": [2.3431932014695382, 48.858844492141145]}, "IncludeCountries": ["FRA"]}' \
--additional-features "Core"
```

------

## 開發人員秘訣
<a name="suggest-highlight-developer-tips"></a>

使用`Title`回應欄位顯示搜尋結果，為使用者提供簡潔、可辨識的項目。對於看起來相似的結果，請使用 `Place.Address.Label` 欄位顯示其他地址詳細資訊，以協助使用者區分它們。如需詳細資訊，請參閱[如何協助使用者在類似結果之間模糊不清使用建議 API 來取消混淆結果](suggest-disambiguate-results.md)。