Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
search: ListFolder() with search capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuAlfageme committed Nov 24, 2022
1 parent 16d7c15 commit 97afb61
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 56 deletions.
5 changes: 5 additions & 0 deletions internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,11 @@ func (s *service) ListContainer(ctx context.Context, req *provider.ListContainer
}, nil
}

// Hack to enable search
if req.Opaque.Map["search"] != nil {
s.storage.ListFolder(ctx, newRef, []string{"search"})
}

mds, err := s.storage.ListFolder(ctx, newRef, req.ArbitraryMetadataKeys)
if err != nil {
var st *rpc.Status
Expand Down
49 changes: 32 additions & 17 deletions internal/http/services/owncloud/ocdav/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package ocdav

import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"net/http"
Expand All @@ -28,6 +29,7 @@ import (
rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
providerv1beta1 "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
ctxpkg "github.com/cs3org/reva/pkg/ctx"
)
Expand Down Expand Up @@ -71,25 +73,38 @@ func (s *svc) doSearchFiles(w http.ResponseWriter, r *http.Request, sf *reportSe

log.Info().Msgf("hugo: search is: %+v", sf)

/*
_, err := bleve.Open("/var/tmp/search.db")
if err != nil {
log.Error().Err(err).Msg("hugo: error opening bleve db")
w.WriteHeader(http.StatusInternalServerError)
return
}
client, err := s.getClient()
if err != nil {
log.Error().Err(err).Msg("search: error getting grpc client")
w.WriteHeader(http.StatusInternalServerError)
return
}

query := bleve.NewWildcardQuery(sf.Search.Pattern)
req := bleve.NewSearchRequest(query)
res, err := index.Search(req)
if err != nil {
log.Error().Err(err).Msg("hugo: error searching")
w.WriteHeader(http.StatusInternalServerError)
return
}
*/
opaqueMap := map[string]*typespb.OpaqueEntry{
"search": {
Decoder: "plain",
Value: []byte("search"),
},
}

ref := &provider.Reference{Path: "/eos/project/c/cernbox"}

req := &provider.ListContainerRequest{Opaque: &typespb.Opaque{
Map: opaqueMap,
}, Ref: ref}

res, err := client.ListContainer(ctx, req)

if err != nil {
log.Error().Err(err).Msg("search: error listing container")
w.WriteHeader(http.StatusInternalServerError)
return
}

for _, v := range res.Infos {
fmt.Println(v)
}

//log.Info().Msgf("hugo: bleve result: %+v", res)
data := `
<?xml version="1.0" encoding="UTF-8"?>
<d:multistatus xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:s="http://sabredav.org/ns">
Expand Down
81 changes: 42 additions & 39 deletions pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import (

const (
refTargetAttrKey = "reva.target"
lwShareAttrKey = "reva.lwshare"
)

const (
Expand Down Expand Up @@ -1279,6 +1280,47 @@ func (fs *eosfs) ListFolder(ctx context.Context, ref *provider.Reference, mdKeys
return nil, errors.Wrap(err, "eosfs: error resolving reference")
}

u, err := getUser(ctx)
if err != nil {
return nil, errors.Wrap(err, "eosfs: no user in ctx")
}
// lightweight accounts don't have share folders, so we're passing an empty string as path
auth, err := fs.getUserAuth(ctx, u, "")
if err != nil {
return nil, err
}

searchString := ""
finfos := []*provider.ResourceInfo{}

for i, key := range mdKeys {
if key == "search" {
// Check that searchString not empty
searchString = mdKeys[i]

eosFileInfos, err := fs.c.SearchDir(ctx, auth, searchString, p)
if err != nil {
return nil, errors.Wrap(err, "eosfs: error searching")
}

for _, eosFileInfo := range eosFileInfos {
// filter out sys files
if !fs.conf.ShowHiddenSysFiles {
base := path.Base(eosFileInfo.File)
if hiddenReg.MatchString(base) {
continue
}
}

if finfo, err := fs.convertToFileReference(ctx, eosFileInfo); err == nil {
finfos = append(finfos, finfo)
}
}

return finfos, nil
}
}

if fs.conf.EnableHome {
return fs.listWithHome(ctx, p)
}
Expand Down Expand Up @@ -1372,45 +1414,6 @@ func (fs *eosfs) listShareFolderRoot(ctx context.Context, p string) (finfos []*p
return finfos, nil
}

func (fs *eosfs) findFilesOnTree(ctx context.Context, ss string, p string) (finfos []*provider.ResourceInfo, err error) {
fn := fs.wrapShadow(ctx, p)

u, err := getUser(ctx)

if err != nil {
return nil, errors.Wrap(err, "eosfs: search: no user in ctx")
}
// lightweight accounts don't have share folders, so we're passing an empty string as path
auth, err := fs.getUserAuth(ctx, u, "")
if err != nil {
return nil, err
}

log := appctx.GetLogger(ctx)
log.Info().Msgf("eosfs: search: user=%s path=%s searchString=%s", u, fn, ss)

eosFileInfos, err := fs.c.SearchDir(ctx, auth, ss, fn)
if err != nil {
return nil, errors.Wrap(err, "eosfs: search: error listing")
}

for _, eosFileInfo := range eosFileInfos {
// filter out sys files
if !fs.conf.ShowHiddenSysFiles {
base := path.Base(eosFileInfo.File)
if hiddenReg.MatchString(base) {
continue
}
}

if finfo, err := fs.convertToFileReference(ctx, eosFileInfo); err == nil {
finfos = append(finfos, finfo)
}
}

return finfos, nil
}

// CreateStorageSpace creates a storage space
func (fs *eosfs) CreateStorageSpace(ctx context.Context, req *provider.CreateStorageSpaceRequest) (*provider.CreateStorageSpaceResponse, error) {
return nil, fmt.Errorf("unimplemented: CreateStorageSpace")
Expand Down

0 comments on commit 97afb61

Please sign in to comment.