From 37d528c169e1514a0dbedc1c93403d7d8b62ed60 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Tue, 17 Oct 2023 11:46:24 +0200 Subject: [PATCH] MOBILE-3371 search: Remove top results They've been removed because they are not respecting category filters. In the LMS it's the expected behaviour because they use category tabs instead, but that is not correct in the app. --- .../classes/global-search-results-source.ts | 57 +------------------ .../features/search/services/global-search.ts | 39 ------------- 2 files changed, 1 insertion(+), 95 deletions(-) diff --git a/src/core/features/search/classes/global-search-results-source.ts b/src/core/features/search/classes/global-search-results-source.ts index 26caf6be3..dc3b9e76a 100644 --- a/src/core/features/search/classes/global-search-results-source.ts +++ b/src/core/features/search/classes/global-search-results-source.ts @@ -27,9 +27,6 @@ export class CoreSearchGlobalSearchResultsSource extends CorePaginatedItemsManag private query: string; private filters: CoreSearchGlobalSearchFilters; - private pagesLoaded = 0; - private totalResults?: number; - private topResultsIds?: number[]; constructor(query: string, filters: CoreSearchGlobalSearchFilters) { super(); @@ -87,65 +84,13 @@ export class CoreSearchGlobalSearchResultsSource extends CorePaginatedItemsManag this.setDirty(true); } - /** - * @inheritdoc - */ - getPagesLoaded(): number { - return this.pagesLoaded; - } - - /** - * Get total results with the given filter. - * - * @returns Total results. - */ - getTotalResults(): number | null { - return this.totalResults ?? null; - } - - /** - * @inheritdoc - */ - async reload(): Promise { - this.pagesLoaded = 0; - - await super.reload(); - } - - /** - * Reset collection data. - */ - reset(): void { - this.pagesLoaded = 0; - delete this.totalResults; - delete this.topResultsIds; - - super.reset(); - } - /** * @inheritdoc */ protected async loadPageItems(page: number): Promise<{ items: CoreSearchGlobalSearchResult[]; hasMoreItems: boolean }> { - this.pagesLoaded++; - - const results: CoreSearchGlobalSearchResult[] = []; - - if (page === 0) { - const topResults = await CoreSearchGlobalSearch.getTopResults(this.query, this.filters); - - results.push(...topResults); - - this.topResultsIds = topResults.map(result => result.id); - } - const pageResults = await CoreSearchGlobalSearch.getResults(this.query, this.filters, page); - this.totalResults = pageResults.total; - - results.push(...pageResults.results.filter(result => !this.topResultsIds?.includes(result.id))); - - return { items: results, hasMoreItems: pageResults.canLoadMore }; + return { items: pageResults.results, hasMoreItems: pageResults.canLoadMore }; } /** diff --git a/src/core/features/search/services/global-search.ts b/src/core/features/search/services/global-search.ts index 33f553ff7..9b89e16a8 100644 --- a/src/core/features/search/services/global-search.ts +++ b/src/core/features/search/services/global-search.ts @@ -144,30 +144,6 @@ export class CoreSearchGlobalSearchService { }; } - /** - * Get top results. - * - * @param query Search query. - * @param filters Search filters. - * @returns Top search results. - */ - async getTopResults(query: string, filters: CoreSearchGlobalSearchFilters): Promise { - if (this.filtersYieldEmptyResults(filters)) { - return []; - } - - const site = CoreSites.getRequiredCurrentSite(); - const params: CoreSearchGetTopResultsWSParams = { - query, - filters: await this.prepareAdvancedWSFilters(filters), - }; - const preSets = CoreSites.getReadingStrategyPreSets(CoreSitesReadingStrategy.PREFER_NETWORK); - - const { results } = await site.read('core_search_get_top_results', params, preSets); - - return await Promise.all((results ?? []).map(result => this.formatWSResult(result))); - } - /** * Get available search areas. * @@ -358,14 +334,6 @@ type CoreSearchViewResultsWSParams = { page?: number; // Results page number starting from 0, defaults to the first page. }; -/** - * Params of core_search_get_top_results WS. - */ -type CoreSearchGetTopResultsWSParams = { - query: string; // The search query. - filters?: CoreSearchAdvancedWSFilters; // Filters to apply. -}; - /** * Search result returned in WS. */ @@ -444,10 +412,3 @@ type CoreSearchViewResultsWSResponse = { status: boolean; // Status: true if success. warnings?: CoreWSExternalWarning[]; }; - -/** - * Data returned by core_search_get_top_results WS. - */ -type CoreSearchGetTopResultsWSResponse = { - results?: CoreSearchWSResult[]; -};