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

Filter hidden files #5018

Merged
merged 5 commits into from
Nov 10, 2022
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
7 changes: 7 additions & 0 deletions changelog/unreleased/filter-hidden-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: Add the "hidden" state to the search index

We changed the search service to store the "hidden" state of entries in the
search index. That will allow for filtering/searching hidden files in the
future.

https://github.com/owncloud/ocis/pull/5018
3 changes: 3 additions & 0 deletions services/search/pkg/search/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type indexDocument struct {
Type uint64

Deleted bool
Hidden bool
}

// Index represents a bleve based search index
Expand Down Expand Up @@ -297,6 +298,7 @@ func toEntity(ref *sprovider.Reference, ri *sprovider.ResourceInfo) *indexDocume
MimeType: ri.MimeType,
Type: uint64(ri.Type),
Deleted: false,
Hidden: strings.HasPrefix(ri.Path, "."),
}

if ri.Mtime != nil {
Expand All @@ -318,6 +320,7 @@ func fieldsToEntity(fields map[string]interface{}) *indexDocument {
MimeType: fields["MimeType"].(string),
Type: uint64(fields["Type"].(float64)),
Deleted: fields["Deleted"].(bool),
Hidden: fields["Hidden"].(bool),
}
return doc
}
Expand Down
10 changes: 10 additions & 0 deletions services/search/pkg/search/index/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ var _ = Describe("Index", func() {
assertDocCount(ref.ResourceId, `Name:1234*`, 1)
})

It("filters hidden files", func() {
ri.Path = ".hidden.pdf"
ref.Path = "./" + ri.Path
err := i.Add(ref, ri)
Expect(err).ToNot(HaveOccurred())

assertDocCount(ref.ResourceId, `Name:*hidden* +Hidden:T`, 1)
assertDocCount(ref.ResourceId, `Name:*hidden* +Hidden:F`, 0)
})

Context("with a file in the root of the space", func() {
JustBeforeEach(func() {
err := i.Add(ref, ri)
Expand Down