From b648a17de9df117129bfcceeb1cd58a305856cb2 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 4 Dec 2011 14:47:05 -0800 Subject: [PATCH] index: implement some of SearchPermanodesWithAttr (untested, fighting) Change-Id: I703f6432dba0781e4b125f2cd959fd7fa90efedb --- lib/go/camli/index/index.go | 48 ++++++++++++++++++++++++++++++----- lib/go/camli/index/keys.go | 14 ++++++++++ lib/go/camli/index/receive.go | 6 ++--- 3 files changed, 58 insertions(+), 10 deletions(-) diff --git a/lib/go/camli/index/index.go b/lib/go/camli/index/index.go index a81ab9e2f..01917dbe1 100644 --- a/lib/go/camli/index/index.go +++ b/lib/go/camli/index/index.go @@ -267,7 +267,7 @@ func (x *Index) PermanodeOfSignerAttrValue(signer *blobref.BlobRef, attr, val st if err != nil { return nil, err } - it := x.queryPrefixString(pipes("signerattrvalue", keyId, urle(attr), urle(val), "")) + it := x.queryPrefix(keySignerAttrValue, keyId, attr, val) defer closeIterator(it, &err) if it.Next() { return blobref.Parse(it.Value()), nil @@ -275,6 +275,47 @@ func (x *Index) PermanodeOfSignerAttrValue(signer *blobref.BlobRef, attr, val st return nil, os.ENOENT } +// This is just like PermanodeOfSignerAttrValue except we return multiple and dup-suppress. +func (x *Index) SearchPermanodesWithAttr(dest chan<- *blobref.BlobRef, request *search.PermanodeByAttrRequest) (err os.Error) { + defer close(dest) + if request.FuzzyMatch { + // TODO(bradfitz): remove this for now? figure out how to handle it generically? + log.Printf("Got unsupported fuzzy search request: %#v", request) + return os.NewError("TODO: SearchPermanodesWithAttr: generic indexer doesn't support FuzzyMatch on PermanodeByAttrRequest") + } + if request.Attribute == "" { + return os.NewError("index: missing Attribute in SearchPermanodesWithAttr") + } + + keyId, err := x.keyId(request.Signer) + if err == ErrNotFound { + return nil + } + if err != nil { + return err + } + seen := make(map[string]bool) + it := x.queryPrefix(keySignerAttrValue, keyId, request.Attribute, request.Query) + defer closeIterator(it, &err) + for it.Next() { + pn := blobref.Parse(it.Value()) + if pn == nil { + continue + } + pnstr := pn.String() + if seen[pnstr] { + continue + } + seen[pnstr] = true + + dest <- pn + if len(seen) == request.MaxResults { + break + } + } + return nil +} + func (x *Index) PathsOfSignerTarget(signer, target *blobref.BlobRef) (paths []*search.Path, err os.Error) { paths = []*search.Path{} keyId, err := x.keyId(signer) @@ -455,8 +496,3 @@ func (x *Index) GetFileInfo(fileRef *blobref.BlobRef) (*search.FileInfo, os.Erro } return fi, nil } - -func (x *Index) SearchPermanodesWithAttr(dest chan<- *blobref.BlobRef, request *search.PermanodeByAttrRequest) os.Error { - log.Printf("index: TODO SearchPermanodesWithAttr") - return os.NewError("TODO: SearchPermanodesWithAttr") -} diff --git a/lib/go/camli/index/keys.go b/lib/go/camli/index/keys.go index 70976e4ee..3c558eb04 100644 --- a/lib/go/camli/index/keys.go +++ b/lib/go/camli/index/keys.go @@ -172,4 +172,18 @@ var ( {"mimetype", typeStr}, }, } + + keySignerAttrValue = &keyType{ + "signerattrvalue", + []part{ + {"signer", typeKeyId}, + {"attr", typeStr}, + {"value", typeStr}, + {"claimdate", typeReverseTime}, + {"claimref", typeBlobRef}, + }, + []part{ + {"permanode", typeBlobRef}, + }, + } ) diff --git a/lib/go/camli/index/receive.go b/lib/go/camli/index/receive.go index 378821a8f..068282a19 100644 --- a/lib/go/camli/index/receive.go +++ b/lib/go/camli/index/receive.go @@ -195,10 +195,8 @@ func (ix *Index) populateClaim(br *blobref.BlobRef, ss *schema.Superset, sniffer } if search.IsIndexedAttribute(ss.Attribute) { - savKey := pipes("signerattrvalue", - verifiedKeyId, urle(ss.Attribute), urle(ss.Value), - reverseTimeString(ss.ClaimDate), br) - bm.Set(savKey, pnbr.String()) + key := keySignerAttrValue.Key(verifiedKeyId, ss.Attribute, ss.Value, ss.ClaimDate, br) + bm.Set(key, keySignerAttrValue.Val(pnbr)) } return nil }