github.com/slspeek/camlistore_namedsearch@v0.0.0-20140519202248-ed6f70f7721a/pkg/index/interface.go (about)

     1  package index
     2  
     3  import (
     4  	"time"
     5  
     6  	"camlistore.org/pkg/blob"
     7  	"camlistore.org/pkg/context"
     8  	"camlistore.org/pkg/types/camtypes"
     9  )
    10  
    11  type Interface interface {
    12  	// os.ErrNotExist should be returned if the blob isn't known
    13  	GetBlobMeta(blob.Ref) (camtypes.BlobMeta, error)
    14  
    15  	// Should return os.ErrNotExist if not found.
    16  	GetFileInfo(fileRef blob.Ref) (camtypes.FileInfo, error)
    17  
    18  	// Should return os.ErrNotExist if not found.
    19  	GetImageInfo(fileRef blob.Ref) (camtypes.ImageInfo, error)
    20  
    21  	// Should return os.ErrNotExist if not found.
    22  	GetMediaTags(fileRef blob.Ref) (map[string]string, error)
    23  
    24  	// KeyId returns the GPG keyid (e.g. "2931A67C26F5ABDA)
    25  	// given the blobref of its ASCII-armored blobref.
    26  	// The error is ErrNotFound if not found.
    27  	KeyId(blob.Ref) (string, error)
    28  
    29  	// AppendClaims appends to dst claims on the given permanode.
    30  	// The signerFilter and attrFilter are both optional.  If non-zero,
    31  	// they filter the return items to only claims made by the given signer
    32  	// or claims about the given attribute, respectively.
    33  	// Deleted claims are never returned.
    34  	// The items may be appended in any order.
    35  	//
    36  	// TODO: this should take a context and a callback func
    37  	// instead of a dst, then it can append to a channel instead,
    38  	// and the context lets it be interrupted. The callback should
    39  	// take the context too, so the channel send's select can read
    40  	// from the Done channel.
    41  	AppendClaims(dst []camtypes.Claim, permaNode blob.Ref,
    42  		signerFilter blob.Ref,
    43  		attrFilter string) ([]camtypes.Claim, error)
    44  
    45  	// TODO(bradfitz): methods below this line are slated for a redesign
    46  	// to work efficiently for the new in-memory index.
    47  
    48  	// dest must be closed, even when returning an error.
    49  	// limit <= 0 means unlimited.
    50  	GetRecentPermanodes(dest chan<- camtypes.RecentPermanode,
    51  		owner blob.Ref,
    52  		limit int,
    53  		before time.Time) error
    54  
    55  	// SearchPermanodes finds permanodes matching the provided
    56  	// request and sends unique permanode blobrefs to dest.
    57  	// In particular, if request.FuzzyMatch is true, a fulltext
    58  	// search is performed (if supported by the attribute(s))
    59  	// instead of an exact match search.
    60  	// If request.Query is blank, the permanodes which have
    61  	// request.Attribute as an attribute (regardless of its value)
    62  	// are searched.
    63  	// Additionally, if request.Attribute is blank, all attributes
    64  	// are searched (as fulltext), otherwise the search is
    65  	// restricted  to the named attribute.
    66  	//
    67  	// dest is always closed, regardless of the error return value.
    68  	SearchPermanodesWithAttr(dest chan<- blob.Ref,
    69  		request *camtypes.PermanodeByAttrRequest) error
    70  
    71  	// ExistingFileSchemas returns 0 or more blobrefs of "bytes"
    72  	// (TODO(bradfitz): or file?) schema blobs that represent the
    73  	// bytes of a file given in bytesRef.  The file schema blobs
    74  	// returned are not guaranteed to reference chunks that still
    75  	// exist on the blobservers, though.  It's purely a hint for
    76  	// clients to avoid uploads if possible.  Before re-using any
    77  	// returned blobref they should be checked.
    78  	//
    79  	// Use case: a user drag & drops a large file onto their
    80  	// browser to upload.  (imagine that "large" means anything
    81  	// larger than a blobserver's max blob size) JavaScript can
    82  	// first SHA-1 the large file locally, then send the
    83  	// wholeFileRef to this call and see if they'd previously
    84  	// uploaded the same file in the past.  If so, the upload
    85  	// can be avoided if at least one of the returned schemaRefs
    86  	// can be validated (with a validating HEAD request) to still
    87  	// all exist on the blob server.
    88  	ExistingFileSchemas(wholeFileRef blob.Ref) (schemaRefs []blob.Ref, err error)
    89  
    90  	// GetDirMembers sends on dest the children of the static
    91  	// directory dirRef. It returns os.ErrNotExist if dirRef
    92  	// is nil.
    93  	// dest must be closed, even when returning an error.
    94  	// limit <= 0 means unlimited.
    95  	GetDirMembers(dirRef blob.Ref, dest chan<- blob.Ref, limit int) error
    96  
    97  	// Given an owner key, a camliType 'claim', 'attribute' name,
    98  	// and specific 'value', find the most recent permanode that has
    99  	// a corresponding 'set-attribute' claim attached.
   100  	// Returns os.ErrNotExist if none is found.
   101  	// Only attributes white-listed by IsIndexedAttribute are valid.
   102  	// TODO(bradfitz): ErrNotExist here is a weird error message ("file" not found). change.
   103  	// TODO(bradfitz): use keyId instead of signer?
   104  	PermanodeOfSignerAttrValue(signer blob.Ref, attr, val string) (blob.Ref, error)
   105  
   106  	// PathsOfSignerTarget queries the index about "camliPath:"
   107  	// URL-dispatch attributes.
   108  	//
   109  	// It returns a list of all the path claims that have been signed
   110  	// by the provided signer and point at the given target.
   111  	//
   112  	// This is used when editing a permanode, to figure work up
   113  	// the name resolution tree backwards ultimately to a
   114  	// camliRoot permanode (which should know its base URL), and
   115  	// then the complete URL(s) of a target can be found.
   116  	PathsOfSignerTarget(signer, target blob.Ref) ([]*camtypes.Path, error)
   117  
   118  	// All Path claims for (signer, base, suffix)
   119  	PathsLookup(signer, base blob.Ref, suffix string) ([]*camtypes.Path, error)
   120  
   121  	// Most recent Path claim for (signer, base, suffix) as of
   122  	// provided time 'at', or most recent if 'at' is nil.
   123  	PathLookup(signer, base blob.Ref, suffix string, at time.Time) (*camtypes.Path, error)
   124  
   125  	// EdgesTo finds references to the provided ref.
   126  	//
   127  	// For instance, if ref is a permanode, it might find the parent permanodes
   128  	// that have ref as a member.
   129  	// Or, if ref is a static file, it might find static directories which contain
   130  	// that file.
   131  	// This is a way to go "up" or "back" in a hierarchy.
   132  	//
   133  	// opts may be nil to accept the defaults.
   134  	EdgesTo(ref blob.Ref, opts *camtypes.EdgesToOpts) ([]*camtypes.Edge, error)
   135  
   136  	// EnumerateBlobMeta sends ch information about all blobs
   137  	// known to the indexer (which may be a subset of all total
   138  	// blobs, since the indexer is typically configured to not see
   139  	// non-metadata blobs) and then closes ch.  When it returns an
   140  	// error, it also closes ch. The blobs may be sent in any order.
   141  	// If the context finishes, the return error is context.ErrCanceled.
   142  	EnumerateBlobMeta(*context.Context, chan<- camtypes.BlobMeta) error
   143  }