def compare_group_user(g_name1, g_name2, submit_user, flag): if flag == 'all': detail_result1 = query_detail_group(g_name1, submit_user) detail_result2 = query_detail_group(g_name2, submit_user) return {'detail_result1':detail_result1,'detail_result2':detail_result2} else: topic_id1 = p.get_pinyin(g_name1) topic_id1 = topic_id1.lower() eid_string1 = es_group.get(index=group_name, doc_type=group_type, id=topic_id1, fields=['people']) event_list1 = eid_string1['fields']['people'][0].split('&') topic_id2 = p.get_pinyin(g_name2) topic_id2 = topic_id2.lower() eid_string2 = es_group.get(index=group_name, doc_type=group_type, id=topic_id2, fields=['people']) event_list2 = eid_string2['fields']['people'][0].split('&') if flag == 'same': same_e = set(event_list1)&set(event_list2) same_e = [i for i in same_e] detail_result1 = user_detail_search(same_e,submit_user) detail_result2 = user_detail_search(same_e,submit_user) if flag == 'diff': diff_e1 = set(event_list1) - (set(event_list1)&set(event_list2)) diff_e1 = [i for i in diff_e1] diff_e2 = set(event_list2) - (set(event_list1)&set(event_list2)) diff_e2 = [i for i in diff_e2] detail_result1 = user_detail_search(diff_e1,submit_user) detail_result2 = user_detail_search(diff_e2,submit_user) return {'detail_result1':detail_result1,'detail_result2':detail_result2}
def search_related_u_auto(g_name, submit_user): group_id = p.get_pinyin(g_name) group_id = group_id.lower() uid_string = es_group.get(index=group_name, doc_type=group_type, id=group_id, fields=['people']) uid_list = uid_string['fields']['people'][0].split('&') related_list = [] for en_name in uid_list: s_string = 'START s0 = node:node_index(uid="%s") \ MATCH (s0)-[r]-(s3:User) return s3' % (en_name) print s_string result = graph.run(s_string) for item in result: item_dict = dict(item) related_list.append(item_dict['s3']['uid']) for en_name in uid_list: s_string = 'START s0 = node:node_index(uid="%s") \ MATCH (s0)-[r]-(s3:Org) return s3' % (en_name) print s_string result = graph.run(s_string) for item in result: item_dict = dict(item) related_list.append( item_dict['s3']['org_id']) # print uid_list, '---------' related_list = set(related_list) - set(uid_list) related_list = [i for i in related_list] print related_list, '---------' result = user_detail_search(related_list, submit_user) return result
def query_detail_group(g_name, submit_user): group_id = p.get_pinyin(g_name) group_id = group_id.lower() try: uid_string = es_group.get(index=group_name, doc_type=group_type, id=group_id, fields=['people']) except: return 0 uid_list = uid_string['fields']['people'][0].split('&') # result = uid_list result = user_detail_search(uid_list, submit_user) #后面加!! return result
def compare_theme_user(theme_name1, theme_name2, submit_user, flag): topic_id1 = p.get_pinyin(theme_name1) topic_id1 = topic_id1.lower() eid_string1 = es_event.get(index=special_event_name, doc_type=special_event_type, id=topic_id1, fields=['event']) event_list1 = eid_string1['fields']['event'][0].split('&') topic_id2 = p.get_pinyin(theme_name2) topic_id2 = topic_id2.lower() eid_string2 = es_event.get(index=special_event_name, doc_type=special_event_type, id=topic_id2, fields=['event']) event_list2 = eid_string2['fields']['event'][0].split('&') event_list_all = [event_list1, event_list2] uid_list = [] for event_result in event_list_all: uid_list1 = [] print event_result for event in event_result: event_value = event # event_list.append(event_value) c_string = 'START s0 = node:event_index(event_id="' + str( event_value) + '") ' c_string += 'MATCH (s0)-[r]-(s1:User) return s1 LIMIT 50' print c_string result = graph.run(c_string) for i in list(result): end_id = dict(i['s1']) uid_list1.append(end_id['uid']) uid_list.append(uid_list1) # return uid_list ##对于实际的人怎么处理? if flag == 'all': uid_list1 = [i for i in set(uid_list[0])] uid_list2 = [i for i in set(uid_list[1])] detail_result1 = user_detail_search(uid_list1, submit_user) detail_result2 = user_detail_search(uid_list2, submit_user) if flag == 'same': same_u = set(uid_list[0]) & set(uid_list[1]) same_u = [i for i in same_u] detail_result1 = user_detail_search(same_u, submit_user) detail_result2 = user_detail_search(same_u, submit_user) if flag == 'diff': diff_u1 = set(uid_list[0]) - (set(uid_list[0]) & set(uid_list[1])) diff_u1 = [i for i in diff_u1] diff_u2 = set(uid_list[1]) - (set(uid_list[0]) & set(uid_list[1])) diff_u2 = [i for i in diff_u2] detail_result1 = user_detail_search(diff_u1, submit_user) detail_result2 = user_detail_search(diff_u2, submit_user) return {'detail_result1': detail_result1, 'detail_result2': detail_result2}
def search_related_u_auto(g_name, submit_user): group_id = p.get_pinyin(g_name) group_id = group_id.lower() uid_string = es_group.get(index=group_name, doc_type=group_type, id=group_id, fields=['people']) uid_list = uid_string['fields']['people'][0].split('&') related_list = [] user_list,org_list = search_user_type(uid_list) indx_id_list = [] for i in user_list: a = graph.run('start n=node:'+node_index_name+'("'+people_primary+':'+str(i)+'") return id(n)') for j in a: indx_id_list.append(str(dict(j)['id(n)'])) for i in org_list: a = graph.run('start n=node:'+org_index_name+'("'+org_primary+':'+str(i)+'") return id(n)') for j in a: indx_id_list.append(str(dict(j)['id(n)'])) event_id_string = ','.join(indx_id_list) query = 'start d=node('+event_id_string+') match (d)-[r]-(e) where labels(e)[0] in '+json.dumps(['User', 'Org'])+' return e, labels(e)' print query result = graph.run(query) node_dict = {} related_list = [] for i in result: dict_i = dict(i) print dict_i node_type = dict_i['labels(e)'][0] if node_type == people_node: node_id = dict_i['e']['uid'] related_list.append(node_id) elif node_type == org_node: node_id = dict_i['e']['org_id'] related_list.append(node_id) related_list = set(related_list) - set(uid_list) related_list = [i for i in related_list] print related_list,'---------' result = user_detail_search(related_list, submit_user) return result