From 4b0d2841eec202d329f1cda08df361b7e813de54 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sat, 3 Nov 2012 16:08:37 +0100 Subject: [PATCH] Add search.EdgesTo method to search interface. No implementation yet. Change-Id: Ie3a9eb91e218e172b195d55cb9c17cb6c8f819ce --- pkg/index/index.go | 5 +++++ pkg/search/search.go | 23 +++++++++++++++++++++++ pkg/test/fakeindex.go | 4 ++++ 3 files changed, 32 insertions(+) diff --git a/pkg/index/index.go b/pkg/index/index.go index 2ba24b46f..c62217c5d 100644 --- a/pkg/index/index.go +++ b/pkg/index/index.go @@ -554,4 +554,9 @@ func (x *Index) GetFileInfo(fileRef *blobref.BlobRef) (*search.FileInfo, error) return fi, nil } +func (x *Index) EdgesTo(ref *blobref.BlobRef, opts *search.EdgesToOpts) ([]*search.Edge, error) { + // unimplemented. + return nil, errors.New("TODO: implement") +} + func (x *Index) Storage() IndexStorage { return x.s } diff --git a/pkg/search/search.go b/pkg/search/search.go index bd72620c1..e1f6bb4cf 100644 --- a/pkg/search/search.go +++ b/pkg/search/search.go @@ -125,6 +125,18 @@ type PermanodeByAttrRequest struct { MaxResults int // optional max results } +type EdgesToOpts struct { + Max int + // TODO: filter by type? +} + +type Edge struct { + From *blobref.BlobRef + FromType string // "permanode", "directory", etc + FromTitle string // name of source permanode or directory + To *blobref.BlobRef +} + type Index interface { // dest must be closed, even when returning an error. // limit is <= 0 for default. smallest possible default is 0 @@ -198,6 +210,17 @@ type Index interface { // Most recent Path claim for (signer, base, suffix) as of // provided time 'at', or most recent if 'at' is nil. PathLookup(signer, base *blobref.BlobRef, suffix string, at time.Time) (*Path, error) + + // EdgesTo finds references to the provided ref. + // + // For instance, if ref is a permanode, it might find the parent permanodes + // that have ref as a member. + // Or, if ref is a static file, it might find static directories which contain + // that file. + // This is a way to go "up" or "back" in a hierarchy. + // + // opts may be nil to accept the defaults. + EdgesTo(ref *blobref.BlobRef, opts *EdgesToOpts) ([]*Edge, error) } // TODO(bradfitz): rename this? This is really about signer-attr-value diff --git a/pkg/test/fakeindex.go b/pkg/test/fakeindex.go index 110dabd9e..a15fba1d1 100644 --- a/pkg/test/fakeindex.go +++ b/pkg/test/fakeindex.go @@ -171,3 +171,7 @@ func (fi *FakeIndex) PathLookup(signer, base *blobref.BlobRef, suffix string, at log.Printf("PathLookup miss for signer %q, base %q, suffix %q", signer, base, suffix) return nil, os.ErrNotExist } + +func (fi *FakeIndex) EdgesTo(ref *blobref.BlobRef, opts *search.EdgesToOpts) ([]*search.Edge, error) { + panic("NOIMPL") +}