mirror of https://github.com/perkeep/perkeep.git
Various renamings. dropped getTagged.
Change-Id: I20982074071b819110fe07cb795ffcb7d6c8560e
This commit is contained in:
parent
aa83d21048
commit
b0dda5e86f
|
@ -303,9 +303,9 @@ func main() {
|
||||||
}
|
}
|
||||||
if *flagTag != "" {
|
if *flagTag != "" {
|
||||||
tags := strings.Split(*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 {
|
for _, tag := range tags {
|
||||||
m = schema.NewAddAttributeClaim(permaNode.BlobRef, "camliTag", tag)
|
m = schema.NewAddAttributeClaim(permaNode.BlobRef, "tag", tag)
|
||||||
put, err := up.UploadAndSignMap(m)
|
put, err := up.UploadAndSignMap(m)
|
||||||
handleResult("claim-permanode-tag", put, err)
|
handleResult("claim-permanode-tag", put, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,11 +182,9 @@ func (mi *Indexer) populateClaim(blobRef *blobref.BlobRef, camli *schema.Superse
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(mpl): revert all "camliTag" to "tag".
|
|
||||||
// Will do in next CL, when we drop GetTaggedPermanodes
|
|
||||||
if verifiedKeyId != "" {
|
if verifiedKeyId != "" {
|
||||||
switch camli.Attribute {
|
switch camli.Attribute {
|
||||||
case "camliRoot", "camliTag", "title":
|
case "camliRoot", "tag", "title":
|
||||||
// TODO(bradfitz,mpl): these tag names are hard-coded.
|
// TODO(bradfitz,mpl): these tag names are hard-coded.
|
||||||
// we should probably have a config file of attributes
|
// we should probably have a config file of attributes
|
||||||
// and properties (e.g. which way(s) they're indexed)
|
// 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 {
|
camli.ClaimDate, blobRef.String(), camli.Permanode); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if camli.Attribute == "camliTag" || camli.Attribute == "title" {
|
if camli.Attribute == "tag" || camli.Attribute == "title" {
|
||||||
// Identical copy for fulltext searches
|
// Identical copy for fulltext searches
|
||||||
// TODO(mpl): do the DELETEs as well
|
// TODO(mpl): do the DELETEs as well
|
||||||
if err = mi.db.Execute("INSERT IGNORE INTO signerattrvalueft (keyid, attr, value, claimdate, blobref, permanode) "+
|
if err = mi.db.Execute("INSERT IGNORE INTO signerattrvalueft (keyid, attr, value, claimdate, blobref, permanode) "+
|
||||||
|
|
|
@ -141,35 +141,7 @@ func (mi *Indexer) GetBlobMimeType(blob *blobref.BlobRef) (mime string, size int
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mi *Indexer) GetTaggedPermanodes(dest chan<- *blobref.BlobRef, signer *blobref.BlobRef, tag string, limit int) os.Error {
|
func (mi *Indexer) SearchPermanodesWithAttr(dest chan<- *blobref.BlobRef, request *search.PermanodeByAttrRequest) 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 {
|
|
||||||
defer close(dest)
|
defer close(dest)
|
||||||
keyId, err := mi.keyIdOfSigner(request.Signer)
|
keyId, err := mi.keyIdOfSigner(request.Signer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -105,11 +105,8 @@ func (sh *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||||
case "camli/search/recent":
|
case "camli/search/recent":
|
||||||
sh.serveRecentPermanodes(rw, req)
|
sh.serveRecentPermanodes(rw, req)
|
||||||
return
|
return
|
||||||
case "camli/search/tag":
|
case "camli/search/permanodeattr":
|
||||||
sh.serveTaggedPermanodes(rw, req)
|
sh.servePermanodesWithAttr(rw, req)
|
||||||
return
|
|
||||||
case "camli/search/request":
|
|
||||||
sh.serveRequestedPermanodes(rw, req)
|
|
||||||
return
|
return
|
||||||
case "camli/search/describe":
|
case "camli/search/describe":
|
||||||
sh.serveDescribe(rw, req)
|
sh.serveDescribe(rw, req)
|
||||||
|
@ -169,41 +166,8 @@ func (sh *Handler) serveRecentPermanodes(rw http.ResponseWriter, req *http.Reque
|
||||||
dr.PopulateJSON(ret)
|
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
|
// 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()
|
ret := jsonMap()
|
||||||
defer httputil.ReturnJson(rw, ret)
|
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)
|
ch := make(chan *blobref.BlobRef, buffered)
|
||||||
errch := make(chan os.Error)
|
errch := make(chan os.Error)
|
||||||
go func() {
|
go func() {
|
||||||
errch <- sh.index.SearchPermanodes(ch,
|
errch <- sh.index.SearchPermanodesWithAttr(ch,
|
||||||
&PermanodesRequest{Attribute: attr,
|
&PermanodeByAttrRequest{Attribute: attr,
|
||||||
Query: value,
|
Query: value,
|
||||||
Signer: signer,
|
Signer: signer,
|
||||||
FuzzyMatch: fuzzyMatch,
|
FuzzyMatch: fuzzyMatch,
|
||||||
|
@ -247,12 +211,12 @@ func (sh *Handler) serveRequestedPermanodes(rw http.ResponseWriter, req *http.Re
|
||||||
|
|
||||||
dr := sh.NewDescribeRequest()
|
dr := sh.NewDescribeRequest()
|
||||||
|
|
||||||
requested := jsonMapList()
|
withAttr := jsonMapList()
|
||||||
for res := range ch {
|
for res := range ch {
|
||||||
dr.Describe(res, 2)
|
dr.Describe(res, 2)
|
||||||
jm := jsonMap()
|
jm := jsonMap()
|
||||||
jm["permanode"] = res.String()
|
jm["permanode"] = res.String()
|
||||||
requested = append(requested, jm)
|
withAttr = append(withAttr, jm)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := <-errch
|
err := <-errch
|
||||||
|
@ -262,7 +226,7 @@ func (sh *Handler) serveRequestedPermanodes(rw http.ResponseWriter, req *http.Re
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ret["requested"] = requested
|
ret["withAttr"] = withAttr
|
||||||
dr.PopulateJSON(ret)
|
dr.PopulateJSON(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ type Path struct {
|
||||||
Suffix string
|
Suffix string
|
||||||
}
|
}
|
||||||
|
|
||||||
type PermanodesRequest struct {
|
type PermanodeByAttrRequest struct {
|
||||||
Attribute string // currently supported: "tag", "title"
|
Attribute string // currently supported: "tag", "title"
|
||||||
Query string
|
Query string
|
||||||
Signer *blobref.BlobRef
|
Signer *blobref.BlobRef
|
||||||
|
@ -87,14 +87,6 @@ type Index interface {
|
||||||
owner []*blobref.BlobRef,
|
owner []*blobref.BlobRef,
|
||||||
limit int) os.Error
|
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
|
// SearchPermanodes finds permanodes matching the provided
|
||||||
// request and sends unique permanode blobrefs to dest.
|
// request and sends unique permanode blobrefs to dest.
|
||||||
// In particular, if request.FuzzyMatch is true, a fulltext
|
// In particular, if request.FuzzyMatch is true, a fulltext
|
||||||
|
@ -105,8 +97,8 @@ type Index interface {
|
||||||
// restricted to the named attribute.
|
// restricted to the named attribute.
|
||||||
//
|
//
|
||||||
// dest is always closed, regardless of the error return value.
|
// dest is always closed, regardless of the error return value.
|
||||||
SearchPermanodes(dest chan<- *blobref.BlobRef,
|
SearchPermanodesWithAttr(dest chan<- *blobref.BlobRef,
|
||||||
request *PermanodesRequest) os.Error
|
request *PermanodeByAttrRequest) os.Error
|
||||||
|
|
||||||
GetOwnerClaims(permaNode, owner *blobref.BlobRef) (ClaimList, os.Error)
|
GetOwnerClaims(permaNode, owner *blobref.BlobRef) (ClaimList, os.Error)
|
||||||
|
|
||||||
|
|
|
@ -113,11 +113,7 @@ func (fi *FakeIndex) GetRecentPermanodes(dest chan *search.Result, owner []*blob
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(mpl): write real tests
|
// TODO(mpl): write real tests
|
||||||
func (fi *FakeIndex) GetTaggedPermanodes(dest chan<- *blobref.BlobRef, signer *blobref.BlobRef, tag string, limit int) os.Error {
|
func (fi *FakeIndex) SearchPermanodesWithAttr(dest chan<- *blobref.BlobRef, request *search.PermanodeByAttrRequest) os.Error {
|
||||||
panic("NOIMPL")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fi *FakeIndex) SearchPermanodes(dest chan<- *blobref.BlobRef, request *search.PermanodesRequest) os.Error {
|
|
||||||
panic("NOIMPL")
|
panic("NOIMPL")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -306,17 +306,9 @@ function camliGetRecentlyUpdatedPermanodes(opts) {
|
||||||
xhr.send();
|
xhr.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
function camliGetTaggedPermanodes(signer, value, opts) {
|
function camliGetPermanodesWithAttr(signer, attr, value, fuzzy, opts) {
|
||||||
var xhr = camliJsonXhr("camliGetTaggedPermanodes", opts);
|
var xhr = camliJsonXhr("camliGetPermanodesWithAttr", opts);
|
||||||
var path = makeURL(Camli.config.searchRoot + "camli/search/tag",
|
var path = makeURL(Camli.config.searchRoot + "camli/search/permanodeattr",
|
||||||
{ 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",
|
|
||||||
{ signer: signer, attr: attr, value: value, fuzzy: fuzzy });
|
{ signer: signer, attr: attr, value: value, fuzzy: fuzzy });
|
||||||
xhr.open("GET", path, true);
|
xhr.open("GET", path, true);
|
||||||
xhr.send();
|
xhr.send();
|
||||||
|
|
|
@ -88,7 +88,7 @@ function handleFormTagsSubmit(e) {
|
||||||
var tag = tags[idx];
|
var tag = tags[idx];
|
||||||
camliNewAddAttributeClaim(
|
camliNewAddAttributeClaim(
|
||||||
getPermanodeParam(),
|
getPermanodeParam(),
|
||||||
"camliTag",
|
"tag",
|
||||||
tag,
|
tag,
|
||||||
{
|
{
|
||||||
success: oneDone,
|
success: oneDone,
|
||||||
|
@ -143,7 +143,7 @@ function deleteTagFunc(tag, strikeEle, removeEle) {
|
||||||
strikeEle.innerHTML = "<del>" + strikeEle.innerHTML + "</del>";
|
strikeEle.innerHTML = "<del>" + strikeEle.innerHTML + "</del>";
|
||||||
camliNewDelAttributeClaim(
|
camliNewDelAttributeClaim(
|
||||||
getPermanodeParam(),
|
getPermanodeParam(),
|
||||||
"camliTag",
|
"tag",
|
||||||
tag,
|
tag,
|
||||||
{
|
{
|
||||||
success: function() {
|
success: function() {
|
||||||
|
@ -410,7 +410,7 @@ function onBlobDescribed(jres) {
|
||||||
c.appendChild(a);
|
c.appendChild(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
var tags = permanodeObject.attr.camliTag;
|
var tags = permanodeObject.attr.tag;
|
||||||
for (idx in tags) {
|
for (idx in tags) {
|
||||||
var tag = tags[idx];
|
var tag = tags[idx];
|
||||||
|
|
||||||
|
|
|
@ -93,13 +93,13 @@ function doSearch() {
|
||||||
// TODO(mpl): add other kinds of searches (by filename for ex).
|
// TODO(mpl): add other kinds of searches (by filename for ex).
|
||||||
switch(CamliSearch.type) {
|
switch(CamliSearch.type) {
|
||||||
case "tag":
|
case "tag":
|
||||||
camliGetTaggedPermanodes(sigconf.publicKeyBlobRef, CamliSearch.query, tagcb);
|
camliGetPermanodesWithAttr(sigconf.publicKeyBlobRef, "tag", CamliSearch.query, CamliSearch.fuzzy, tagcb);
|
||||||
break;
|
break;
|
||||||
case "title":
|
case "title":
|
||||||
camliGetRequestedPermanodes(sigconf.publicKeyBlobRef, "title", CamliSearch.query, CamliSearch.fuzzy, tagcb);
|
camliGetPermanodesWithAttr(sigconf.publicKeyBlobRef, "title", CamliSearch.query, "true", tagcb);
|
||||||
break;
|
break;
|
||||||
case "":
|
case "":
|
||||||
camliGetRequestedPermanodes(sigconf.publicKeyBlobRef, "", CamliSearch.query, "true", tagcb);
|
camliGetPermanodesWithAttr(sigconf.publicKeyBlobRef, "", CamliSearch.query, "true", tagcb);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -120,14 +120,7 @@ function showPermanodes(searchRes, type) {
|
||||||
while (div.hasChildNodes()) {
|
while (div.hasChildNodes()) {
|
||||||
div.removeChild(div.lastChild);
|
div.removeChild(div.lastChild);
|
||||||
}
|
}
|
||||||
switch(type) {
|
var results = searchRes.withAttr;
|
||||||
case "tag":
|
|
||||||
var results = searchRes.tagged;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
var results = searchRes.requested;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (results.length > 0) {
|
if (results.length > 0) {
|
||||||
var checkall = document.createElement("input");
|
var checkall = document.createElement("input");
|
||||||
checkall.id = "checkall";
|
checkall.id = "checkall";
|
||||||
|
|
Loading…
Reference in New Issue