本文整理汇总了Python中xapian.sortable_unserialise函数的典型用法代码示例。如果您正苦于以下问题:Python sortable_unserialise函数的具体用法?Python sortable_unserialise怎么用?Python sortable_unserialise使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sortable_unserialise函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _decode_simple_value
def _decode_simple_value(field_cls, data):
"""Used to decode values in stored fields.
"""
# Overload the Integer type, cf _encode_simple_value
if issubclass(field_cls, Integer):
return int(sortable_unserialise(data))
elif issubclass(field_cls, Decimal):
return decimal(sortable_unserialise(data))
# A common field or a new field
return field_cls.decode(data)
示例2: two_range
def two_range(self, field, purpose, q):
"""Check the result of a range search which should return 2 items.
"""
r = [x for x in q.search(0, 10)]
self.assertEqual(len(r), 2)
val = xapian.sortable_unserialise(r[0].get_value("foo", "collsort"))
self.assertTrue(3 <= val)
self.assertTrue(val <= 4)
val = xapian.sortable_unserialise(r[1].get_value("foo", "collsort"))
self.assertTrue(4 <= val)
self.assertTrue(val <= 5)
示例3: group_poi
def group_poi(request):
response = {}
try:
response['status'] = 'OK'
group_type = request.GET.get('gt', 'city_code')
if group_type == 'admin_code':
admin_code_spy = xapian.ValueCountMatchSpy(1)
elif group_type == 'prov_code':
admin_code_spy = xapian.ValueCountMatchSpy(4)
else:
admin_code_spy = xapian.ValueCountMatchSpy(5)
with contextlib.closing(get_xapian_conn()) as xapian_database:
poi_query_parser = get_poi_query_parser()
poi_query_parser.set_database(xapian_database)
make_group_matches(
request, poi_query_parser, admin_code_spy, xapian_database)
group_result = {}
for value in admin_code_spy.values():
code = int(xapian.sortable_unserialise(value.term))
group_result[code] = value.termfreq
response['results'] = group_result
except BaseException as e:
logger.exception(e)
response['results'] = []
response['size'] = 0
response['status'] = 'ERROR_PARAMETERS'
return json.dumps(response, ensure_ascii=False, encoding='utf-8')
示例4: _remove_cached_items
def _remove_cached_items(self, docid=None, xapid=None):
"""Remove from the cache any items for the specified document.
The document may be specified by xappy docid, or by xapian document id.
"""
if self.cache_manager is None:
raise errors.IndexerError("CacheManager has been applied to this "
"index, but is not currently set.")
doc, xapid = self._get_xapdoc(docid, xapid)
if doc is None:
return
#print "Removing docid=%d" % xapid
# FIXME: this will only remove the hits from the set cache
# manager, if we have multiple applied caches, the others won't be
# updated. This means that currently, if multiple caches are applied
# and document removals happen, some of the caches will get out of
# date; multiple caches are therefore not really suitable for use in
# production systems - they are however useful for experimenting with
# different caching algorithms.
for value in doc.values():
base_slot = self._cache_manager_slot_start
upper_slot = self._cache_manager_slot_start + self.cache_manager.num_cached_queries()
if not (base_slot <= value.num < upper_slot):
continue
rank = int(self._cache_manager_max_hits -
xapian.sortable_unserialise(value.value))
self.cache_manager.remove_hits(
value.num - self._cache_manager_slot_start,
((rank, xapid),))
示例5: get_popcon
def get_popcon(self, doc):
""" Return a popcon value from a xapian document """
popcon_raw = doc.get_value(XapianValues.POPCON)
if popcon_raw:
popcon = xapian.sortable_unserialise(popcon_raw)
else:
popcon = 0
return popcon
示例6: single_range
def single_range(self, field, purpose, q):
"""Check the result of a range search which should return 1 item.
"""
r = [x for x in q.search(0, 10)]
self.assertEqual(len(r), 1)
val = xapian.sortable_unserialise(r[0].get_value(field, purpose))
self.assertTrue(3 <= val)
self.assertTrue(val <= 4.01)
示例7: deconvert
def deconvert(self, data):
if data is None:
return data
if self.ftype == PyFieldMeta.TYPE_LONG:
data = data or long(0)
return long(data)
elif self.ftype == PyFieldMeta.TYPE_FLOAT:
return xapian.sortable_unserialise(data)
else:
return data.decode('utf-8')
示例8: remove_cached_items
def remove_cached_items(self, iconn, doc, xapid):
#print "Removing docid=%d" % xapid
for value in doc.values():
base_slot = cache_manager_slot_start(iconn, self.id)
upper_slot = base_slot + self.num_cached_queries()
if not (base_slot <= value.num < upper_slot):
continue
rank = int(CACHE_MANAGER_MAX_HITS -
xapian.sortable_unserialise(value.value))
self.remove_hits(
value.num - base_slot,
((rank, xapid),))
示例9: extract
def extract(self, document):
if self.number:
value = document.get_value(self.number)
content_type = self._get_content_type(value)
if self._is_float_or_interger(content_type):
value = xapian.sortable_unserialise(value)
return value
return None
示例10: display_differences
def display_differences(self, ids1, ids2, name1, name2):
ids1_unique = ids1 - ids2
ids2_unique = ids2 - ids1
if ids1_unique or ids2_unique:
print "results for %s and %s differ" % (name1, name2)
if ids1_unique:
print "ids only in %s: " % name1, ids1_unique
if ids2_unique:
print "ids only in %s: " % name2, ids2_unique
for i in ids1 ^ ids2:
d = self.sconn.get_document(i)
print "value: ", xapian.sortable_unserialise(d.get_value('price', 'collsort'))
print "termlist: ", map (lambda t: t.term, d._doc.termlist())
示例11: doc2dict
def doc2dict(doc):
od = OrderedDict()
url = doc.get_value(VALUE_URL)
od['url'] = url
title = doc.get_value(VALUE_TITLE)
if title:
od['title'] = title.decode('UTF-8')
tags = doc.get_value(VALUE_TAGS)
od['tags'] = tags.decode('UTF-8').split(u'\x1f') if tags else []
created = xapian.sortable_unserialise(doc.get_value(VALUE_CREATED))
od['created'] = arrow.get(created)
archived_val = doc.get_value(VALUE_ARCHIVED)
if archived_val:
archived = xapian.sortable_unserialise(archived_val)
od['archived'] = arrow.get(archived)
od['notes'] = doc.get_data().decode('UTF-8')
return od
示例12: _generate_records
def _generate_records(self, mset, select=set(["*"])):
"""
仅返回item_id,item_type,外部再从memcached、db中读取详细数据
"""
for m in mset:
result = {"_did" : m.docid, "_score" : m.percent, "_rank" : m.rank, "_collapse_count" : m.collapse_count, "_weight" : m.weight}
result['item_id'] = int(xapian.sortable_unserialise(m.document.get_value(DOC_ITEM_ID))) #int
result['item_type'] = m.document.get_value(DOC_ITEM_TYPE) #string
if select:
doc = m.document
data_str = doc.get_data()
if len(data_str):
data_dict = cPickle.loads(data_str)
for key, value in data_dict.items():
if key in select or "*" in select:
result[key] = value
yield result
示例13: size
def size(self):
"""Return the size of the application without dependencies
Note that this will return the download size if the app is
not installed and the installed size if it is installed.
"""
if self._pkg:
if not self._pkg.installed:
if self._app.archive_suite:
ver = self._get_version_for_archive_suite(self._pkg, self._app.archive_suite)
if ver:
return ver.size
return self._pkg.candidate.size
else:
return self._pkg.installed.size
elif self._doc:
size = self._doc.get_value(XapianValues.DOWNLOAD_SIZE)
if size:
return xapian.sortable_unserialise(self._doc.get_value(XapianValues.DOWNLOAD_SIZE))
示例14: _remove_cached_items
def _remove_cached_items(self, docid=None, xapid=None):
"""Remove from the cache any items for the specified document.
The document may be specified by xappy docid, or by xapian document id.
"""
if self.cache_manager is None:
raise errors.IndexerError("CacheManager has been applied to this "
"index, but is not currently set.")
doc, xapid = self._get_xapdoc(docid, xapid)
if doc is None:
return
#print "Removing docid=%d" % xapid
for value in doc.values():
if value.num < self._cache_manager_slot_start:
continue
rank = int(self._cache_manager_max_hits -
xapian.sortable_unserialise(value.value))
self.cache_manager.remove_hits(
value.num - self._cache_manager_slot_start,
((rank, xapid),))
示例15: get_weight
def get_weight(self, doc):
val = doc.get_value(self.field, self.purpose)
val = xapian.sortable_unserialise(val)
if val > self.maxval:
return self.maxval
return val