Examine query.Execute() isn't returning all search results

Hi all,

I’m building an examine query to search for descendants of a page, but I’m running into an issue where query.Execute() isn’t returning all the results (only 100 of 260).

Version: 13.7.2

ISearchResults does have a TotalItemCount property that has the correct count, but I can’t return all the items. Anyone know where I’m going wrong with this?

        public IEnumerable<T> GetDescendantsWithType<T>(IPublishedContent root, string sortField = null, SortType sortType = SortType.String, bool sortAscending = true)
            where T : IPublishedContent
        {
            if (_examineManager.TryGetIndex(UmbracoIndexes.ExternalIndexName, out IIndex index) == false)
            {
                throw new Exception($"Failed to find {UmbracoIndexes.ExternalIndexName}");
            }

            var type = typeof(T).Name.ToLower();

            var query = index.Searcher.CreateQuery("content").NodeTypeAlias(type);

            query.And().Field("path", root.Id.ToString());

            if (string.IsNullOrWhiteSpace(sortField) == false)
            {
                if (sortAscending == true)
                {
                    query.OrderBy(new SortableField(sortField, sortType));
                }
                else
                {
                    query.OrderByDescending(new SortableField(sortField, sortType));
                }
            }

			ISearchResults searchResults = query.Execute(); //100 results
            var testTotalItemCount = searchResults.TotalItemCount; //260 results
			return searchResults.GetResults<T>();
        }

Thanks

Execute has skip and take parameters I think. Just put a max int value in it for the take, that might help. By default, the number of results is capped, although I thought it was 500 and not 100.

Thanks @LuukPeters thats done the trick :raising_hands:

For anyone else who finds this query.Execute(new QueryOptions(0, 1000)); got this working

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.