本文整理汇总了Python中schema.Schema.split_term方法的典型用法代码示例。如果您正苦于以下问题:Python Schema.split_term方法的具体用法?Python Schema.split_term怎么用?Python Schema.split_term使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类schema.Schema
的用法示例。
在下文中一共展示了Schema.split_term方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Zapian
# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import split_term [as 别名]
#.........这里部分代码省略.........
document = xapian.Document()
termgen = xapian.TermGenerator()
termgen.set_document(document)
terms = set()
values = set()
# build new xapian object
for field, value in doc.iteritems():
both = field.startswith('+')
if both:
field = field[1:]
is_value = isinstance(value, (int, float, datetime))
is_term = not is_value
# sortable
if both or is_value:
if field in values:
continue
slotnum = self.schema.get_slot(field)
value = clean_value(value)
_add_value(document, slotnum, value)
values.add(slotnum)
# field
if both or is_term:
if field in terms:
continue
prefix = self.schema.get_prefix(field)
value = clean_value(value)
_add_term(document, termgen, prefix, value)
terms.add(prefix)
# new value will be replace old value
if old_doc is not None:
for term in old_doc.termlist():
prefix, value = self.schema.split_term(term.term)
if prefix not in terms:
_add_term(document, termgen, prefix, value)
for value in old_doc.values():
if value.num not in values:
_add_value(document, value.num, value.value)
if data is None:
data = dict()
old_data = old_doc.get_data()
if old_data:
old_data = pickle.loads(old_data)
for k, v in old_data.iteritems():
if k not in data:
data[k] = v
# add data
if data:
document.set_data(pickle.dumps(data))
return document
def add_document(self, part_name, index, uid=None, data=None, flush=True):
""" add a xapian document
"""
db = _get_write_db(self.db_path, part_name)
doc = self.get_interior_doc(index, data=data)
if not uid:
identifier = u'Q' + part_name + str(db.get_lastdocid())
else:
identifier = u'Q' + str(uid)
doc.add_boolean_term(identifier)