Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOBILE-3371 search: Remove top results #3824

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 1 addition & 56 deletions src/core/features/search/classes/global-search-results-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 };
}

/**
Expand Down
39 changes: 0 additions & 39 deletions src/core/features/search/services/global-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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[];
};
Loading