none
Including total count on Mobile App server query RRS feed

  • Question

  • I'm using Azure Search on my C# Mobile App server in my table controller.  I know the total count of the query, so how would I include the total in the response (to avoid doing another call on the client with Take(0))?  My response currently looks like the following:

    return filteredData?.Results.Select(x => x.Document).AsQueryable()

    Thursday, May 23, 2019 3:15 PM

All replies

  • Just to clarify, are you leveraging Azure Mobile Apps service? Typically, this would filter for all the data - return filteredData?.Results.Select(x => x.Document).AsQueryable(), what specific total in response data are you looking for? Could you please provide more details on your scenario for better understanding?

    Friday, May 24, 2019 5:18 PM
    Moderator
  • Yes, I'm using an Azure Mobile App.  I need to include the total count of all results in the response as I'm using incremental loading on the client.
    Wednesday, June 5, 2019 12:27 AM
  • Thanks for the clarification. If you wish to get total number of documents in an index, you could set IncludeTotalResultCount to true in your search parameters. Once you do that and execute the query, you will see the count of total documents in an index in Count property of search results.
     
    Here's a sample code for that:
     
      var credentials = new SearchCredentials("account-key (query or admin key)");
            var indexClient = new SearchIndexClient("account-name", "index-name", credentials);
            var searchParameters = new SearchParameters()
            {
                QueryType = QueryType.Full,
                IncludeTotalResultCount = true
            };
            var searchResults = await indexClient.Documents.SearchAsync("*", searchParameters);
            Console.WriteLine("Total documents in index (approx) = " + searchResults.Count.GetValueOrDefault());//Prints the total number of documents in the index
    Friday, June 7, 2019 5:37 PM
    Moderator
  • I already know how to get the total count from Azure Search, but I need to include it in my response so that the client and server are sync with the total number of records for incremental loading.  Is the only way to do this by extending Queryable?
    Tuesday, June 11, 2019 12:53 PM
  • AFAIK, based on your scenario the optimum solution is by the way of extending Queryable.

    Thursday, June 13, 2019 6:37 PM
    Moderator