当前位置: 首页>>代码示例>>Python>>正文


Python Autocompleter.create_instances_to_be_saved方法代码示例

本文整理汇总了Python中autocompleter.Autocompleter.create_instances_to_be_saved方法的典型用法代码示例。如果您正苦于以下问题:Python Autocompleter.create_instances_to_be_saved方法的具体用法?Python Autocompleter.create_instances_to_be_saved怎么用?Python Autocompleter.create_instances_to_be_saved使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在autocompleter.Autocompleter的用法示例。


在下文中一共展示了Autocompleter.create_instances_to_be_saved方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: save_consolidated_autocomplete_data

# 需要导入模块: from autocompleter import Autocompleter [as 别名]
# 或者: from autocompleter.Autocompleter import create_instances_to_be_saved [as 别名]
def save_consolidated_autocomplete_data(data_slice, offset):
    consolidated_records = _ConsolidationHashMap.query().fetch(1000)
    consolidated_books = {}
    for rec in consolidated_records:
        consolidated_books.update(rec.hashmap)
    logging.info("Running save subprocess for {} records, offset={}. "
                 "consolidated_books={}".format(
        len(data_slice), offset, len(consolidated_books)
    ))
    autocompleter = Autocompleter()
    docs = []
    records = []
    for book_hash in consolidated_books:
        book = consolidated_books[book_hash]
        # assert isinstance(book, tuple)
        assert len(book) == 3
        index = book[0] - offset
        if not (0 <= index < len(data_slice)):
            continue  # not found in slice - a sibling process will take care of this
        row = data_slice[index]
        year = None
        try:
            year = int(unicode(row[3]))
        except:
            pass
        doc, record = Autocompleter.create_instances_to_be_saved(
            book[1],  # item_ids
            row[1],  # author
            row[2],  # title
            year,  # year
            book[2]  # count
        )
        docs.append(doc)
        if len(docs) >= 200:
            autocompleter.index.put(docs)
            logging.info("{} docs were put into index".format(len(docs)))
            docs = []
        records.append(record)
        if len(records) >= 200:
            ndb.put_multi(records)
            logging.info(
                "{} records were put into storage".format(len(records)))
            records = []
    autocompleter.index.put(docs)
    logging.info("{} docs were put into index".format(len(docs)))
    ndb.put_multi(records)
    logging.info("{} records were put into storage".format(len(records)))
开发者ID:gdg-garage,项目名称:knihovna-db,代码行数:49,代码来源:admin.py


注:本文中的autocompleter.Autocompleter.create_instances_to_be_saved方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。