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

Allowing in-here search with empty query #10092

Merged
merged 4 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 29 additions & 24 deletions packages/web-app-files/src/components/Search/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -397,31 +397,36 @@ export default defineComponent({
query['mediatype'] = mediaTypeParams.split('+').map((t) => `"${t}"`)
updateFilter(mediaTypeFilter)
}
// By definition (KQL spec) OR, AND or (GROUP) is implicit for simple cases where
// different or identical keys are part of the query.
//
// We list these operators for the following reasons nevertheless explicit:
// * request readability
// * code readability
// * complex cases readability
let searchTermArray = Object.keys(query).reduce((acc, prop) => {
const isArrayValue = Array.isArray(query[prop])

if (!isArrayValue) {
acc.push(`${prop}:${query[prop]}`)
}

return (
// By definition (KQL spec) OR, AND or (GROUP) is implicit for simple cases where
// different or identical keys are part of the query.
//
// We list these operators for the following reasons nevertheless explicit:
// * request readability
// * code readability
// * complex cases readability
Object.keys(query)
.reduce((acc, prop) => {
const isArrayValue = Array.isArray(query[prop])

if (!isArrayValue) {
acc.push(`${prop}:${query[prop]}`)
}

if (isArrayValue) {
acc.push(`${prop}:(${query[prop].join(' OR ')})`)
}

return acc
}, [])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the sort array helper before the join to make sure that the scope is at the end (just specify a sort callback function that does nothing else than sorting items starting with scope: to the end). Can be called in all cases, even on an empty result after the reducer finished, so you can keep the old structure of the code and only add the sort call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

.join(' AND ')
)
if (isArrayValue) {
acc.push(`${prop}:(${query[prop].join(' OR ')})`)
}

return acc
}, [])

// moving scope to the end of the query to prevent invalid query starting with AND
if (searchTermArray.length > 1) {
const scopeIndex = searchTermArray.findIndex((item) => item.includes('scope:'))
if (scopeIndex > -1 && scopeIndex !== searchTermArray.length - 1) {
const scope = searchTermArray.splice(scopeIndex, 1)
searchTermArray = [...searchTermArray, ...scope]
}
}
return searchTermArray.join(' AND ')
}

const breadcrumbs = computed(() => {
Expand Down
1 change: 0 additions & 1 deletion packages/web-app-search/src/portals/SearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ export default defineComponent({
scope = unref(scopeQueryValue)
}
const useScope =
unref(term) &&
unref(currentFolderAvailable) &&
unref(locationFilterId) === SearchLocationFilterConstants.inHere
router.push(
Expand Down