Skip to content

Graph client search query runs indefinitely #2870

@IllyaYushchenko

Description

@IllyaYushchenko

I'm using Graph client to search SharePoint Sites, and functionality worked good until a few days ago, when same query begun to run indefinitely.

It keeps "finding" same sites, and "MoreResultsAvailable" flag in response is always True. (And I'm relying on that flag to quit the loop).

I'll post code snippet below that worked perfectly before but couple days ago stopped working without any changes from my side.


          var siteResults = new List<Site>();
          var searching = true;
          int from = 0;

          while (searching)
          {
              // Create the search request object
              var searchRequest = new SearchRequest
              {
                  EntityTypes = new List<EntityType?> { EntityType.Site },
                  Query = new SearchQuery
                  {
                      QueryString = "description:\"{my description}""
                  },
                  SortProperties = new List<SortProperty>
                  {
                      new SortProperty { Name = "CreatedDateTime", IsDescending = true }
                  },
                  From = from,
                  Size = 500,
              };

              // Create the QueryPostRequestBody and pass the search request inside it
              var queryPostRequestBody = new QueryPostRequestBody
              {
                  Requests = new List<SearchRequest> { searchRequest }
              };

              // Use the `Query` property and pass the correct request body
              var searchResults = await Client.Search
                  .Query
                  .PostAsQueryPostResponseAsync(queryPostRequestBody);

              // Process the search results
              var siteHits = searchResults.Value.First().HitsContainers.First();
              var sites = siteHits.Hits
                  .Select(hit => hit.Resource as Site)
                  .Where(site => site.Description == {"my description"}); // Exact match filter
              siteResults.AddRange(sites);

              // Check if more results are available
              if (!siteHits.MoreResultsAvailable ?? false)
              {
                  searching = false;
              }

              from += 500;
          }

          return siteResults;

SDK versions 5.61.0 and 5.74.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions