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

Fix fuzzy fuse filter results #8863

Merged
merged 2 commits into from
Apr 19, 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
4 changes: 3 additions & 1 deletion changelog/unreleased/bugfix-remove-fuzzy-search-results
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ Bugfix: Remove fuzzy search results
We've had a bug that caused some search results to show up that didn't align with the search term.

https://github.com/owncloud/web/pull/8508
https://github.com/owncloud/web/issues/8493
https://github.com/owncloud/web/pull/8863
https://github.com/owncloud/web/issues/8493
https://github.com/owncloud/web/issues/8860
4 changes: 2 additions & 2 deletions packages/design-system/src/components/OcSelect/OcSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ export default defineComponent({
const fuse = new Fuse(items, {
...(props.label && { keys: [props.label] }),
shouldSort: true,
threshold: 0.1,
location: 0,
threshold: 0,
ignoreLocation: true,
distance: 100,
minMatchCharLength: 1
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ import { SideBarEventTopics } from 'web-pkg/src/composables/sideBar'
import { Group } from 'web-client/src/generated'
import ContextMenuQuickAction from 'web-pkg/src/components/ContextActions/ContextMenuQuickAction.vue'
import { useGettext } from 'vue3-gettext'
import { defaultFuseOptions } from 'web-pkg/src/helpers'

export default defineComponent({
name: 'GroupsList',
Expand Down Expand Up @@ -287,13 +288,7 @@ export default defineComponent({
if (!(filterTerm || '').trim()) {
return groups
}
const groupsSearchEngine = new Fuse(groups, {
includeScore: false,
useExtendedSearch: true,
threshold: 0.1,
keys: ['displayName']
})

const groupsSearchEngine = new Fuse(groups, { ...defaultFuseOptions, keys: ['displayName'] })
return groupsSearchEngine.search(filterTerm).map((r) => r.item)
},
orderBy(list, prop, desc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import MembersRoleSection from '../../Groups/SideBar/MembersRoleSection.vue'
import Fuse from 'fuse.js'
import Mark from 'mark.js'
import { Group } from 'web-client/src/generated'
import { defaultFuseOptions } from 'web-pkg/src/helpers'

export default defineComponent({
name: 'GroupsMembersPanel',
Expand All @@ -37,13 +38,7 @@ export default defineComponent({
return collection
}

const searchEngine = new Fuse(collection, {
includeScore: false,
useExtendedSearch: true,
threshold: 0.1,
keys: ['displayName']
})

const searchEngine = new Fuse(collection, { ...defaultFuseOptions, keys: ['displayName'] })
return searchEngine.search(term).map((r) => r.item)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import MembersRoleSection from './MembersRoleSection.vue'
import Fuse from 'fuse.js'
import Mark from 'mark.js'
import { spaceRoleEditor, spaceRoleManager, spaceRoleViewer } from 'web-client/src/helpers/share'
import { defaultFuseOptions } from 'web-pkg/src/helpers'

export default defineComponent({
name: 'MembersPanel',
Expand All @@ -57,13 +58,7 @@ export default defineComponent({
return collection
}

const searchEngine = new Fuse(collection, {
includeScore: false,
useExtendedSearch: true,
threshold: 0.1,
keys: ['displayName']
})

const searchEngine = new Fuse(collection, { ...defaultFuseOptions, keys: ['displayName'] })
return searchEngine.search(term).map((r) => r.item)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ import {
formatDateFromJSDate,
formatRelativeDateFromJSDate,
displayPositionedDropdown,
formatFileSize
formatFileSize,
defaultFuseOptions
} from 'web-pkg/src/helpers'
import { computed, defineComponent, nextTick, onMounted, PropType, ref, unref, watch } from 'vue'
import { SpaceResource } from 'web-client/src/helpers'
Expand Down Expand Up @@ -218,13 +219,7 @@ export default defineComponent({
if (!(filterTerm || '').trim()) {
return spaces
}
const searchEngine = new Fuse(spaces, {
includeScore: false,
useExtendedSearch: true,
threshold: 0.1,
keys: ['name']
})

const searchEngine = new Fuse(spaces, { ...defaultFuseOptions, keys: ['name'] })
return searchEngine.search(filterTerm).map((r) => r.item)
}
const isSpaceSelected = (space: SpaceResource) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
import { defineComponent, PropType, ref, unref, ComponentPublicInstance } from 'vue'
import Fuse from 'fuse.js'
import Mark from 'mark.js'
import { displayPositionedDropdown, eventBus } from 'web-pkg'
import { defaultFuseOptions, displayPositionedDropdown, eventBus } from 'web-pkg'
import { SideBarEventTopics } from 'web-pkg/src/composables/sideBar'
import { AppRole, User } from 'web-client/src/generated'
import ContextMenuQuickAction from 'web-pkg/src/components/ContextActions/ContextMenuQuickAction.vue'
Expand Down Expand Up @@ -311,9 +311,7 @@ export default defineComponent({
return users
}
const usersSearchEngine = new Fuse(users, {
includeScore: false,
useExtendedSearch: true,
threshold: 0.1,
...defaultFuseOptions,
keys: ['displayName', 'mail', 'onPremisesSamAccountName', 'role.displayName']
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`MembersPanel should display an empty result if no matching members found 1`] = `
<div class="oc-ml-s">
<oc-text-input-stub class="oc-text-truncate oc-mr-s oc-mt-m" clearbuttonaccessiblelabel="" clearbuttonenabled="false" disabled="false" fixmessageline="false" id="oc-textinput-3" label="Filter members" modelvalue="no-match" type="text"></oc-text-input-stub>
<oc-text-input-stub class="oc-text-truncate oc-mr-s oc-mt-m" clearbuttonaccessiblelabel="" clearbuttonenabled="false" disabled="false" fixmessageline="false" id="oc-textinput-3" label="Filter members" modelvalue="no-match" readonly="false" type="text"></oc-text-input-stub>
<div>
<div>
<h3 class="oc-text-bold oc-text-medium">No members found</h3>
Expand All @@ -14,7 +14,7 @@ exports[`MembersPanel should display an empty result if no matching members foun

exports[`MembersPanel should render all members accordingly to their role assignments 1`] = `
<div class="oc-ml-s">
<oc-text-input-stub class="oc-text-truncate oc-mr-s oc-mt-m" clearbuttonaccessiblelabel="" clearbuttonenabled="false" disabled="false" fixmessageline="false" id="oc-textinput-1" label="Filter members" modelvalue="" type="text"></oc-text-input-stub>
<oc-text-input-stub class="oc-text-truncate oc-mr-s oc-mt-m" clearbuttonaccessiblelabel="" clearbuttonenabled="false" disabled="false" fixmessageline="false" id="oc-textinput-1" label="Filter members" modelvalue="" readonly="false" type="text"></oc-text-input-stub>
<div>
<!--v-if-->
<div class="oc-mb-m">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import { ProjectSpaceResource } from 'web-client/src/helpers'
import { useClientService } from 'web-pkg/src/composables'
import Fuse from 'fuse.js'
import Mark from 'mark.js'
import { configurationManager } from 'web-pkg'
import { configurationManager, defaultFuseOptions } from 'web-pkg'

export default defineComponent({
name: 'SpaceMembers',
Expand Down Expand Up @@ -148,9 +148,7 @@ export default defineComponent({
return collection
}
const searchEngine = new Fuse(collection, {
includeScore: false,
useExtendedSearch: true,
threshold: 0.1,
...defaultFuseOptions,
keys: ['collaborator.displayName', 'collaborator.name']
})

Expand Down
5 changes: 2 additions & 3 deletions packages/web-app-files/src/helpers/resource/filter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import Fuse from 'fuse.js'
import { defaultFuseOptions } from 'web-pkg/src/helpers'

export const filterResources = (resources: unknown[], term: string, limit?: number): unknown[] => {
const engine = new Fuse(resources, {
includeScore: false,
useExtendedSearch: true,
threshold: 0.1,
...defaultFuseOptions,
keys: ['name', 'type', 'icon', 'extension', 'tags']
})

Expand Down
10 changes: 2 additions & 8 deletions packages/web-app-files/src/views/trash/Overview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import Mark from 'mark.js'
import Fuse from 'fuse.js'
import { useGettext } from 'vue3-gettext'
import { useTask } from 'vue-concurrency'
import { useClientService, useRouter, useStore } from 'web-pkg'
import { defaultFuseOptions, useClientService, useRouter, useStore } from 'web-pkg'
import { createLocationTrash } from 'web-app-files/src/router'
import { createFileRouteOptions } from 'web-pkg/src/helpers/router'
import AppBar from 'web-app-files/src/components/AppBar/AppBar.vue'
Expand Down Expand Up @@ -155,13 +155,7 @@ export default defineComponent({
if (!(filterTerm || '').trim()) {
return spaces
}
const searchEngine = new Fuse(spaces, {
includeScore: true,
useExtendedSearch: true,
threshold: 0.1,
keys: ['name']
})

const searchEngine = new Fuse(spaces, { ...defaultFuseOptions, keys: ['name'] })
return searchEngine.search(filterTerm).map((r) => r.item)
}

Expand Down
6 changes: 2 additions & 4 deletions packages/web-pkg/src/components/ItemFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import { defineComponent, nextTick, onMounted, ref, unref, watch } from 'vue'
import Fuse from 'fuse.js'
import Mark from 'mark.js'
import omit from 'lodash-es/omit'
import { useRoute, useRouteQuery, useRouter } from 'web-pkg'
import { defaultFuseOptions, useRoute, useRouteQuery, useRouter } from 'web-pkg'
import { queryItemAsString } from 'web-pkg/src/composables/appDefaults'

export default defineComponent({
Expand Down Expand Up @@ -164,9 +164,7 @@ export default defineComponent({
return items
}
const usersSearchEngine = new Fuse(items, {
includeScore: false,
useExtendedSearch: true,
threshold: 0.1,
...defaultFuseOptions,
keys: props.filterableAttributes as any
})

Expand Down
5 changes: 5 additions & 0 deletions packages/web-pkg/src/helpers/fuse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const defaultFuseOptions = {
ignoreLocation: true,
threshold: 0,
useExtendedSearch: true
}
1 change: 1 addition & 0 deletions packages/web-pkg/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from './contextMenuDropdown'
export * from './download'
export * from './datetime'
export * from './filesize'
export * from './fuse'
export * from './locale'