public ActionResult AdvancedSearchGetPagePositionInAllResultPages(int hitResultTotalStart, int compositionsPerPage,
                                                                          CorpusListLookupAdvancedSearchParams searchParams)
        {
            var bookId = 0L;

            var compositionListStart       = 0;
            var currentResultsUpToThisBook = 0L;

            long LoadCompositionPage()
            {
                while (true)
                {
                    var query = new CorpusListGetPageContractAdvanced
                    {
                        Start               = compositionListStart,
                        Count               = compositionsPerPage,
                        SortBooksBy         = searchParams.SortBooksBy,
                        SortDirection       = searchParams.SortDirection,
                        Json                = searchParams.Json,
                        SelectedBookIds     = searchParams.SelectedBookIds,
                        SelectedCategoryIds = searchParams.SelectedCategoryIds
                    };
                    var numberOfResultsArray     = AdvancedSearchGetResultSnapshotListPageOfIdsWithResultNumbers(query);
                    var compositionResultNumbers = numberOfResultsArray.SnapshotList;
                    foreach (var composition in compositionResultNumbers)
                    {
                        currentResultsUpToThisBook += composition.ResultCount;
                        if (hitResultTotalStart >= currentResultsUpToThisBook)
                        {
                            continue;
                        }
                        bookId = composition.SnapshotId;
                        return(currentResultsUpToThisBook - composition.ResultCount);
                    }

                    compositionListStart += compositionsPerPage;
                }
            }

            var resultsUpToThisCompositionStart = LoadCompositionPage();

            return(Json(new
            {
                compositionListStart = compositionListStart,
                bookId = bookId,
                hitResultStart = (hitResultTotalStart - resultsUpToThisCompositionStart)
            }));
        }
        public CorpusSearchSnapshotsResultContract AdvancedSearchGetResultSnapshotListPageOfIdsWithResultNumbers(
            [FromBody] CorpusListGetPageContractAdvanced searchQuery)
        {
            var json                        = searchQuery.Json;
            var selectedBookIds             = searchQuery.SelectedBookIds;
            var selectedCategoryIds         = searchQuery.SelectedCategoryIds;
            var listSearchCriteriaContracts = CreateTextCriteriaListFromJson(json, selectedBookIds, selectedCategoryIds);

            var sortBooksBy   = searchQuery.SortBooksBy;
            var sortDirection = searchQuery.SortDirection;
            var start         = searchQuery.Start;
            var count         = searchQuery.Count;

            return(GetCorpusSearchResultSnapshotList(new BookPagedCorpusSearchRequestContract
            {
                Start = start,
                Count = count,
                ConditionConjunction = listSearchCriteriaContracts,
                Sort = sortBooksBy,
                SortDirection = sortDirection,
                FetchNumberOfResults = true
            }));
        }
        public ActionResult AdvancedSearchGetResultSnapshotListPageOfIdsWithoutResultNumbers([FromBody] CorpusListGetPageContractAdvanced searchQuery)
        {
            var json                = searchQuery.Json;
            var selectedBookIds     = searchQuery.SelectedBookIds;
            var selectedCategoryIds = searchQuery.SelectedCategoryIds;
            List <SearchCriteriaContract> listSearchCriteriaContracts;

            var sortBooksBy   = searchQuery.SortBooksBy;
            var sortDirection = searchQuery.SortDirection;
            var start         = searchQuery.Start;
            var count         = searchQuery.Count;

            try
            {
                listSearchCriteriaContracts = CreateTextCriteriaListFromJson(json, selectedBookIds, selectedCategoryIds);
            }
            catch (ArgumentException exception)
            {
                return(BadRequest(exception.Message));
            }

            return(Json(GetCorpusSearchResultSnapshotList(new BookPagedCorpusSearchRequestContract
            {
                Start = start,
                Count = count,
                ConditionConjunction = listSearchCriteriaContracts,
                Sort = sortBooksBy,
                SortDirection = sortDirection
            })));
        }