本文整理汇总了Python中user_portrait.global_utils.es_user_profile.mget函数的典型用法代码示例。如果您正苦于以下问题:Python mget函数的具体用法?Python mget怎么用?Python mget使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mget函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: retweet_dict2results
def retweet_dict2results(uid, item_results):
results = []
uid_list = []
sort_list = []
sorted_list = sorted(item_results.iteritems(), key = lambda x:x[0], reverse=True)
count = 0
for key, value in sorted_list:
if (key == 'None' or key == uid):
continue
count += 1
uid_list.append(key)
sort_list.append(value)
if (count == 100):
break
# 查看背景信息
if uid_list:
profile_result = es_user_profile.mget(index=profile_index_name, doc_type=profile_index_type, body={"ids":uid_list})["docs"]
for item in profile_result:
_id = item['_id']
index = profile_result.index(item)
tmp = []
if item['found']:
item = item['_source']
tmp.append(item['uid'])
tmp.append(item['nick_name'])
else:
tmp.extend([_id,''])
value = sort_list[index]
tmp.append(value)
results.append(tmp)
return results
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:31,代码来源:utils.py
示例2: query_vary_top_k
def query_vary_top_k(index_name, doctype, top_k, sort_index="vary"):
query_body = {
"query": {
"match_all": {}
},
"size": top_k,
"sort": [{sort_index: {"order": "desc"}}]
}
result = es.search(index=index_name, doc_type=doctype, body=query_body)['hits']['hits']
uid_list = []
for item in result:
uid_list.append(item['_id'])
portrait_result = es_portrait.mget(index="user_portrait", doc_type="user", body={"ids":uid_list}, _source=True)['docs']
profile_result = es_profile.mget(index="weibo_user",doc_type="user", body={"ids":uid_list}, _source=True)['docs']
return_list = []
rank = 1
for i in range(len(result)):
info = ['','','','','']
info[0] = rank
if profile_result[i]['found']:
info[1] = profile_result[i]['_source'].get('photo_url','')
info[3] = profile_result[i]['_source'].get('nick_name','')
info[2] = result[i].get('_id','')
info[4] = result[i]['_source']['vary']
if portrait_result[i]['found']:
info.append('1')
else:
info.append('0')
return_list.append(info)
rank += 1
return return_list
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:35,代码来源:search_vary_index_function.py
示例3: retweet_dict2results
def retweet_dict2results(uid, item_results):
results = []
uid_list = []
sort_list = []
for key in item_results:
if (key == uid):
continue
uid_list.append(key)
sort_list.append(item_results[key])
# 查看背景信息
if uid_list:
profile_result = es_user_profile.mget(index=profile_index_name, doc_type=profile_index_type, body={"ids":uid_list})["docs"]
for item in profile_result:
_id = item['_id']
index = profile_result.index(item)
tmp = []
if item['found']:
item = item['_source']
tmp.append(item['uid'])
tmp.append(item['nick_name'])
else:
tmp.extend([_id,''])
value = sort_list[index]
tmp.append(value)
results.append(tmp)
return results
开发者ID:jianjian0dandan,项目名称:user_portrait_0324,代码行数:27,代码来源:utils.py
示例4: get_user_profile_weibo
def get_user_profile_weibo(user_list):
user_info_dict = {}
try:
user_profile_dict = es_user_profile.mget(index=profile_index_name, doc_type=profile_index_type, \
body={'ids': user_list})['docs']
except:
user_profile_dict = []
if user_profile_dict:
for user_dict in user_profile_dict:
if user_dict['found'] == True:
source = user_dict['_source']
source_dict['uid'] = source['uid']
source_dict['uname'] = source['nick_name']
source_dict['location'] = source['location']
source_dict['photo_url'] = source['photo_url']
source_dict['fansnum'] = source['fansnum']
source_dict['friendsnum'] = source['friendsnum']
source_dict['statusnum'] = source['statusnum']
source_dict['description'] = source['description']
else:
source_dict['uid'] = source['uid']
source_dict['uname'] = 'unknown'
source_dict['location'] = 'unknown'
source_dict['photo_url'] = ''
source_dict['fansnum'] = 0
source_dict['friendsnum'] = 0
source_dict['statusnum'] = 0
source_dict['description'] = ''
user_info_dict[user_dict['_id']] = source_dict
return user_info_dict
开发者ID:huxiaoqian,项目名称:revised_user_portrait,代码行数:31,代码来源:new_search.py
示例5: get_user_detail
def get_user_detail(date, input_result, status):
results = []
if status=='show_in':
uid_list = input_result
if status=='show_compute':
uid_list = input_result.keys()
if status=='show_in_history':
uid_list = input_result.keys()
if date!='all':
index_name = 'bci_' + ''.join(date.split('-'))
else:
now_ts = time.time()
now_date = ts2datetime(now_ts)
index_name = 'bci_' + ''.join(now_date.split('-'))
index_type = 'bci'
user_bci_result = es_cluster.mget(index=index_name, doc_type=index_type, body={'ids':uid_list}, _source=True)['docs']
user_profile_result = es_user_profile.mget(index='weibo_user', doc_type='user', body={'ids':uid_list}, _source=True)['docs']
max_evaluate_influ = get_evaluate_max(index_name)
for i in range(0, len(uid_list)):
uid = uid_list[i]
bci_dict = user_bci_result[i]
profile_dict = user_profile_result[i]
try:
bci_source = bci_dict['_source']
except:
bci_source = None
if bci_source:
influence = bci_source['user_index']
influence = math.log(influence/max_evaluate_influ['user_index'] * 9 + 1 ,10)
influence = influence * 100
else:
influence = ''
try:
profile_source = profile_dict['_source']
except:
profile_source = None
if profile_source:
uname = profile_source['nick_name']
location = profile_source['user_location']
fansnum = profile_source['fansnum']
statusnum = profile_source['statusnum']
else:
uname = ''
location = ''
fansnum = ''
statusnum = ''
if status == 'show_in':
results.append([uid, uname, location, fansnum, statusnum, influence])
if status == 'show_compute':
in_date = json.loads(input_result[uid])[0]
compute_status = json.loads(input_result[uid])[1]
if compute_status == '1':
compute_status = '3'
results.append([uid, uname, location, fansnum, statusnum, influence, in_date, compute_status])
if status == 'show_in_history':
in_status = input_result[uid]
results.append([uid, uname, location, fansnum, statusnum, influence, in_status])
return results
开发者ID:huxiaoqian,项目名称:user_portrait,代码行数:59,代码来源:utils.py
示例6: search_portrait_user_in_activity
def search_portrait_user_in_activity(es, number, active_index, active_type, portrait_index, portrait_type, field="user_index"):
return_list = []
index_exist = es.indices.exists(index=active_index)
if not index_exist:
return "no active_index exist"
sys.exit(0)
count_s = 0
count_c = 0
start = 0
rank = 1
while 1:
search_list = []
user_list = search_k(es, active_index, active_type, start, field, 100)
start += 100
for item in user_list:
if field == "vary":
uid = item.get('uid', '0') # obtain uid, notice "uid" or "user"
else:
uid = item.get('user', '0')
search_list.append(uid) # uid list
search_result = es_portrait.mget(index=portrait_index, doc_type=portrait_type, body={"ids": search_list}, _source=True)["docs"]
profile_result = es_profile.mget(index="weibo_user", doc_type="user", body={"ids": search_list}, _source=True)["docs"]
key_list = ["origin_weibo_retweeted_total_number", "origin_weibo_retweeted_average_number", "origin_weibo_retweeted_top_number", "origin_weibo_retweeted_brust_average", \
"origin_weibo_comment_total_number", "origin_weibo_comment_average_number", "origin_weibo_comment_top_number", "origin_weibo_retweeted_brust_average", \
"retweeted_weibo_retweeted_total_number", "retweeted_weibo_retweeted_average_number", "retweeted_weibo_retweeted_top_number", "retweeted_weibo_retweeted_brust_average", \
"retweeted_weibo_comment_total_number", "retweeted_weibo_comment_average_number", "retweeted_weibo_comment_top_number", "retweeted_weibo_retweeted_brust_average"]
for item in search_result:
if item["found"]:
info = ['','','','','','']
info[0] = rank
index = search_result.index(item)
if profile_result[index]['found']:
info[1] = profile_result[index]['_source'].get('photo_url','')
info[3] = profile_result[index]['_source'].get('nick_name','')
info[2] = search_result[index].get('_id','')
info[4] = user_list[index]['user_index']
info[5] = "1"
if field == 'origin_weibo_retweeted_brust_average':
info.append(user_list[index]['origin_weibo_retweeted_brust_average'])
for key in key_list:
info.append(user_list[index][key])
elif field == 'origin_weibo_comment_brust_average':
info.append(user_list[index]['origin_weibo_comment_brust_average'])
for key in key_list:
info.append(user_list[index][key])
else:
pass
return_list.append(info)
rank += 1
count_c += 1
if count_c >= int(number):
return return_list
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:58,代码来源:rank_portrait_in_active_user.py
示例7: get_recommentation
def get_recommentation(submit_user):
if RUN_TYPE:
now_ts = time.time()
else:
now_ts = datetime2ts(RUN_TEST_TIME)
in_portrait_set = set(r.hkeys("compute"))
result = []
for i in range(7):
iter_ts = now_ts - i*DAY
iter_date = ts2datetime(iter_ts)
submit_user_recomment = "recomment_" + submit_user + "_" + str(iter_date)
bci_date = ts2datetime(iter_ts - DAY)
submit_user_recomment = r.hkeys(submit_user_recomment)
bci_index_name = "bci_" + bci_date.replace('-', '')
exist_bool = es_cluster.indices.exists(index=bci_index_name)
if not exist_bool:
continue
if submit_user_recomment:
user_bci_result = es_cluster.mget(index=bci_index_name, doc_type="bci", body={'ids':submit_user_recomment}, _source=True)['docs']
user_profile_result = es_user_profile.mget(index='weibo_user', doc_type='user', body={'ids':submit_user_recomment}, _source=True)['docs']
max_evaluate_influ = get_evaluate_max(bci_index_name)
for i in range(len(submit_user_recomment)):
uid = submit_user_recomment[i]
bci_dict = user_bci_result[i]
profile_dict = user_profile_result[i]
try:
bci_source = bci_dict['_source']
except:
bci_source = None
if bci_source:
influence = bci_source['user_index']
influence = math.log(influence/max_evaluate_influ['user_index'] * 9 + 1 ,10)
influence = influence * 100
else:
influence = ''
try:
profile_source = profile_dict['_source']
except:
profile_source = None
if profile_source:
uname = profile_source['nick_name']
location = profile_source['user_location']
fansnum = profile_source['fansnum']
statusnum = profile_source['statusnum']
else:
uname = ''
location = ''
fansnum = ''
statusnum = ''
if uid in in_portrait_set:
in_portrait = "1"
else:
in_portrait = "0"
recomment_day = iter_date
result.append([iter_date, uid, uname, location, fansnum, statusnum, influence, in_portrait])
return result
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:58,代码来源:utils.py
示例8: show_keywords_rank
def show_keywords_rank(task_id, sort_type, count):
try:
task_found = es_network_task.get(index=network_keywords_index_name, \
doc_type=network_keywords_index_type, id=task_id)['_source']
except:
task_found = {}
return task_found
search_results = json.loads(task_found['results'])
sort_results = search_results[sort_type]
results = []
uid_list = []
sort_list = []
for source_uid, sort_value in sort_results:
uid_list.append(source_uid)
sort_list.append(sort_value)
# 查看背景信息
if uid_list:
profile_result = es_user_profile.mget(index=profile_index_name, doc_type=profile_index_type, body={"ids":uid_list})["docs"]
for item in profile_result:
_id = item['_id']
index = profile_result.index(item)
tmp = []
if item['found']:
item = item['_source']
tmp.append(item['uid'])
tmp.append(item['nick_name'])
tmp.append(item['user_location'])
else:
tmp.extend([_id,'',''])
value = sort_list[index]
tmp.append(value)
results.append(tmp)
if uid_list:
count = 0
history_result = es_bci_history.mget(index=bci_history_index_name, doc_type=bci_history_index_type, body={"ids":uid_list})["docs"]
for item in history_result:
if item['found']:
item = item['_source']
results[count].extend([item['user_fansnum'], item['weibo_month_sum']])
else:
results[count].extend(['',''])
count += 1
if uid_list:
count = 0
portrait_result = es_user_portrait.mget(index=portrait_index_name, doc_type=portrait_index_type, body={"ids":uid_list})["docs"]
for item in portrait_result:
if item['found']:
results[count].append("1")
else:
results[count].append("0")
count += 1
return results
开发者ID:huxiaoqian,项目名称:user_portrait_ending2,代码行数:57,代码来源:utils.py
示例9: search_top_index
def search_top_index(index_name, top_k=1, index_type="bci", top=False, sort_order="user_index"):
query_body = {
"query": {
"match_all": {}
},
"size": top_k,
"sort": [{sort_order: {"order": "desc"}}]
}
if top:
result = es.search(index=index_name, doc_type=index_type, body=query_body)['hits']['hits'][0]['_source'][sort_order]
else:
search_result = es.search(index=index_name, doc_type=index_type, body=query_body)['hits']['hits']
uid_list = []
for item in search_result:
uid_list.append(item['_id'])
profile_result = es_profile.mget(index="weibo_user",doc_type="user", body={"ids":uid_list}, _source=True)['docs']
portrait_result = es_portrait.mget(index="user_portrait", doc_type="user", body={"ids":uid_list}, _source=True)['docs']
result = []
rank = 1
for i in range(len(search_result)):
info = ['','','','']
info[0] = rank
if profile_result[i]['found']:
info[1] = profile_result[i]['_source'].get('photo_url','')
info[3] = profile_result[i]['_source'].get('nick_name','')
info[2] = search_result[i].get('_id','')
if sort_order in ["user_index","origin_weibo_retweeted_brust_average","origin_weibo_comment_brust_average"]:
info.append(search_result[i]['_source'][sort_order])
if portrait_result[i]['found']:
info.append("1")
else:
info.append("0")
elif sort_order == "origin_weibo_retweeted_top_number":
info.append(search_result[i]['_source']['origin_weibo_retweeted_top_number'])
mid = search_result[i]['_source']['origin_weibo_top_retweeted_id']
info.append(weiboinfo2url(info[2],mid))
if portrait_result[i]['found']:
info.append("1")
else:
info.append("0")
elif sort_order == "origin_weibo_comment_top_number":
info.append(search_result[i]['_source']['origin_weibo_comment_top_number'])
mid = search_result[i]['_source']['origin_weibo_top_comment_id']
info.append(weiboinfo2url(info[2],mid))
if portrait_result[i]['found']:
info.append("1")
else:
info.append("0")
rank += 1
result.append(info)
return result
开发者ID:ztybuaa,项目名称:user_portrait,代码行数:57,代码来源:search_user_index_function.py
示例10: show_daily_rank
def show_daily_rank(period, sort_type, count):
index_name = 'user_portrait_network'
index_type = 'network'
if (len(sort_type.split('_')) > 1):
sort = 'rank_' + sort_type + '_' + str(period) #pr_0
else:
sort = sort_type + '_' + str(period) #pr_0
query_body = {
'sort':[{sort:{'order': 'desc'}}],
'size': count
}
try:
search_results = es_network_task.search(index=index_name, doc_type=index_type, body=query_body)['hits']['hits']
except:
search_results = []
results = []
uid_list = []
sort_list = []
for item in search_results:
source = item['_source']
if sort in source:
uid_list.append(source['uid'])
sort_list.append(source[sort])
# 查看背景信息
if uid_list:
profile_result = es_user_profile.mget(index=profile_index_name, doc_type=profile_index_type, body={"ids":uid_list})["docs"]
for item in profile_result:
_id = item['_id']
index = profile_result.index(item)
tmp = []
if item['found']:
item = item['_source']
tmp.append(item['uid'])
tmp.append(item['nick_name'])
tmp.append(item['statusnum'])
tmp.append(item['user_location'])
tmp.append(item['fansnum'])
else:
tmp.extend([_id,'','','',''])
value = sort_list[index]
tmp.append(value)
results.append(tmp)
if uid_list:
count = 0
portrait_result = es_user_portrait.mget(index=portrait_index_name, doc_type=portrait_index_type, body={"ids":uid_list})["docs"]
for item in portrait_result:
if item['found']:
results[count].append("1")
else:
results[count].append("0")
count += 1
return results
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:56,代码来源:utils.py
示例11: search_max_single_field
def search_max_single_field(field, index_name, doctype, top_k=3):
# field = "origin_weibo_retweeted_top_number", "origin_weibo_comment_top_number"
query_body = {
"query": {
"match_all": {}
},
"sort": [{field: {"order": "desc"}}],
"size": top_k
}
return_list = []
rank = 1
count_c = 0
start = 0
while 1:
search_list = []
user_list = search_k(es, index_name, doctype, start, field, 100)
start += 100
for item in user_list:
uid = item.get('user','0')
search_list.append(uid) # uid list
search_result = es_portrait.mget(index="user_portrait", doc_type="user", body={"ids": search_list}, _source=True)["docs"]
profile_result = es_profile.mget(index="weibo_user", doc_type="user", body={"ids": search_list}, _source=True)["docs"]
for i in range(len(search_result)):
if search_result[i]['found']:
info = ['','','','','','','1']
info[0] = rank
info[2] = search_result[i].get('_id','')
if profile_result[i]['found']:
info[1] = profile_result[i]['_source'].get('photo_url','')
info[3] = profile_result[i]['_source'].get('nick_name','')
if 'retweeted' in field:
temp_mid = user_list[i]['origin_weibo_top_retweeted_id']
info[5] = weiboinfo2url(info[2], temp_mid)
info[4] = user_list[i]['origin_weibo_retweeted_top_number']
else:
temp_mid = user_list[i]['origin_weibo_top_comment_id']
info[5] = weiboinfo2url(info[2], temp_mid)
info[4] = user_list[i]['origin_weibo_comment_top_number']
rank += 1
return_list.append(info)
if rank >= int(top_k)+1:
return return_list
开发者ID:ztybuaa,项目名称:user_portrait,代码行数:52,代码来源:search_user_index_function.py
示例12: identify_user_out
def identify_user_out(input_uid_list):
out_user_list = []
in_user_list = []
input_len = len(input_uid_list)
iter_count = 0
print 'identify user out'
#get user list who is out user_portrait
while iter_count < input_len:
iter_user_list = input_uid_list[iter_count: iter_count+DETECT_ITER_COUNT]
try:
portrait_result = es_user_portrait.mget(index=portrait_index_name, doc_type=portrait_index_type, body={'ids':iter_user_list}, _source=False)['docs']
except:
portrait_result = []
for item in portrait_result:
uid = item['_id']
if item['found'] != True:
out_user_list.append(uid)
else:
in_user_list.append(uid)
iter_count += DETECT_ITER_COUNT
print 'get out user portrait information'
#get user profile information for out user_portrait
iter_count = 0
out_user_count = len(out_user_list)
out_user_result = []
while iter_count < out_user_count:
iter_user_list = out_user_list[iter_count: iter_count+DETECT_ITER_COUNT]
try:
profile_result = es_user_profile.mget(index=profile_index_name, doc_type=profile_index_type, body={'ids':iter_user_list}, _source=True)['docs']
except:
profile_result = []
for item in profile_result:
uid = item['_id']
if item['found']==True:
source = item['_source']
uname = source['nick_name']
fansnum = source['fansnum']
statusnum = source['statusnum']
friendsnum = source['friendsnum']
else:
uname = u'未知'
fansnum = u'未知'
statusnum = u'未知'
friendsnum = u'未知'
out_user_result.append([uid, uname, fansnum, statusnum, friendsnum])
iter_count += DETECT_ITER_COUNT
sort_out_user_result = sorted(out_user_result, key=lambda x:x[2], reverse=True)
return in_user_list, sort_out_user_result
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:50,代码来源:utils.py
示例13: compare_user_profile
def compare_user_profile(uid_list):
results = {}
index_name = 'weibo_user'
index_type = 'user'
search_results = es_user_profile.mget(index=index_name, doc_type=index_type, body={'ids':uid_list})['docs']
#print 'results:', search_results
for result in search_results:
uid = result['_id']
results[uid] = []
try:
item = result['_source']
except:
next
photo_url = item['photo_url']
results[uid] = photo_url
#print 'results:', results
return results
开发者ID:taozhiiq,项目名称:user_portrait,代码行数:17,代码来源:utils.py
示例14: portrait_user_vary
def portrait_user_vary(es, number, active_index, active_type, portrait_index, portrait_type, field="vary"):
return_list = []
index_exist = es.indices.exists(index=active_index)
if not index_exist:
return "no active_index exist"
sys.exit(0)
count_s = 0
count_c = 0
start = 0
rank = 1
try:
while 1:
search_list = []
user_list = search_k(es, active_index, active_type, start, field, 100)
start += 100
for item in user_list:
uid = item.get('uid', '0') # obtain uid, notice "uid" or "user"
search_list.append(uid) # uid list
search_result = es_portrait.mget(index="user_portrait", doc_type="user", body={"ids": search_list}, _source=True)["docs"]
profile_result = es_profile.mget(index="weibo_user", doc_type="user", body={"ids": search_list}, _source=True)["docs"]
for item in search_result:
count_c += 1
if item["found"]:
info = ['','','','','','1']
info[0] = rank
index = search_result.index(item)
if profile_result[index]['found']:
info[1] = profile_result[index]['_source'].get('photo_url','')
info[3] = profile_result[index]['_source'].get('nick_name','')
info[2] = search_result[index].get('_id','')
info[4] = user_list[index]['vary']
return_list.append(info)
rank += 1
if rank == int(number)+1:
return return_list
if count_c > 10000:
break
except RequestError:
print "timeout"
return return_list
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:46,代码来源:rank_portrait_in_active_user.py
示例15: get_user_url
def get_user_url(uid_list):
results = []
try:
es_results = es_profile.mget(index=profile_index_name, doc_type=profile_index_type, body={"ids": uid_list})['docs']
except:
es_results = {}
for item in es_results:
temp = []
if item['found']:
temp.append(item['_source']["photo_url"])
temp.append(item['_source']['nick_name'])
temp.append(item['_id'])
else:
temp.append("unknown")
temp.append("unknown")
temp.append(item['_id'])
results.append(temp)
return results
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:18,代码来源:personal_influence.py
示例16: search_attention
def search_attention(uid):
stat_results = dict()
results = dict()
for db_num in R_DICT:
r = R_DICT[db_num]
ruid_results = r.hgetall('retweet_'+str(uid))
if ruid_results:
for ruid in ruid_results:
if ruid != uid:
try:
stat_results[ruid] += ruid_results[ruid]
except:
stat_results[ruid] = ruid_results[ruid]
# print 'results:', stat_results
if not results:
return [None, 0]
try:
sort_state_results = sorted(stat_results.items(), key=lambda x:x[1], reverse=True)[:20]
except:
return [None, 0]
print 'sort_state_results:', sort_state_results
uid_list = [item[0] for item in sort_state_results]
es_profile_results = es_user_profile.mget(index='weibo_user', doc_type='user', body={'ids':uid_list})['docs']
es_portrait_results = es_user_portrait.mget(index='user_portrait', doc_type='user', body={'ids':uid_list})['docs']
result_list = []
for i in range(len(es_profile_results)):
item = es_profile_results[i]
uid = item['_id']
try:
source = item['_source']
uname = source['nick_name']
except:
uname = u'未知'
# identify uid is in the user_portrait
portrait_item = es_portrait_results[i]
try:
source = portrait_item[i]
in_status = 1
except:
in_status = 0
result_list.append([uid,[uname, stat_results[uid], in_status]])
return [result_list[:20], len(stat_results)]
开发者ID:ztybuaa,项目名称:user_portrait,代码行数:44,代码来源:search.py
示例17: search_tag
def search_tag(es, number, active_index, active_type, portrait_index, portrait_type, field_dict):
#field_dict = {"domain":"art"}
return_list = []
count_s = 0
count_c = 0
start = 0
rank = 1
while 1:
search_list = []
user_list = search_k(es, active_index, active_type, start, "user_index", 1000)
start += 1000
for item in user_list:
uid = item.get('user', '0')
search_list.append(uid) # uid list
search_result = es_portrait.mget(index=portrait_index, doc_type=portrait_type, body={"ids": search_list}, _source=True)["docs"]
profile_result = es_profile.mget(index="weibo_user", doc_type="user", body={"ids": search_list}, _source=True)["docs"]
for item in search_result:
count_s += 1
if item['found'] and field_dict.values()[0] in item['_source'][field_dict.keys()[0]]:
info = ['','','','','','','']
info[0] = rank
index = search_result.index(item)
if profile_result[index]['found']:
info[1] = profile_result[index]['_source'].get('photo_url','')
info[3] = profile_result[index]['_source'].get('nick_name','')
info[2] = search_result[index].get('_id','')
info[4] = user_list[index]['user_index']
info[5] = search_result[index]['_source'].get('activeness','')
info[6] = search_result[index]['_source'].get('importance','')
rank += 1
return_list.append(info)
if rank >= int(number)+1:
return return_list
if count_s > 10000:
return return_list
开发者ID:taozhiiq,项目名称:user_portrait,代码行数:43,代码来源:search_tag_in_portrait.py
示例18: compare_user_profile
def compare_user_profile(uid_list):
results = {}
search_results = es_user_profile.mget(index=profile_index_name, doc_type=profile_index_type,\
body={'ids':uid_list})['docs']
for result in search_results:
uid = result['_id']
results[uid] = []
try:
item = result['_source']
except:
item = {}
try:
photo_url = item['photo_url']
except:
photo_url = 'unkown'
results[uid] = photo_url
return results
开发者ID:huxiaoqian,项目名称:user_portrait,代码行数:19,代码来源:utils.py
示例19: search_follower
def search_follower(uid):
results = dict()
stat_results = dict()
for db_num in R_DICT:
r = R_DICT[db_num]
br_uid_results = r.hgetall('be_retweet_'+str(uid))
if br_uid_results:
for br_uid in br_uid_results:
if br_uid != uid:
try:
stat_results[br_uid] += br_uid_results[br_uid]
except:
stat_results[br_uid] = br_uid_results[br_uid]
if not stat_results:
return [None, 0]
try:
sort_stat_results = sorted(stat_results.items(), key=lambda x:x[1], reverse=True)[:20]
except:
return [None, 0]
uid_list = [item[0] for item in sort_stat_results]
es_profile_results = es_user_profile.mget(index='weibo_user', doc_type='user', body={'ids':uid_list})['docs']
es_portrait_results = es_user_portrait.mget(index='user_portrait', doc_type='user', body={'ids':uid_list})['docs']
result_list = []
for i in range(len(es_profile_results)):
item = es_profile_results[i]
uid = item['_id']
try:
source = item['_source']
uname = source['nick_name']
except:
uname = u'未知'
portrait_item = es_portrait_results[i]
try:
source = portrait_item['_source']
in_status = 1
except:
in_status = 0
result_list.append([uid,[uname, stat_results[uid], in_status]])
return [result_list[:20], len(stat_results)]
开发者ID:ztybuaa,项目名称:user_portrait,代码行数:41,代码来源:search.py
示例20: get_sensitive_weibo_detail
def get_sensitive_weibo_detail(ts, social_sensors, sensitive_words_list, message_type, size=100):
results = []
query_body = {
"query":{
"filtered":{
"filter":{
"bool":{
"must":[
{"range":{
"timestamp":{
"gte": ts - time_interval,
"lt": ts
}
}},
{"term": {"message_type": message_type}},
{"terms":{"keywords_string": sensitive_words_list}}
]
}
}
}
},
"size": size,
"sort": {"timestamp": {"order": "desc"}}
}
if social_sensors:
query_body['query']['filtered']['filter']['bool']['must'].append({"terms": {"uid": social_sensors}})
datetime = ts2datetime(ts)
datetime_1 = ts2datetime(ts-time_interval)
index_name = flow_text_index_name_pre + datetime
exist_es = es_text.indices.exists(index_name)
index_name_1 = flow_text_index_name_pre + datetime_1
exist_es_1 = es_text.indices.exists(index_name_1)
if datetime == datetime_1 and exist_es:
search_results = es_text.search(index=index_name, doc_type=flow_text_index_type, body=query_body)["hits"]["hits"]
elif datetime != datetime_1 and exist_es_1:
search_results = es_text.search(index=index_name_1, doc_type=flow_text_index_type, body=query_body)["hits"]["hits"]
else:
search_results = []
uid_list = []
if search_results:
for item in search_results:
uid_list.append(item["_source"]['uid'])
if uid_list:
portrait_result = es_profile.mget(index=profile_index_name, doc_type=profile_index_type, body={"ids":uid_list}, fields=['nick_name', 'photo_url'])["docs"]
for i in range(len(uid_list)):
item = search_results[i]['_source']
temp = []
# uid, nick_name, photo_url, text, sentiment, timestamp, geo, common_keywords, message_type
temp.append(item['uid'])
if portrait_result[i]['found']:
temp.append(portrait_result[i]["fields"]["nick_name"][0])
temp.append(portrait_result[i]["fields"]["photo_url"][0])
else:
temp.append("unknown")
temp.append("")
temp.append(item["text"])
#print item['text']
temp.append(item["sentiment"])
temp.append(ts2date(item['timestamp']))
temp.append(item['geo'])
keywords_set = set(item['keywords_string'].split('&'))
common_keywords = set(sensitive_words_list) & keywords_set
temp.append(list(common_keywords))
temp.append(item['message_type'])
results.append(temp)
return results
开发者ID:huxiaoqian,项目名称:user_portrait,代码行数:72,代码来源:full_text_serach.py
|
请发表评论