本文整理汇总了Python中schema.Schema.get_prefix方法的典型用法代码示例。如果您正苦于以下问题:Python Schema.get_prefix方法的具体用法?Python Schema.get_prefix怎么用?Python Schema.get_prefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类schema.Schema
的用法示例。
在下文中一共展示了Schema.get_prefix方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Zapian
# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import get_prefix [as 别名]
#.........这里部分代码省略.........
def _add_value(doc, slotnum, value):
if isinstance(value, float):
value = xapian.sortable_serialise(float(value))
doc.add_value(int(slotnum), value)
else:
doc.add_value(int(slotnum), str(value))
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