本文整理汇总了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)))