コード例 #1
0
ファイル: main.py プロジェクト: am-github/lmfdb
def cleanup():
    """
    reindexes knowls, also the list of categories. prunes history.
    this is an internal task just for admins!
    """
    from knowl import refresh_knowl_categories, extract_cat, make_keywords, get_knowls
    cats = refresh_knowl_categories()
    knowls = get_knowls()
    q_knowls = knowls.find({}, ['content', 'title'])
    for k in q_knowls:
        kid = k['_id']
        cat = extract_cat(kid)
        search_keywords = make_keywords(k['content'], kid, k['title'])
        knowls.update({'_id': kid},
                      {"$set": {
                       'cat': cat,
                       '_keywords': search_keywords
                       }})

    hcount = 0
    # max allowed history length
    max_h = 50
    q_knowls = knowls.find({'history': {'$exists': True}}, ['history'])
    for k in q_knowls:
        if len(k['history']) <= max_h:
            continue
        hcount += 1
        knowls.update({'_id': k['_id']}, {'$set': {'history': k['history'][-max_h:]}})

    return "categories: %s <br/>reindexed %s knowls<br/>pruned %s histories" % (cats, q_knowls.count(), hcount)
コード例 #2
0
ファイル: main.py プロジェクト: rpollack9974/lmfdb
def cleanup():
    """
    reindexes knowls, also the list of categories. prunes history.
    this is an internal task just for admins!
    """
    from knowl import refresh_knowl_categories, extract_cat, make_keywords, get_knowls
    cats = refresh_knowl_categories()
    knowls = get_knowls()
    q_knowls = knowls.find({}, ['content', 'title'])
    for k in q_knowls:
        kid = k['_id']
        cat = extract_cat(kid)
        search_keywords = make_keywords(k['content'], kid, k['title'])
        knowls.update({'_id': kid},
                      {"$set": {
                          'cat': cat,
                          '_keywords': search_keywords
                      }})

    hcount = 0
    # max allowed history length
    max_h = 50
    q_knowls = knowls.find({'history': {'$exists': True}}, ['history'])
    for k in q_knowls:
        if len(k['history']) <= max_h:
            continue
        hcount += 1
        knowls.update({'_id': k['_id']},
                      {'$set': {
                          'history': k['history'][-max_h:]
                      }})

    return "categories: %s <br/>reindexed %s knowls<br/>pruned %s histories" % (
        cats, q_knowls.count(), hcount)
コード例 #3
0
ファイル: main.py プロジェクト: anneschilling/lmfdb
def cleanup():
    """
    reindexes knowls, also the list of categories. prunes history.
    this is an internal task just for admins!
    """
    from knowl import refresh_knowl_categories, extract_cat, make_keywords, get_knowls

    cats = refresh_knowl_categories()
    knowls = get_knowls()
    q_knowls = knowls.find(fields=["content", "title"])
    for k in q_knowls:
        kid = k["_id"]
        cat = extract_cat(kid)
        search_keywords = make_keywords(k["content"], kid, k["title"])
        knowls.update({"_id": kid}, {"$set": {"cat": cat, "_keywords": search_keywords}})

    hcount = 0
    # max allowed history length
    max_h = 50
    q_knowls = knowls.find({"history": {"$exists": True}}, fields=["history"])
    for k in q_knowls:
        if len(k["history"]) <= max_h:
            continue
        hcount += 1
        knowls.update({"_id": k["_id"]}, {"$set": {"history": k["history"][-max_h:]}})

    return "categories: %s <br/>reindexed %s knowls<br/>pruned %s histories" % (cats, q_knowls.count(), hcount)