Skip to content

Commit

Permalink
Filter hidden files (#5018)
Browse files Browse the repository at this point in the history
* Filter hidden files from search results

* Add changelog

* Do not filter hidden files by default

* Set the hidden fields when converting fields to an entity

* Fix test
  • Loading branch information
aduffeck authored Nov 10, 2022
1 parent 38ce3b7 commit a0762e2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
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

0 comments on commit a0762e2

Please sign in to comment.