Filter hidden files (#5018)

* 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
This commit is contained in:
Andre Duffeck
2022-11-10 17:05:43 +01:00
committed by GitHub
parent 38ce3b7018
commit a0762e248e
3 changed files with 20 additions and 0 deletions

View File

@@ -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

View File

@@ -56,6 +56,7 @@ type indexDocument struct {
Type uint64
Deleted bool
Hidden bool
}
// Index represents a bleve based search index
@@ -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 {
@@ -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
}

View File

@@ -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)