Skip to content

Instantly share code, notes, and snippets.

@jamesmundy
Last active February 3, 2019 16:57
Show Gist options
  • Save jamesmundy/e2c83a698cfc5444ed022ad71638c97b to your computer and use it in GitHub Desktop.
Save jamesmundy/e2c83a698cfc5444ed022ad71638c97b to your computer and use it in GitHub Desktop.
My code to search Azure Search and the records I then get from the database
public Task<PagedList<BoatDto>> Find(BoatCriteria criteria)
{
return Adapter.Connect()
.CallAsync(async provider =>
{
var results = await _searchService.SearchBoatsAsync(criteria.Filter,
criteria.PageSize * criteria.PageNumber);
var unorderedResults = await provider.Boats()
.Where(b => results.Contains(b.Id))
.Select(BoatMappings.Select())
.OrderBy(x => x.Name)
.ToPagedListAsync(c => c, criteria);
var orderedResults = unorderedResults.Items.OrderBy(b => results.IndexOf(b.Id))
.ToList();
return orderedResults;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment