mirror of https://github.com/perkeep/perkeep.git
index: implement some of SearchPermanodesWithAttr (untested, fighting)
Change-Id: I703f6432dba0781e4b125f2cd959fd7fa90efedb
This commit is contained in:
parent
21afbab992
commit
b648a17de9
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -172,4 +172,18 @@ var (
|
|||
{"mimetype", typeStr},
|
||||
},
|
||||
}
|
||||
|
||||
keySignerAttrValue = &keyType{
|
||||
"signerattrvalue",
|
||||
[]part{
|
||||
{"signer", typeKeyId},
|
||||
{"attr", typeStr},
|
||||
{"value", typeStr},
|
||||
{"claimdate", typeReverseTime},
|
||||
{"claimref", typeBlobRef},
|
||||
},
|
||||
[]part{
|
||||
{"permanode", typeBlobRef},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue