Created
November 10, 2010 04:49
-
-
Save anandology/670374 to your computer and use it in GitHub Desktop.
Python Script to add design document to couchdb database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import couchdb | |
view = { | |
"_id": "_design/seeds", | |
"fulltext": { | |
"by_seed": { | |
"index": """function(doc) { | |
if (doc.seeds) { | |
var d = new Document(); | |
for (var i=0; i<doc.seeds.length; i++) { | |
d.add(doc.seeds[i].toLowerCase(), {"field": "seed", "index": "not_analyzed", "store": "yes", "analyzer": "keyword"}); | |
} | |
d.add(doc.last_modified.value, {"field": "last_modified", "type": "string", "index": "not_analyzed", "store": "yes"}); | |
return d; | |
} | |
return null; | |
}""" | |
} | |
} | |
} | |
def main(url): | |
db = couchdb.Database(url) | |
id = view['_id'] | |
if id in db: | |
rev = db[id]['_rev'] | |
view['_rev'] = rev | |
db[id] = view | |
if __name__ == "__main__": | |
import sys | |
main(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment