Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 36 lines (24 sloc) 0.815 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
"""To support MongoDB full-text search, go through old posts and pages and add
a "plain" field with the plain text. Not needed for new posts, which have
"plain" added when they're created or edited.
"""

import argparse
import pymongo
from motor_blog.text import plain


def parse_args():
    parser = argparse.ArgumentParser(
        description='Add a plain-text field to all posts and pages',
    )

    args = parser.parse_args()
    return args


def main(args):
    db = pymongo.MongoClient().motorblog

    print (
        'Updating all', db.posts.count(), 'posts')

    print

    for post in db.posts.find().sort('_id'):
        print post['title'], post['type'], post['mod']
        post['plain'] = plain.plain(post['body'])
        db.posts.save(post)


if __name__ == '__main__':
    main(parse_args())
Something went wrong with that request. Please try again.