Skip to content

Commit 61393d5

Browse files
Merge pull request #70 from textkernel/match-v2-env
Better Match v2 environment handling
2 parents 3e6d534 + 488943b commit 61393d5

File tree

18 files changed

+131
-63
lines changed

18 files changed

+131
-63
lines changed

src/Textkernel.Tx.SDK.Examples/MatchV2/UploadAndSearchDocuments.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public async Task Run(TxClient client)
3131
TaxonomyVersion = "V2"
3232
},
3333
//method #1: index a document during the parse request
34-
IndexingOptions = new IndexingOptionsGeneric(Services.MatchV2Environment.PROD, "my-first-document")
34+
IndexingOptions = new IndexingOptionsGeneric("my-first-document")
3535
});
3636

3737
try

src/Textkernel.Tx.SDK.Examples/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ public static async Task Main(string[] args)
2222
SkillsIntelligenceIncludeCertifications = true
2323
});
2424

25-
//IExample example = new BasicParsing();
26-
IExample example = new UploadAndSearchDocuments();
25+
IExample example = new BasicParsing();
26+
//IExample example = new BatchParsing();
27+
//IExample example = new UploadAndSearchDocuments();
2728
await example.Run(client);
2829

2930
Console.ReadKey();

src/Textkernel.Tx.SDK.Tests/IntegrationTests/MatchV2Tests.cs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,31 @@
88
using Textkernel.Tx.Models.API.Matching;
99
using Textkernel.Tx.Models.Matching;
1010
using Textkernel.Tx.Models.API.MatchV2.Request;
11+
using Textkernel.Tx.Models.API.Parsing;
12+
using Textkernel.Tx.Models;
13+
using System.Collections;
1114

