From f2678b122e58979094cd1944fa0091f80f12ceef Mon Sep 17 00:00:00 2001 From: nfebe Date: Sat, 11 Jan 2025 00:07:19 +0100 Subject: [PATCH] fix(unified-search): Use appId for searching Each provider may search from a particular app so we should use that for searching. Before this commit, we used `provider.id` instead of `provider.appId` the problem with the previous approach is that it forces the provider id to be a valid search provider (an app that supports search) limiting the developers ability to use unique IDs to identify the different providers (especially plugin providers) inside the places filter. For example the Files search plugin "In folder" (search in folder plugin) was required to have id as `files` while the files provider itself already has id as `files`. Signed-off-by: nfebe --- apps/files/src/plugins/search/folderSearch.ts | 5 +++-- .../components/UnifiedSearch/UnifiedSearchModal.vue | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/files/src/plugins/search/folderSearch.ts b/apps/files/src/plugins/search/folderSearch.ts index 2b29c7aec4d..4ba7e34a40e 100644 --- a/apps/files/src/plugins/search/folderSearch.ts +++ b/apps/files/src/plugins/search/folderSearch.ts @@ -21,7 +21,7 @@ function init() { logger.info('Initializing unified search plugin: folder search from files app') OCA.UnifiedSearch.registerFilterAction({ - id: 'files', + id: 'in-folder', appId: 'files', label: t('files', 'In folder'), icon: imagePath('files', 'app.svg'), @@ -35,7 +35,8 @@ function init() { logger.info('Folder picked', { folder: nodes[0] }) const folder = nodes[0] emit('nextcloud:unified-search:add-filter', { - id: 'files', + id: 'in-folder', + appId: 'files', payload: folder, filterUpdateText: t('files', 'Search in folder: {folder}', { folder: folder.basename }), filterParams: { path: folder.path }, diff --git a/core/src/components/UnifiedSearch/UnifiedSearchModal.vue b/core/src/components/UnifiedSearch/UnifiedSearchModal.vue index 09d3db52835..d75d54756ac 100644 --- a/core/src/components/UnifiedSearch/UnifiedSearchModal.vue +++ b/core/src/components/UnifiedSearch/UnifiedSearchModal.vue @@ -374,7 +374,7 @@ export default defineComponent({ const providersToSearch = this.filteredProviders.length > 0 ? this.filteredProviders : this.providers const searchProvider = (provider, filters) => { const params = { - type: provider.id, + type: provider.appId, query, cursor: null, extraQueries: provider.extraParams, @@ -397,6 +397,7 @@ export default defineComponent({ if (this.providerResultLimit > 5) { params.limit = this.providerResultLimit + unifiedSearchLogger.debug('Limiting search to', params.limit) } const request = unifiedSearch(params).request @@ -404,6 +405,7 @@ export default defineComponent({ request().then((response) => { newResults.push({ id: provider.id, + appId: provider.appId, provider: provider.name, inAppSearch: provider.inAppSearch, results: response.data.ocs.data.entries, @@ -500,11 +502,13 @@ export default defineComponent({ }, loadMoreResultsForProvider(providerId) { this.providerResultLimit += 5 - this.filters = this.filters.filter(filter => filter.type !== 'provider') + // If user wants more result for a particular filter remove other filters??? + this.filters = this.filters.filter(filter => filter.id === providerId) const provider = this.providers.find(provider => provider.id === providerId) this.addProviderFilter(provider, true) }, addProviderFilter(providerFilter, loadMoreResultsForProvider = false) { + unifiedSearchLogger.debug('Applying provider filter', { providerFilter, loadMoreResultsForProvider }) if (!providerFilter.id) return if (providerFilter.isPluginFilter) { providerFilter.callback() @@ -521,6 +525,7 @@ export default defineComponent({ } this.filteredProviders.push({ id: providerFilter.id, + appId: providerFilter.appId, name: providerFilter.name, icon: providerFilter.icon, type: providerFilter.type || 'provider', @@ -649,6 +654,7 @@ export default defineComponent({ this.updateDateFilter() }, handlePluginFilter(addFilterEvent) { + unifiedSearchLogger.debug('Handling plugin filter', { addFilterEvent }) for (let i = 0; i < this.filteredProviders.length; i++) { const provider = this.filteredProviders[i] if (provider.id === addFilterEvent.id) {