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

enhancement: Add support for kql search queries #9644

Closed
wants to merge 7 commits into from
Closed
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
5 changes: 3 additions & 2 deletions .drone.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# The version of OCIS to use in pipelines that test against OCIS
OCIS_COMMITID=9c3511d2b08de25b16be3d309d0a7710b6848747
OCIS_BRANCH=master
OCIS_REPO_URL=https://github.com/fschade/ocis.git
OCIS_COMMITID=182a2fa1ac325455f65459e16d40a3187ef4b333
OCIS_BRANCH=enable-kql
3 changes: 1 addition & 2 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,6 @@ def restoreOcisCache():
}]

def buildOcis():
ocis_repo_url = "https://github.com/owncloud/ocis.git"
return [
{
"name": "clone-ocis",
Expand All @@ -1458,7 +1457,7 @@ def buildOcis():
"cd $GOPATH/src",
"mkdir -p github.com/owncloud",
"cd github.com/owncloud",
"git clone -b $OCIS_BRANCH --single-branch %s" % ocis_repo_url,
"git clone -b $OCIS_BRANCH --single-branch $OCIS_REPO_URL",
"cd ocis",
"git checkout $OCIS_COMMITID",
],
Expand Down
8 changes: 8 additions & 0 deletions changelog/unreleased/enhancement-use-kql-for-search
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Enhancement: Keyword Query Language (KQL) search syntax support

Use [KQL](https://learn.microsoft.com/en-us/sharepoint/dev/general-development/keyword-query-language-kql-syntax-reference) as default search syntax.

https://github.com/owncloud/web/issues/9636
https://github.com/owncloud/web/pull/9644
https://github.com/owncloud/ocis/pull/7196
https://github.com/owncloud/ocis/pull/7043
35 changes: 21 additions & 14 deletions packages/web-app-files/src/components/Search/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -242,24 +242,31 @@ export default defineComponent({
}

const buildSearchTerm = (manuallyUpdateFilterChip = false) => {
let term = ''
if (unref(searchTerm)) {
term = `+Name:*${unref(searchTerm)}*`
let query = ''
const add = (k: string, v: string) => {
query = (query + ` ${k}:${v}`).trimStart()
}

const fullTextQuery = queryItemAsString(unref(fullTextParam))
if (fullTextQuery) {
term = `+Content:"${unref(searchTerm)}"`
const humanSearchTerm = unref(searchTerm)
const isContentOnlySearch = queryItemAsString(unref(fullTextParam)) == 'true'

if (isContentOnlySearch && !!humanSearchTerm) {
add('content', `"${humanSearchTerm}"`)
} else if (!!humanSearchTerm) {
add('name', `"*${humanSearchTerm}*"`)
}
if (unref(scopeQuery) && unref(doUseScope) === 'true') {
term += ` scope:${unref(scopeQuery)}`

const humanScopeQuery = unref(scopeQuery)
const isScopedSearch = unref(doUseScope) === 'true'
if (isScopedSearch && humanScopeQuery) {
add('scope', `${humanScopeQuery}`)
}

const tagsQuery = queryItemAsString(unref(tagParam))
if (tagsQuery) {
tagsQuery.split('+')?.forEach((tag) => {
term += ` +Tags:"${unref(tag)}"`
})
const humanTagsParams = queryItemAsString(unref(tagParam))
if (humanTagsParams) {
// in the legacy implementation there was the option to query by multiple tags, e.g. string.split("+")
// this was not in use(?) and is removed.
add('tag', `"${humanTagsParams}"`)

if (manuallyUpdateFilterChip && unref(tagFilter)) {
/**
Expand All @@ -272,7 +279,7 @@ export default defineComponent({
}
}

return term.trimStart()
return query
}

const breadcrumbs = computed(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('List component', () => {
const searchTerm = 'term'
const { wrapper } = getWrapper({ searchTerm })
const appBar = wrapper.findComponent<any>('app-bar-stub')
expect(appBar.props('breadcrumbs')[0].text).toContain(searchTerm)
expect(appBar.props('breadcrumbs')[0].text).toEqual(`Search results for "${searchTerm}"`)
})
})
describe('filter', () => {
Expand All @@ -75,13 +75,13 @@ describe('List component', () => {
const searchTerm = 'term'
const tagFilterQuery = 'tag1'
const { wrapper } = getWrapper({
availableTags: ['tag1'],
availableTags: [tagFilterQuery],
searchTerm,
tagFilterQuery
})
await wrapper.vm.loadAvailableTagsTask.last
expect(wrapper.emitted('search')[0][0]).toEqual(
`+Name:*${searchTerm}* +Tags:"${tagFilterQuery}"`
`name:"*${searchTerm}*" tag:"${tagFilterQuery}"`
)
})
})
Expand All @@ -98,7 +98,7 @@ describe('List component', () => {
fullTextSearchEnabled: true
})
await wrapper.vm.loadAvailableTagsTask.last
expect(wrapper.emitted('search')[0][0]).toEqual(`+Content:"${searchTerm}"`)
expect(wrapper.emitted('search')[0][0]).toEqual(`content:"${searchTerm}"`)
})
})
})
Expand Down
30 changes: 13 additions & 17 deletions packages/web-app-search/src/portals/SearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ import { eventBus } from 'web-pkg/src/services/eventBus'
import { computed, defineComponent, GlobalComponents, inject, Ref, ref, unref, watch } from 'vue'
import { SearchLocationFilterConstants } from 'web-pkg/src/composables'
import { SearchBarFilter } from 'web-pkg/src/components'
import { SHARE_JAIL_ID } from 'web-client/src/helpers'

export default defineComponent({
name: 'SearchBar',
Expand All @@ -128,7 +127,7 @@ export default defineComponent({
const isMobileWidth = inject<Ref<boolean>>('isMobileWidth')
const scopeQueryValue = useRouteQuery('scope')
const shareId = useRouteQuery('shareId')
const locationFilterId = ref(SearchLocationFilterConstants.inHere)
const locationFilterId = ref(SearchLocationFilterConstants.everywhere)
const optionsDropRef = ref(null)
const activePreviewIndex = ref(null)
const term = ref('')
Expand Down Expand Up @@ -166,41 +165,36 @@ export default defineComponent({
return unref(providerStore)?.availableProviders
})

const buildLocationScopeId = () => {
const currentFolder = store.getters['Files/currentFolder']
const path = currentFolder.path === '/' ? '' : currentFolder.path
if (isShareRoute()) {
return `${SHARE_JAIL_ID}$${SHARE_JAIL_ID}!${shareId.value}${path}`
}
const spaceId = currentFolder.fileId.split('!')[0]
return `${spaceId}${path}`
}

const search = async () => {
searchResults.value = []
if (!unref(term)) {
return
}
let searchTerm = unref(term)
const terms = [`name:"*${unref(term)}*"`]

if (
unref(currentFolderAvailable) &&
unref(locationFilterId) === SearchLocationFilterConstants.inHere
) {
const currentFolder = store.getters['Files/currentFolder']
let scope

if (currentFolder?.fileId) {
scope = buildLocationScopeId()
scope = currentFolder?.fileId
} else {
scope = unref(scopeQueryValue)
}
searchTerm = `${unref(term)} scope:${scope}`

terms.push(`scope:${scope}`)
}

loading.value = true

for (const availableProvider of unref(availableProviders)) {
if (availableProvider.previewSearch?.available) {
searchResults.value.push({
providerId: availableProvider.id,
result: await availableProvider.previewSearch.search(unref(searchTerm))
result: await availableProvider.previewSearch.search(terms.join(' '))
})
}
}
Expand All @@ -215,9 +209,10 @@ export default defineComponent({
if (unref(activePreviewIndex) === null) {
const currentQuery = unref(router.currentRoute).query
const currentFolder = store.getters['Files/currentFolder']

let scope
if (unref(currentFolderAvailable) && currentFolder?.fileId) {
scope = buildLocationScopeId()
scope = currentFolder?.fileId
} else {
scope = unref(scopeQueryValue)
}
Expand Down Expand Up @@ -583,6 +578,7 @@ export default defineComponent({
&.active {
background-color: var(--oc-color-background-highlight);
}

&.disabled {
background-color: var(--oc-color-background-muted);
pointer-events: none;
Expand Down
6 changes: 3 additions & 3 deletions packages/web-pkg/src/components/SearchBarFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default defineComponent({
emits: ['update:modelValue'],
setup(props, { emit }) {
const { $gettext } = useGettext()
const useSopeQueryValue = useRouteQuery('useScope')
const useScopeQueryValue = useRouteQuery('useScope')

const currentSelection = ref<LocationOption>()
const userSelection = ref<LocationOption>()
Expand All @@ -80,8 +80,8 @@ export default defineComponent({
watch(
() => props.currentFolderAvailable,
() => {
if (unref(useSopeQueryValue)) {
const useScope = unref(useSopeQueryValue).toString() === 'true'
if (unref(useScopeQueryValue)) {
const useScope = unref(useScopeQueryValue).toString() === 'true'
if (useScope) {
currentSelection.value = unref(locationOptions).find(
({ id }) => id === SearchLocationFilterConstants.inHere
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.