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

feat: search highlights #9294

Merged
merged 4 commits into from
Jun 28, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: Search list add highlighted file content

We've introduced a feature that shows a highlighted result summary matching the search term in the search list,
if there are occurrences in the found files.

https://github.com/owncloud/web/pull/9294
https://github.com/owncloud/web/issues/9295
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"cucumber-html-reporter": "5.5.1",
"depcheck": "1.4.3",
"ejs": "3.1.9",
"eslint": "8.40.0",
"eslint": "8.43.0",
Copy link
Contributor Author

@AlexAndBear AlexAndBear Jun 27, 2023

Choose a reason for hiding this comment

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

I bumped eslint as locally calling eslint --fix tried always to alter packages/web-pkg/src/composables/router/types.ts
which resulted in a linter error in the ci, which was annoying.

Works now

"flush-promises": "1.0.2",
"git-repo-info": "2.1.1",
"jest": "29.5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<oc-icon name="edit-2" fill-type="line" size="small" />
</oc-button>
</div>
<slot name="additionalResourceContent" :resource="item" />
</template>
<template #status="{ item }">
<!-- @slot Status column -->
Expand Down
23 changes: 21 additions & 2 deletions packages/web-app-files/src/components/Search/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</item-filter>
<item-filter-toggle
v-if="fullTextSearchEnabled"
:filter-label="$gettext('Search in file content')"
:filter-label="$gettext('Search only in content')"
filter-name="fullText"
class="files-search-filter-full-text oc-mr-s"
/>
Expand Down Expand Up @@ -61,10 +61,18 @@
:is-selectable="true"
:sort-by="sortBy"
:sort-dir="sortDir"
:fields-displayed="['name', 'size', 'tags', 'mdate']"
@file-click="triggerDefaultAction"
@row-mounted="rowMounted"
@sort="handleSort"
>
<template #additionalResourceContent="{ resource }">
<span
v-if="resource.highlights"
class="files-search-resource-highlights oc-text-truncate"
v-html="resource.highlights"
/>
</template>
<template #contextMenu="{ resource }">
<context-actions
v-if="isResourceInSelection(resource)"
Expand Down Expand Up @@ -373,4 +381,15 @@ export default defineComponent({
}
})
</script>
<style lang="scss"></style>
<style lang="scss">
.files-search-resource-highlights {
font-size: 0.8125rem;
color: var(--oc-color-text-muted);

mark {
background: #fff74c;
font-style: normal;
font-weight: var(--oc-font-weight-semibold);
}
}
</style>
17 changes: 15 additions & 2 deletions packages/web-app-files/src/search/sdk/list.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import { SearchList, SearchResult } from 'web-app-search/src/types'
import ListComponent from '../../components/Search/List.vue'
import { ClientService } from 'web-pkg/src/services'
import { ProjectSpaceResource, buildResource, isProjectSpaceResource } from 'web-client/src/helpers'
import {
ProjectSpaceResource,
buildResource,
isProjectSpaceResource,
Resource
} from 'web-client/src/helpers'
import { Component, computed, Ref, unref } from 'vue'
import { DavProperties, DavProperty } from 'web-client/src/webdav/constants'
import { Store } from 'vuex'

export const searchLimit = 200

export interface SearchResource extends Resource {
highlights: string
}

export default class List implements SearchList {
public readonly component: Component
private readonly store: Store<any>
Expand Down Expand Up @@ -45,7 +54,11 @@ export default class List implements SearchList {
totalResults: range ? parseInt(range?.split('/')[1]) : null,
values: results.map((result) => {
const matchingSpace = this.getMatchingSpace(result.fileInfo[DavProperty.FileParent])
const resource = matchingSpace ? matchingSpace : buildResource(result)
const resource = {
...(matchingSpace ? matchingSpace : buildResource(result)),
highlights: result.fileInfo[DavProperty.Highlights] || ''
} as SearchResource

// info: in oc10 we have no storageId in resources. All resources are mounted into the personal space.
if (!resource.storageId) {
resource.storageId = this.store.getters.user.id
Expand Down
1 change: 1 addition & 0 deletions packages/web-client/src/webdav/constants/dav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export abstract class DavProperty {
static readonly MimeType: string = '{DAV:}getcontenttype'
static readonly ResourceType: string = '{DAV:}resourcetype'
static readonly DownloadURL: string = '{http://owncloud.org/ns}downloadURL'
static readonly Highlights: string = '{http://owncloud.org/ns}highlights'

static readonly ShareId: string = '{http://owncloud.org/ns}shareid'
static readonly ShareRoot: string = '{http://owncloud.org/ns}shareroot'
Expand Down
63 changes: 33 additions & 30 deletions pnpm-lock.yaml

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