Various renamings. dropped getTagged.

Change-Id: I20982074071b819110fe07cb795ffcb7d6c8560e
This commit is contained in:
mpl 2011-09-04 00:48:49 +02:00
parent aa83d21048
commit b0dda5e86f
9 changed files with 27 additions and 120 deletions

View File

@ -303,9 +303,9 @@ func main() {
}
if *flagTag != "" {
tags := strings.Split(*flagTag, ",")
m := schema.NewSetAttributeClaim(permaNode.BlobRef, "camliTag", tags[0])
m := schema.NewSetAttributeClaim(permaNode.BlobRef, "tag", tags[0])
for _, tag := range tags {
m = schema.NewAddAttributeClaim(permaNode.BlobRef, "camliTag", tag)
m = schema.NewAddAttributeClaim(permaNode.BlobRef, "tag", tag)
put, err := up.UploadAndSignMap(m)
handleResult("claim-permanode-tag", put, err)
}

View File

@ -182,11 +182,9 @@ func (mi *Indexer) populateClaim(blobRef *blobref.BlobRef, camli *schema.Superse
return
}
// TODO(mpl): revert all "camliTag" to "tag".
// Will do in next CL, when we drop GetTaggedPermanodes
if verifiedKeyId != "" {
switch camli.Attribute {
case "camliRoot", "camliTag", "title":
case "camliRoot", "tag", "title":
// TODO(bradfitz,mpl): these tag names are hard-coded.
// we should probably have a config file of attributes
// and properties (e.g. which way(s) they're indexed)
@ -196,7 +194,7 @@ func (mi *Indexer) populateClaim(blobRef *blobref.BlobRef, camli *schema.Superse
camli.ClaimDate, blobRef.String(), camli.Permanode); err != nil {
return
}
if camli.Attribute == "camliTag" || camli.Attribute == "title" {
if camli.Attribute == "tag" || camli.Attribute == "title" {
// Identical copy for fulltext searches
// TODO(mpl): do the DELETEs as well
if err = mi.db.Execute("INSERT IGNORE INTO signerattrvalueft (keyid, attr, value, claimdate, blobref, permanode) "+

View File

@ -141,35 +141,7 @@ func (mi *Indexer) GetBlobMimeType(blob *blobref.BlobRef) (mime string, size int
return
}
func (mi *Indexer) GetTaggedPermanodes(dest chan<- *blobref.BlobRef, signer *blobref.BlobRef, tag string, limit int) os.Error {
defer close(dest)
keyId, err := mi.keyIdOfSigner(signer)
if err != nil {
return err
}
rs, err := mi.db.Query("SELECT permanode FROM signerattrvalue WHERE keyid = ? AND attr = ? AND value = ? AND claimdate <> '' ORDER BY claimdate DESC LIMIT ?",
keyId, "camliTag", tag, limit)
if err != nil {
return err
}
defer rs.Close()
pn := ""
for rs.Next() {
if err := rs.Scan(&pn); err != nil {
return err
}
br := blobref.Parse(pn)
if br == nil {
continue
}
dest <- br
}
return nil
}
func (mi *Indexer) SearchPermanodes(dest chan<- *blobref.BlobRef, request *search.PermanodesRequest) os.Error {
func (mi *Indexer) SearchPermanodesWithAttr(dest chan<- *blobref.BlobRef, request *search.PermanodeByAttrRequest) os.Error {
defer close(dest)
keyId, err := mi.keyIdOfSigner(request.Signer)
if err != nil {

View File

@ -105,11 +105,8 @@ func (sh *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
case "camli/search/recent":
sh.serveRecentPermanodes(rw, req)
return
case "camli/search/tag":
sh.serveTaggedPermanodes(rw, req)
return
case "camli/search/request":
sh.serveRequestedPermanodes(rw, req)
case "camli/search/permanodeattr":
sh.servePermanodesWithAttr(rw, req)
return
case "camli/search/describe":
sh.serveDescribe(rw, req)
@ -169,41 +166,8 @@ func (sh *Handler) serveRecentPermanodes(rw http.ResponseWriter, req *http.Reque
dr.PopulateJSON(ret)
}
func (sh *Handler) serveTaggedPermanodes(rw http.ResponseWriter, req *http.Request) {
ret := jsonMap()
defer httputil.ReturnJson(rw, ret)
signer := blobref.MustParse(mustGet(req, "signer"))
value := mustGet(req, "value")
ch := make(chan *blobref.BlobRef, buffered)
errch := make(chan os.Error)
go func() {
errch <- sh.index.GetTaggedPermanodes(ch, signer, value, maxPermanodes)
}()
dr := sh.NewDescribeRequest()
tagged := jsonMapList()
for res := range ch {
dr.Describe(res, 2)
jm := jsonMap()
jm["permanode"] = res.String()
tagged = append(tagged, jm)
}
err := <-errch
if err != nil {
// TODO(mpl): return error status code, in addition to the english error code
ret["error"] = err.String()
return
}
ret["tagged"] = tagged
dr.PopulateJSON(ret)
}
// TODO(mpl): configure and/or document the name of the possible attributes in the http request
func (sh *Handler) serveRequestedPermanodes(rw http.ResponseWriter, req *http.Request) {
func (sh *Handler) servePermanodesWithAttr(rw http.ResponseWriter, req *http.Request) {
ret := jsonMap()
defer httputil.ReturnJson(rw, ret)
@ -237,8 +201,8 @@ func (sh *Handler) serveRequestedPermanodes(rw http.ResponseWriter, req *http.Re
ch := make(chan *blobref.BlobRef, buffered)
errch := make(chan os.Error)
go func() {
errch <- sh.index.SearchPermanodes(ch,
&PermanodesRequest{Attribute: attr,
errch <- sh.index.SearchPermanodesWithAttr(ch,
&PermanodeByAttrRequest{Attribute: attr,
Query: value,
Signer: signer,
FuzzyMatch: fuzzyMatch,
@ -247,12 +211,12 @@ func (sh *Handler) serveRequestedPermanodes(rw http.ResponseWriter, req *http.Re
dr := sh.NewDescribeRequest()
requested := jsonMapList()
withAttr := jsonMapList()
for res := range ch {
dr.Describe(res, 2)
jm := jsonMap()
jm["permanode"] = res.String()
requested = append(requested, jm)
withAttr = append(withAttr, jm)
}
err := <-errch
@ -262,7 +226,7 @@ func (sh *Handler) serveRequestedPermanodes(rw http.ResponseWriter, req *http.Re
return
}
ret["requested"] = requested
ret["withAttr"] = withAttr
dr.PopulateJSON(ret)
}

View File

@ -72,7 +72,7 @@ type Path struct {
Suffix string
}
type PermanodesRequest struct {
type PermanodeByAttrRequest struct {
Attribute string // currently supported: "tag", "title"
Query string
Signer *blobref.BlobRef
@ -87,14 +87,6 @@ type Index interface {
owner []*blobref.BlobRef,
limit int) os.Error
// TODO(mpl): ditch this and merge it into SearchPermanodes.
// GetTaggedPermanodes finds permanodes that have a tag which
// is an exact match with the given tag.
// dest is closed
GetTaggedPermanodes(dest chan<- *blobref.BlobRef,
signer *blobref.BlobRef,
tag string, limit int) os.Error
// SearchPermanodes finds permanodes matching the provided
// request and sends unique permanode blobrefs to dest.
// In particular, if request.FuzzyMatch is true, a fulltext
@ -105,8 +97,8 @@ type Index interface {
// restricted to the named attribute.
//
// dest is always closed, regardless of the error return value.
SearchPermanodes(dest chan<- *blobref.BlobRef,
request *PermanodesRequest) os.Error
SearchPermanodesWithAttr(dest chan<- *blobref.BlobRef,
request *PermanodeByAttrRequest) os.Error
GetOwnerClaims(permaNode, owner *blobref.BlobRef) (ClaimList, os.Error)

View File

@ -113,11 +113,7 @@ func (fi *FakeIndex) GetRecentPermanodes(dest chan *search.Result, owner []*blob
}
// TODO(mpl): write real tests
func (fi *FakeIndex) GetTaggedPermanodes(dest chan<- *blobref.BlobRef, signer *blobref.BlobRef, tag string, limit int) os.Error {
panic("NOIMPL")
}
func (fi *FakeIndex) SearchPermanodes(dest chan<- *blobref.BlobRef, request *search.PermanodesRequest) os.Error {
func (fi *FakeIndex) SearchPermanodesWithAttr(dest chan<- *blobref.BlobRef, request *search.PermanodeByAttrRequest) os.Error {
panic("NOIMPL")
}

View File

@ -306,17 +306,9 @@ function camliGetRecentlyUpdatedPermanodes(opts) {
xhr.send();
}
function camliGetTaggedPermanodes(signer, value, opts) {
var xhr = camliJsonXhr("camliGetTaggedPermanodes", opts);
var path = makeURL(Camli.config.searchRoot + "camli/search/tag",
{ signer: signer, value: value });
xhr.open("GET", path, true);
xhr.send();
}
function camliGetRequestedPermanodes(signer, attr, value, fuzzy, opts) {
var xhr = camliJsonXhr("camliGetRequestedPermanodes", opts);
var path = makeURL(Camli.config.searchRoot + "camli/search/request",
function camliGetPermanodesWithAttr(signer, attr, value, fuzzy, opts) {
var xhr = camliJsonXhr("camliGetPermanodesWithAttr", opts);
var path = makeURL(Camli.config.searchRoot + "camli/search/permanodeattr",
{ signer: signer, attr: attr, value: value, fuzzy: fuzzy });
xhr.open("GET", path, true);
xhr.send();

View File

@ -88,7 +88,7 @@ function handleFormTagsSubmit(e) {
var tag = tags[idx];
camliNewAddAttributeClaim(
getPermanodeParam(),
"camliTag",
"tag",
tag,
{
success: oneDone,
@ -143,7 +143,7 @@ function deleteTagFunc(tag, strikeEle, removeEle) {
strikeEle.innerHTML = "<del>" + strikeEle.innerHTML + "</del>";
camliNewDelAttributeClaim(
getPermanodeParam(),
"camliTag",
"tag",
tag,
{
success: function() {
@ -410,7 +410,7 @@ function onBlobDescribed(jres) {
c.appendChild(a);
}
var tags = permanodeObject.attr.camliTag;
var tags = permanodeObject.attr.tag;
for (idx in tags) {
var tag = tags[idx];

View File

@ -93,13 +93,13 @@ function doSearch() {
// TODO(mpl): add other kinds of searches (by filename for ex).
switch(CamliSearch.type) {
case "tag":
camliGetTaggedPermanodes(sigconf.publicKeyBlobRef, CamliSearch.query, tagcb);
camliGetPermanodesWithAttr(sigconf.publicKeyBlobRef, "tag", CamliSearch.query, CamliSearch.fuzzy, tagcb);
break;
case "title":
camliGetRequestedPermanodes(sigconf.publicKeyBlobRef, "title", CamliSearch.query, CamliSearch.fuzzy, tagcb);
camliGetPermanodesWithAttr(sigconf.publicKeyBlobRef, "title", CamliSearch.query, "true", tagcb);
break;
case "":
camliGetRequestedPermanodes(sigconf.publicKeyBlobRef, "", CamliSearch.query, "true", tagcb);
camliGetPermanodesWithAttr(sigconf.publicKeyBlobRef, "", CamliSearch.query, "true", tagcb);
break;
}
};
@ -120,14 +120,7 @@ function showPermanodes(searchRes, type) {
while (div.hasChildNodes()) {
div.removeChild(div.lastChild);
}
switch(type) {
case "tag":
var results = searchRes.tagged;
break;
default:
var results = searchRes.requested;
break;
}
var results = searchRes.withAttr;
if (results.length > 0) {
var checkall = document.createElement("input");
checkall.id = "checkall";