@@ -252,11 +252,10 @@ export default defineComponent({
252252 providerResultLimit: 5 ,
253253 dateFilter: { id: ' date' , type: ' date' , text: ' ' , startFrom: null , endAt: null },
254254 personFilter: { id: ' person' , type: ' person' , name: ' ' },
255- dateFilterIsApplied: false ,
256- personFilterIsApplied: false ,
257255 filteredProviders: [],
258256 searching: false ,
259257 searchQuery: ' ' ,
258+ lastSearchQuery: ' ' ,
260259 placessearchTerm: ' ' ,
261260 dateTimeFilter: null ,
262261 filters: [],
@@ -369,10 +368,16 @@ export default defineComponent({
369368 return
370369 }
371370
371+ // Reset the provider result limit when performing a new search
372+ if (query !== this .lastSearchQuery ) {
373+ this .providerResultLimit = 5
374+ }
375+ this .lastSearchQuery = query
376+
372377 this .searching = true
373378 const newResults = []
374379 const providersToSearch = this .filteredProviders .length > 0 ? this .filteredProviders : this .providers
375- const searchProvider = (provider , filters ) => {
380+ const searchProvider = (provider ) => {
376381 const params = {
377382 type: provider .searchFrom ?? provider .id ,
378383 query ,
@@ -382,18 +387,25 @@ export default defineComponent({
382387
383388 // This block of filter checks should be dynamic somehow and should be handled in
384389 // nextcloud/search lib
385- if (filters .dateFilterIsApplied ) {
386- if (provider .filters ?.since && provider .filters ?.until ) {
387- params .since = this .dateFilter .startFrom
388- params .until = this .dateFilter .endAt
389- }
390- }
390+ const activeFilters = this .filters .filter (filter => {
391+ return filter .type !== ' provider' && this .providerIsCompatibleWithFilters (provider , [filter .type ])
392+ })
391393
392- if (filters .personFilterIsApplied ) {
393- if (provider .filters ?.person ) {
394- params .person = this .personFilter .user
394+ activeFilters .forEach (filter => {
395+ switch (filter .type ) {
396+ case ' date' :
397+ if (provider .filters ?.since && provider .filters ?.until ) {
398+ params .since = this .dateFilter .startFrom
399+ params .until = this .dateFilter .endAt
400+ }
401+ break
402+ case ' person' :
403+ if (provider .filters ?.person ) {
404+ params .person = this .personFilter .user
405+ }
406+ break
395407 }
396- }
408+ })
397409
398410 if (this .providerResultLimit > 5 ) {
399411 params .limit = this .providerResultLimit
@@ -404,12 +416,7 @@ export default defineComponent({
404416
405417 request ().then ((response ) => {
406418 newResults .push ({
407- id: provider .id ,
408- appId: provider .appId ,
409- searchFrom: provider .searchFrom ,
410- icon: provider .icon ,
411- name: provider .name ,
412- inAppSearch: provider .inAppSearch ,
419+ ... provider ,
413420 results: response .data .ocs .data .entries ,
414421 })
415422
@@ -419,12 +426,8 @@ export default defineComponent({
419426 this .searching = false
420427 })
421428 }
422- providersToSearch .forEach (provider => {
423- const dateFilterIsApplied = this .dateFilterIsApplied
424- const personFilterIsApplied = this .personFilterIsApplied
425- searchProvider (provider , { dateFilterIsApplied , personFilterIsApplied })
426- })
427429
430+ providersToSearch .forEach (searchProvider )
428431 },
429432 updateResults(newResults ) {
430433 let updatedResults = [... this .results ]
@@ -482,7 +485,7 @@ export default defineComponent({
482485 })
483486 },
484487 applyPersonFilter(person ) {
485- this . personFilterIsApplied = true
488+
486489 const existingPersonFilter = this .filters .findIndex (filter => filter .id === person .id )
487490 if (existingPersonFilter === - 1 ) {
488491 this .personFilter .id = person .id
@@ -504,15 +507,15 @@ export default defineComponent({
504507 },
505508 async loadMoreResultsForProvider(provider ) {
506509 this .providerResultLimit += 5
507- // If load more result for filter, remove other filters
508- this .filters = this .filters .filter (filter => filter .id === provider .id )
510+ // Remove all other providers from filteredProviders except the current "loadmore" provider
509511 this .filteredProviders = this .filteredProviders .filter (filteredProvider => filteredProvider .id === provider .id )
510512 // Plugin filters may have extra parameters, so we need to keep them
511513 // See method handlePluginFilter for more details
512514 if (this .filteredProviders .length > 0 && this .filteredProviders [0 ].isPluginFilter ) {
513515 provider = this .filteredProviders [0 ]
514516 }
515517 this .addProviderFilter (provider , true )
518+ this .find (this .searchQuery )
516519 },
517520 addProviderFilter(providerFilter , loadMoreResultsForProvider = false ) {
518521 unifiedSearchLogger .debug (' Applying provider filter' , { providerFilter , loadMoreResultsForProvider })
@@ -556,14 +559,10 @@ export default defineComponent({
556559 unifiedSearchLogger .debug (' Search filters (recently removed)' , { filters: this .filters })
557560
558561 } else {
562+ // Remove non provider filters such as date and person filters
559563 for (let i = 0 ; i < this .filters .length ; i ++ ) {
560- // Remove date and person filter
561- if (this .filters [i ].id === ' date' || this .filters [i ].id === filter .id ) {
562- this .dateFilterIsApplied = false
564+ if (this .filters [i ].id === filter .id ) {
563565 this .filters .splice (i , 1 )
564- if (filter .type === ' person' ) {
565- this .personFilterIsApplied = false
566- }
567566 this .enableAllProviders ()
568567 break
569568 }
@@ -602,7 +601,7 @@ export default defineComponent({
602601 } else {
603602 this .filters .push (this .dateFilter )
604603 }
605- this . dateFilterIsApplied = true
604+
606605 this .providers .forEach (async (provider , index ) => {
607606 this .providers [index ].disabled = ! (await this .providerIsCompatibleWithFilters (provider , [' since' , ' until' ]))
608607 })
0 commit comments