Created
May 21, 2023 12:59
-
-
Save AndyButland/024a7e389b26378271f330bc092cd1dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<bool> AddOrUpdatePackage(PackageDto packageDto) | |
{ | |
if (!IsSearchServiceConfigured()) | |
{ | |
_logger.LogWarning($"Package with Id {packageDto.PackageId} failed to index with Azure search as the search service is not configured."); | |
return false; | |
} | |
SearchIndexClient indexClient = GetIndexClient(); | |
await CreateIndexIfNotExists(indexClient); | |
SearchClient searchClient = indexClient.GetSearchClient(_searchSettings.IndexName); | |
var batch = IndexDocumentsBatch.Create(IndexDocumentsAction.MergeOrUpload(new PackageModel(packageDto))); | |
IndexDocumentsResult result = await searchClient.IndexDocumentsAsync(batch); | |
IndexingResult packageIndexResult = result.Results[0]; | |
if (packageIndexResult.Succeeded) | |
{ | |
_logger.LogInformation($"Package with Id {packageDto.PackageId} was indexed with Azure search."); | |
return true; | |
} | |
_logger.LogError($"Package with Id {packageDto.PackageId} failed to index with Azure search. Error message: {packageIndexResult.ErrorMessage}"); | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment