-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathPolymorphicObjectExample.cs
More file actions
76 lines (63 loc) · 2.77 KB
/
PolymorphicObjectExample.cs
File metadata and controls
76 lines (63 loc) · 2.77 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved.
* This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
*/
using System.Threading.Tasks;
using Oci.ResourcesearchService;
using Oci.ResourcesearchService.Models;
using Oci.ResourcesearchService.Requests;
using Oci.Common.Auth;
namespace Oci.Examples
{
/**
* This class demonstrates on Polymorphic objects.
* The SearchDetails can be of type either FreeText Search or StructuredQuery Search
*/
public class PolymorphicObjectExample
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public static async Task MainPolymorphicObject()
{
logger.Info("Starting example");
var provider = new ConfigFileAuthenticationDetailsProvider("DEFAULT");
var client = new ResourceSearchClient(provider);
logger.Info("Search for resource by freetext search");
await FreeTextSearch(client, "admin");
logger.Info("Search for resource by structed query search");
await StructuredQuerySearch(client, "query all resources");
logger.Info("End example");
}
private static async Task FreeTextSearch(ResourceSearchClient client, string text)
{
var searchResourcesRequest = new SearchResourcesRequest
{
SearchDetails = new FreeTextSearchDetails
{
Text = text,
MatchingContextType = SearchDetails.MatchingContextTypeEnum.Highlights
}
};
var searchResourcesResponse = await client.SearchResources(searchResourcesRequest);
foreach (var resource in searchResourcesResponse.ResourceSummaryCollection.Items)
{
logger.Info($"Resource: {resource.DisplayName}");
}
}
private static async Task StructuredQuerySearch(ResourceSearchClient client, string query)
{
var searchResourcesRequest = new SearchResourcesRequest
{
SearchDetails = new StructuredSearchDetails
{
MatchingContextType = SearchDetails.MatchingContextTypeEnum.Highlights,
Query = query
}
};
var searchResourcesResponse = await client.SearchResources(searchResourcesRequest);
foreach (var resource in searchResourcesResponse.ResourceSummaryCollection.Items)
{
logger.Info($"Resource: {resource.DisplayName}");
}
}
}
}