/
entitysearch.go
49 lines (43 loc) · 1.84 KB
/
entitysearch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
package cognitiveservices
import (
"context"
"github.com/Azure-Samples/azure-sdk-for-go-samples/services/internal/config"
"github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v1.0/entitysearch"
"github.com/Azure/go-autorest/autorest"
)
func getEntitySearchClient(accountName string) entitysearch.EntitiesClient {
apiKey := getFirstKey(accountName)
entitySearchClient := entitysearch.NewEntitiesClient()
csAuthorizer := autorest.NewCognitiveServicesAuthorizer(apiKey)
entitySearchClient.Authorizer = csAuthorizer
_ = entitySearchClient.AddToUserAgent(config.UserAgent())
return entitySearchClient
}
//SearchEntities retunrs a list of entities
func SearchEntities(accountName string) (*entitysearch.Entities, error) {
entitySearchClient := getEntitySearchClient(accountName)
query := "tom cruise"
market := "en-us"
searchResponse, err := entitySearchClient.Search(
context.Background(), // context
query, // query keyword
"", // Accept-Language header
"", // pragma header
"", // User-Agent header
"", // X-MSEdge-ClientID header
"", // X-MSEdge-ClientIP header
"", // X-Search-Location header
"", // country code
market, // market
[]entitysearch.AnswerType{}, // response filter
[]entitysearch.ResponseFormat{}, // response format
entitysearch.Strict, // safe search
"", // set lang
)
if err != nil {
return nil, err
}
return searchResponse.Entities, nil
}