Move special-casing of certain properties out of mysqlindexer and up to a common spot.

Change-Id: I543ce701e081d2b261b03b6721d5aa053bd231af
This commit is contained in:
Brad Fitzpatrick 2011-11-27 21:50:50 -05:00
parent a1548196b7
commit 3e9fc4c28a
2 changed files with 28 additions and 14 deletions

View File

@ -29,6 +29,7 @@ import (
"camli/jsonsign"
"camli/magic"
"camli/schema"
"camli/search"
)
func (mi *Indexer) ReceiveBlob(blobRef *blobref.BlobRef, source io.Reader) (retsb blobref.SizedBlobRef, err os.Error) {
@ -110,26 +111,21 @@ func (mi *Indexer) populateClaim(blobRef *blobref.BlobRef, camli *schema.Superse
}
if verifiedKeyId != "" {
switch camli.Attribute {
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)
if search.IsIndexedAttribute(camli.Attribute) {
if err = mi.db.Execute("INSERT IGNORE INTO signerattrvalue (keyid, attr, value, claimdate, blobref, permanode) "+
"VALUES (?, ?, ?, ?, ?, ?)",
verifiedKeyId, camli.Attribute, camli.Value,
camli.ClaimDate, blobRef.String(), camli.Permanode); err != nil {
return
}
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) "+
"VALUES (?, ?, ?, ?, ?, ?)",
verifiedKeyId, camli.Attribute, camli.Value,
camli.ClaimDate, blobRef.String(), camli.Permanode); err != nil {
return
}
}
if search.IsFulltextAttribute(camli.Attribute) {
// TODO(mpl): do the DELETEs as well
if err = mi.db.Execute("INSERT IGNORE INTO signerattrvalueft (keyid, attr, value, claimdate, blobref, permanode) "+
"VALUES (?, ?, ?, ?, ?, ?)",
verifiedKeyId, camli.Attribute, camli.Value,
camli.ClaimDate, blobRef.String(), camli.Permanode); err != nil {
return
}
}
if strings.HasPrefix(camli.Attribute, "camliPath:") {

View File

@ -120,6 +120,7 @@ type Index interface {
// and specific 'value', find the most recent permanode that has
// a corresponding 'set-attribute' claim attached.
// Returns os.ENOENT if none is found.
// Only attributes white-listed by IsIndexedAttribute are valid.
PermanodeOfSignerAttrValue(signer *blobref.BlobRef, attr, val string) (*blobref.BlobRef, os.Error)
PathsOfSignerTarget(signer, target *blobref.BlobRef) ([]*Path, os.Error)
@ -131,3 +132,20 @@ type Index interface {
// provided time 'at', or most recent if 'at' is nil.
PathLookup(signer, base *blobref.BlobRef, suffix string, at *time.Time) (*Path, os.Error)
}
func IsIndexedAttribute(attr string) bool {
switch attr {
case "camliRoot", "tag", "title":
return true
}
return false
}
func IsFulltextAttribute(attr string) bool {
switch attr {
case "tag", "title":
return true
}
return false
}