Last active
February 3, 2019 16:57
-
-
Save jamesmundy/a8eb03fd37edef36923c08c0f21b81c8 to your computer and use it in GitHub Desktop.
My service for searching my Azure Search Index
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 class AzureSearchService : ISearchService | |
{ | |
private readonly SearchIndexClient _boatSearchClient; | |
public AzureSearchService() | |
{ | |
_boatSearchClient = new SearchIndexClient(ConfigurationsUtils.Configuration["SearchServiceName"], | |
ConfigurationsUtils.Configuration["SearchBoatsIndex"], | |
new SearchCredentials(ConfigurationsUtils.Configuration["SearchServiceQueryApiKey"])); | |
} | |
public async Task<List<int>> SearchBoatsAsync(string searchTerm, int skip = 0) | |
{ | |
var results = await _boatSearchClient.Documents.SearchAsync<SearchResponse>($"{searchTerm}*", | |
new SearchParameters() | |
{ | |
Skip = skip | |
}); | |
return results.Results.Select(x => Convert.ToInt32(x.Document.Id)).ToList(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment