Skip to content

Commit

Permalink
Fix: Search does not find all files (#7267)
Browse files Browse the repository at this point in the history
Show max results in search
  • Loading branch information
Jan authored Jul 20, 2022
1 parent 5607bd3 commit 24314e4
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 30 deletions.
44 changes: 39 additions & 5 deletions packages/web-app-files/src/components/Search/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@
</template>
<template #footer>
<pagination :pages="paginationPages" :current-page="paginationPage" />
<div
v-if="searchResultExceedsLimit"
class="oc-text-nowrap oc-text-center oc-width-1-1 oc-my-s"
v-text="searchResultExceedsLimitText"
/>
<list-info
v-if="paginatedResources.length > 0"
v-else-if="paginatedResources.length > 0"
class="oc-width-1-1 oc-my-s"
:files="totalFilesCount.files"
:folders="totalFilesCount.folders"
Expand Down Expand Up @@ -57,6 +62,7 @@ import Pagination from '../FilesList/Pagination.vue'
import MixinFileActions from '../../mixins/fileActions'
import MixinFilesListFilter from '../../mixins/filesListFilter'
import MixinFilesListScrolling from '../../mixins/filesListScrolling'
import { searchLimit } from '../../search/sdk/list'
import { Resource } from '../../helpers/resource'
import { useStore } from 'web-pkg/src/composables'
Expand All @@ -67,9 +73,9 @@ export default defineComponent({
mixins: [MixinFileActions, MixinFilesListFilter, MixinFilesListScrolling],
props: {
searchResults: {
type: Array,
type: Object,
default: function () {
return []
return { range: 0, resources: [] }
}
}
},
Expand All @@ -88,6 +94,34 @@ export default defineComponent({
...mapGetters('Files', ['totalFilesCount', 'totalFilesSize']),
displayThumbnails() {
return !this.configuration?.options?.disablePreviews
},
itemCount() {
return this.totalFilesCount.files + this.totalFilesCount.folders
},
rangeSupported() {
return this.searchResults.range
},
rangeItems() {
return this.searchResults.range?.split('/')[1]
},
searchResultExceedsLimit() {
return !this.rangeSupported || (this.rangeItems && this.rangeItems > searchLimit)
},
searchResultExceedsLimitText() {
if (!this.rangeSupported) {
const translated = this.$gettext('Showing up to %{searchLimit} results')
return this.$gettextInterpolate(translated, {
searchLimit
})
}
const translated = this.$gettext(
'Found %{rangeItems}, showing the %{itemCount} best matching results'
)
return this.$gettextInterpolate(translated, {
itemCount: this.itemCount,
rangeItems: this.rangeItems
})
}
},
watch: {
Expand All @@ -96,8 +130,8 @@ export default defineComponent({
this.CLEAR_CURRENT_FILES_LIST()
this.LOAD_FILES({
currentFolder: null,
files: this.searchResults.length
? this.searchResults.map((searchResult) => searchResult.data)
files: this.searchResults.resources.length
? this.searchResults.resources.map((searchResult) => searchResult.data)
: []
})
},
Expand Down
29 changes: 17 additions & 12 deletions packages/web-app-files/src/search/sdk/list.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
import { SearchList, SearchResult } from 'search/src/types'
import { SearchList } from 'search/src/types'
import ListComponent from '../../components/Search/List.vue'
import { clientService } from 'web-pkg/src/services'
import { buildResource } from '../../helpers/resources'
import { Component } from 'vue'
import { DavProperties } from 'web-pkg/src/constants'

export const searchLimit = 200

export default class List implements SearchList {
public readonly component: Component

constructor() {
this.component = ListComponent
}

async search(term: string): Promise<SearchResult[]> {
async search(term: string): Promise<any> {
if (!term) {
return []
}

const plainResources = await clientService.owncloudSdk.files.search(
const searchResponse = await clientService.owncloudSdk.files.search(
term,
undefined,
searchLimit,
DavProperties.Default
)

return plainResources.map((plainResource) => {
let resourceName = decodeURIComponent(plainResource.name)
if (resourceName.startsWith('/dav')) {
resourceName = resourceName.slice(4)
}
return {
range: searchResponse.range,
resources: searchResponse.results.map((plainResource) => {
let resourceName = decodeURIComponent(plainResource.name)
if (resourceName.startsWith('/dav')) {
resourceName = resourceName.slice(4)
}

const resource = buildResource({ ...plainResource, name: resourceName })
return { id: resource.id, data: resource }
})
const resource = buildResource({ ...plainResource, name: resourceName })
return { id: resource.id, data: resource }
})
}
}
}
3 changes: 1 addition & 2 deletions packages/web-app-files/src/search/sdk/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export default class Preview implements SearchPreview {
5, // todo: add configuration option, other places need that too... needs consolidation
DavProperties.Default
)

const resources = plainResources.reduce((acc, plainResource) => {
const resources = plainResources.results.reduce((acc, plainResource) => {
let resourceName = decodeURIComponent(plainResource.name)
if (resourceName.startsWith('/dav')) {
resourceName = resourceName.slice(4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ function getWrapper(searchTerm = '', files = []) {
return mount(List, {
localVue,
propsData: {
searchResults: getSearchResults(files)
searchResults: {
range: 'rows 0-100/100',
resources: getSearchResults(files)
}
},
store: createStore(files),
router: new VueRouter(),
Expand Down
8 changes: 4 additions & 4 deletions packages/web-app-files/tests/unit/search/sdk.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('SDKProvider', () => {
const noTerm = await search.previewSearch.search('')
expect(noTerm).toBeFalsy()

searchMock.mockReturnValueOnce(files)
searchMock.mockReturnValueOnce({ results: files })
const withTerm = await search.previewSearch.search('foo')
expect(withTerm.map((r) => r.data)).toMatchObject(files)

Expand All @@ -119,9 +119,9 @@ describe('SDKProvider', () => {
{ id: 'baz', name: 'baz' }
]

searchMock.mockReturnValueOnce(files)
const withTerm = await search.listSearch.search('foo')
expect(withTerm.map((r) => r.data)).toMatchObject(files)
searchMock.mockReturnValueOnce({ results: files })
const withTerm = (await search.listSearch.search('foo')) as any
expect(withTerm.resources.map((r) => r.data)).toMatchObject(files)
})
})
})
2 changes: 1 addition & 1 deletion packages/web-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"marked": "^4.0.12",
"oidc-client-ts": "^2.0.5",
"owncloud-design-system": "14.0.0-alpha.5",
"owncloud-sdk": "~3.0.0-alpha.14",
"owncloud-sdk": "~3.0.0-alpha.15",
"p-queue": "^6.6.2",
"popper-max-size-modifier": "^0.2.0",
"portal-vue": "^2.1.7",
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9734,9 +9734,9 @@ __metadata:
languageName: node
linkType: hard

"owncloud-sdk@npm:~3.0.0-alpha.14":
version: 3.0.0-alpha.14
resolution: "owncloud-sdk@npm:3.0.0-alpha.14"
"owncloud-sdk@npm:~3.0.0-alpha.15":
version: 3.0.0-alpha.15
resolution: "owncloud-sdk@npm:3.0.0-alpha.15"
peerDependencies:
axios: ^0.27.2
cross-fetch: ^3.0.6
Expand All @@ -9749,7 +9749,7 @@ __metadata:
dependenciesMeta:
"@pact-foundation/pact":
built: true
checksum: 84a37f8fd9dc532963aae1c48f423b86ae5b384a6073515ffaa393e9061ce30f481211a6852b9d433241a911a9ccce092e6076dc74fc3fff154c8b1b8d3c8177
checksum: 3892508b42965f5602fb985173185ee9799d41d0e719895ad574d4b8b2b15326d69bc14300c1d84b14422e4acb3f4de101fdce2f36fc52658c0fa8b17b76c614
languageName: node
linkType: hard

Expand Down Expand Up @@ -13774,7 +13774,7 @@ __metadata:
marked: ^4.0.12
oidc-client-ts: ^2.0.5
owncloud-design-system: 14.0.0-alpha.5
owncloud-sdk: ~3.0.0-alpha.14
owncloud-sdk: ~3.0.0-alpha.15
p-queue: ^6.6.2
popper-max-size-modifier: ^0.2.0
portal-vue: ^2.1.7
Expand Down

0 comments on commit 24314e4

Please sign in to comment.