mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-04 19:29:49 -06:00
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:
7
changelog/unreleased/filter-hidden-files.md
Normal file
7
changelog/unreleased/filter-hidden-files.md
Normal 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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user