Merge pull request #3824 from NoelDeMartin/MOBILE-3371

MOBILE-3371 search: Remove top results
main
Dani Palou 2023-10-17 14:27:49 +02:00 committed by GitHub
commit 59a8a1c3d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 95 deletions

View File

@ -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<void> {
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 };
}
/**

View File

@ -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<CoreSearchGlobalSearchResult[]> {
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<CoreSearchGetTopResultsWSResponse>('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[];
};