1215
namespace Textkernel.Tx.SDK.Tests.IntegrationTests
1316
{
1417
public class MatchV2Tests : TestBase
1518
{
16-
private const string _documentId = "unittestci";
19+
private readonly string _documentId = Guid.NewGuid().ToString();
1720

1821
[OneTimeSetUp]
1922
public async Task SetupAIMatchingIndexes()
2023
{
2124
// add a document to each index
2225
await Client.SearchMatchV2.AddJob(_documentId, TestParsedJobTech);
2326
await Client.SearchMatchV2.AddCandidate(_documentId, TestParsedResume);
24-
await DelayForIndexSync(10_000);
27+
await DelayForIndexSync(5_000);
2528
}
2629

2730
[OneTimeTearDown]
2831
public async Task TeardownMatchingIndexes()
2932
{
3033
await Client.SearchMatchV2.DeleteJobs([_documentId]);
3134
await Client.SearchMatchV2.DeleteCandidates([_documentId]);
32-
await DelayForIndexSync(10_000);
35+
await DelayForIndexSync(5_000);
3336
}
3437

3538
[TestCase("Developer")]
@@ -65,6 +68,44 @@ public async Task TestSearch(string validSearchTerm)
6568
await Task.CompletedTask;
6669
}
6770

71+
[Test]
72+
public async Task TestParseAndUpload()
73+
{
74+
Document document = GetTestFileAsDocument("resume.docx");
75+
string docId = Guid.NewGuid().ToString();
76+
var options = new ParseOptions()
77+
{
78+
ProfessionsSettings = new ProfessionsSettings()
79+
{
80+
Normalize = false
81+
},
82+
IndexingOptions = new Models.API.Indexes.IndexingOptionsGeneric()
83+
{
84+
SearchAndMatchVersion = Models.API.Indexes.SearchAndMatchVersion.V2,
85+
DocumentId = docId
86+
}
87+
};
88+
ParseResumeResponse response = await Client.Parser.ParseResume(new ParseRequest(document, options));
89+
90+
Assert.True(response.Value.IndexingResponse.IsSuccess);
91+
92+
await DelayForIndexSync(10_000);
93+
94+
Options opts = new Options();
95+
SearchQuery query = new SearchQuery();
96+
query.QueryString = "Developer";
97+
Assert.DoesNotThrow(() =>
98+
{
99+
var response = Client.SearchMatchV2.SearchCandidates(query, opts).Result.Value;
100+
Assert.IsNotEmpty(response.ResultItems);
101+
Assert.IsNotEmpty(response.ResultItems.Where(i => i.DocID == docId));
102+
});
103+
104+
await Client.SearchMatchV2.DeleteCandidates([docId]);
105+
106+
await DelayForIndexSync(5_000);
107+
}
108+
68109
//[Test]
69110
public async Task TestMatch()
70111
{

src/Textkernel.Tx.SDK/Models/API/Indexes/IndexDocumentRequest.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,10 @@ public IndexingOptionsGeneric(string documentId, string indexId, List<string> us
128128
/// <summary>
129129
/// Create options to upload a document with Match V2
130130
/// </summary>
131-
/// <param name="env">The target environment where the document will be uploaded</param>
132131
/// <param name="documentId">The id to assign to the new document. This is restricted to alphanumeric with dashes and underscores.</param>
133132
/// <param name="roles">The list of roles that are allowed to retrieve the document. If not set, <c>["all"]</c> will be used.</param>
134133
/// <param name="customFields">A key-value collection of custom fields.</param>
135134
public IndexingOptionsGeneric(
136-
MatchV2Environment env,
137135
string documentId,
138136
List<string> roles = null,
139137
Dictionary<string, string> customFields = null)
@@ -142,7 +140,6 @@ public IndexingOptionsGeneric(
142140
Roles = roles;
143141
CustomFields = customFields;
144142
DocumentId = documentId;
145-
SearchAndMatchEnvironment = env;
146143
}
147144

148145
/// <summary>
@@ -174,12 +171,12 @@ public IndexingOptionsGeneric(
174171
public List<string> UserDefinedTags { get; set; }
175172

176173
/// <summary>
177-
/// The target environment where the document will be uploaded
174+
/// The target environment where the document will be uploaded. This will be set from <see cref="EnvironmentSettings.MatchV2Environment"/> if needed.
178175
/// </summary>
179176
/// <remarks>
180-
/// Only use when <see cref="SearchAndMatchVersion"/> = <see cref="SearchAndMatchVersion.V2"/>
177+
/// Only used when <see cref="SearchAndMatchVersion"/> = <see cref="SearchAndMatchVersion.V2"/>
181178
/// </remarks>
182-
public MatchV2Environment SearchAndMatchEnvironment { get; set; }
179+
public MatchV2Environment SearchAndMatchEnvironment { get; internal set; }
183180

184181
/// <summary>
185182
/// The list of roles that are allowed to retrieve the document. If not set, <c>["all"]</c> will be used.

src/Textkernel.Tx.SDK/Clients/FormatterService.cs renamed to src/Textkernel.Tx.SDK/Services/FormatterService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ namespace Textkernel.Tx.Services
1818
/// </summary>
1919
internal class FormatterService : ServiceBase, IFormatterService
2020
{
21-
internal FormatterService(HttpClient httpClient) : base(httpClient) { }
21+
internal FormatterService(HttpClient httpClient, EnvironmentSettings settings)
22+
: base(httpClient, settings)
23+
{
24+
}
2225

2326
/// <inheritdoc />
2427
public async Task<FormatResumeResponse> FormatResume(FormatResumeRequest request)

src/Textkernel.Tx.SDK/Clients/GeocoderService.cs renamed to src/Textkernel.Tx.SDK/Services/GeocoderService.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Textkernel.Tx.Services
2323
/// </summary>
2424
internal class GeocoderService : ServiceBase, IGeocoderService
2525
{
26-
internal GeocoderService(HttpClient httpClient) : base(httpClient) { }
26+
internal GeocoderService(HttpClient httpClient, EnvironmentSettings settings) : base(httpClient, settings) { }
2727

2828
private async Task<GeocodeResumeResponse> InternalGeocode(ParsedResume resume, GeocodeCredentials geocodeCredentials, Address address = null)
2929
{
@@ -112,6 +112,8 @@ public async Task<GeocodeJobResponse> Geocode(ParsedJob job, Address address, Ge
112112

113113
private async Task<GeocodeAndIndexResumeResponse> InternalGeocodeAndIndex(ParsedResume resume, GeocodeCredentials geocodeCredentials, IndexingOptionsGeneric indexingOptions, bool indexIfGeocodeFails, Address address = null, GeoCoordinates coordinates = null)
114114
{
115+
SetEnvironment(indexingOptions);
116+
115117
GeocodeAndIndexResumeRequest requestBody = new GeocodeAndIndexResumeRequest
116118
{
117119
ResumeData = resume,
@@ -146,6 +148,8 @@ private async Task<GeocodeAndIndexResumeResponse> InternalGeocodeAndIndex(Parsed
146148

147149
private async Task<GeocodeAndIndexJobResponse> InternalGeocodeAndIndex(ParsedJob job, GeocodeCredentials geocodeCredentials, IndexingOptionsGeneric indexingOptions, bool indexIfGeocodeFails, Address address = null, GeoCoordinates coordinates = null)
148150
{
151+
SetEnvironment(indexingOptions);
152+
149153
GeocodeAndIndexJobRequest requestBody = new GeocodeAndIndexJobRequest
150154
{
151155
JobData = job,
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)