Skip to content

Instantly share code, notes, and snippets.

@jamesmundy
Last active February 3, 2019 16:57
Show Gist options
  • Save jamesmundy/a8eb03fd37edef36923c08c0f21b81c8 to your computer and use it in GitHub Desktop.
Save jamesmundy/a8eb03fd37edef36923c08c0f21b81c8 to your computer and use it in GitHub Desktop.
My service for searching my Azure Search Index
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