Skip to content

Commit

Permalink
fix(unified-search): Use appId for searching
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nfebe committed Jan 29, 2025
1 parent ef0d2ea commit b795c4d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions apps/files/src/plugins/search/folderSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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 },
Expand Down
10 changes: 8 additions & 2 deletions core/src/components/UnifiedSearch/UnifiedSearchModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -397,13 +397,15 @@ export default defineComponent({

if (this.providerResultLimit > 5) {
params.limit = this.providerResultLimit
unifiedSearchLogger.debug('Limiting search to', params.limit)
}

const request = unifiedSearch(params).request

request().then((response) => {
newResults.push({
id: provider.id,
appId: provider.appId,
provider: provider.name,
inAppSearch: provider.inAppSearch,
results: response.data.ocs.data.entries,
Expand Down Expand Up @@ -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()
Expand All @@ -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',
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b795c4d

Please sign in to comment.