当前位置: 首页>>代码示例>>Python>>正文


Python es_user_portrait.search函数代码示例

本文整理汇总了Python中user_portrait.global_utils.es_user_portrait.search函数的典型用法代码示例。如果您正苦于以下问题:Python search函数的具体用法?Python search怎么用?Python search使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了search函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: search_task

def search_task(task_name, submit_date, state, status):
    results = []
    query = []
    condition_num = 0
    if task_name:
        task_name_list = task_name.split(' ')
        for item in task_name_list:
            #print 'item:', item
            query.append({'wildcard':{'task_name': '*' + item + '*'}})
            condition_num += 1
    if submit_date:
        query.append({'match':{'submit_date': submit_date}})
        condition_num += 1
    if state:
        state_list = state.split(' ')
        for item in state_list:
            query.append({'wildcard':{'state': '*' + item + '*'}})
            condition_num += 1
    if status:
        query.append({'match':{'status': status}})
        condition_num += 1
    if condition_num > 0:
        try:
            source = es.search(
                    index = 'group_result',
                    doc_type = 'group',
                    body = {
                        'query':{
                            'bool':{
                                'must':query
                                }
                            },
                        'sort': [{'count':{'order': 'desc'}}],
                        'size': 10000
                        }
                    )
        except Exception as e:
            raise e
    else:
        source = es.search(
                index = 'group_result',
                doc_type = 'group',
                body = {
                    'query':{'match_all':{}
                        },
                    'sort': [{'count': {'order': 'desc'}}],
                    'size': 10000
                    }
                )

    try:
        task_dict_list = source['hits']['hits']
    except:
        return None
    result = []
    print 'len task_dict_list:', len(task_dict_list)
    for task_dict in task_dict_list:
        result.append([task_dict['_source']['task_name'], task_dict['_source']['submit_date'], task_dict['_source']['count'], task_dict['_source']['state'], task_dict['_source']['status']])
    
    return result
开发者ID:ztybuaa,项目名称:user_portrait,代码行数:60,代码来源:utils.py

示例2: conclusion_on_influence

def conclusion_on_influence(uid):
    # test
    index_name = copy_portrait_index_name
    index_type = copy_portrait_index_type
    total_number = es.count(index=copy_portrait_index_name, doc_type=copy_portrait_index_type)["count"]

    try:
        influ_result = es.get(index=index_name, doc_type=index_type, id=uid)["_source"]
    except:
        influ_result = {}
        result = [0, 0, 0, 0, 0, 0, total_number]  # aver_activeness, sorted, aver_influence, sorted
        return result

    aver_activeness = influ_result.get("aver_activeness", 0)
    aver_influence = influ_result.get("aver_influence", 0)
    aver_importance = influ_result.get("aver_importance", 0)
    influence_query_body = {"query": {"match_all": {}}, "sort": {"aver_influence": {"order": "desc"}}, "size": 1}
    top_influence = es.search(
        index=copy_portrait_index_name, doc_type=copy_portrait_index_type, body=influence_query_body
    )["hits"]["hits"][0]["sort"][0]

    importance_query_body = {"query": {"match_all": {}}, "sort": {"aver_importance": {"order": "desc"}}, "size": 1}
    top_importance = es.search(
        index=copy_portrait_index_name, doc_type=copy_portrait_index_type, body=importance_query_body
    )["hits"]["hits"][0]["sort"][0]

    activeness_query_body = {"query": {"match_all": {}}, "sort": {"aver_activeness": {"order": "desc"}}, "size": 1}
    top_activeness = es.search(
        index=copy_portrait_index_name, doc_type=copy_portrait_index_type, body=activeness_query_body
    )["hits"]["hits"][0]["sort"][0]

    influence_query_body = {"query": {"filtered": {"filter": {"range": {"aver_influence": {"gt": aver_influence}}}}}}

    activeness_query_body = {"query": {"filtered": {"filter": {"range": {"aver_activeness": {"gt": aver_activeness}}}}}}

    importance_query_body = {"query": {"filtered": {"filter": {"range": {"aver_importance": {"gt": aver_importance}}}}}}

    influence_count = es.count(
        index=copy_portrait_index_name, doc_type=copy_portrait_index_type, body=influence_query_body
    )["count"]
    activeness_count = es.count(
        index=copy_portrait_index_name, doc_type=copy_portrait_index_type, body=activeness_query_body
    )["count"]
    importance_count = es.count(
        index=copy_portrait_index_name, doc_type=copy_portrait_index_type, body=importance_query_body
    )["count"]

    result = [
        int(aver_activeness * 100.0 / top_activeness),
        activeness_count,
        int(aver_influence * 100.0 / top_influence),
        influence_count,
        int(aver_importance * 100.0 / top_importance),
        importance_count,
        total_number,
    ]
    return result
开发者ID:huxiaoqian,项目名称:user_portrait,代码行数:57,代码来源:description.py

示例3: show_social_sensing_task

def show_social_sensing_task(user):
    query_body = {
        "query":{
            "filtered":{
                "filter":{
                    "bool":{
                        "must":[
                            {"term": {"finish": "1"}},
                            {"term": {"create_by": user}}
                        ]
                    }
                }
            }
        },
        "sort": {"create_at": {"order": "desc"}},
        "size": 10000
    }

    results = []
    search_results = es.search(index=index_manage_social_task, doc_type=task_doc_type, body=query_body)['hits']['hits']
    if search_results:
        for item in search_results:
            results.append(item['_source']['task_name'])

    return results
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:25,代码来源:social_sensing_utils.py

示例4: delete_attribute

def delete_attribute(attribute_name):
    status = False
    try:
        result = es.get(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)['_source']
    except:
        return status
    attribute_value = json.loads(result['value'])
    es.delete(index=attribute_index_name, doc_type=attribute_index_type, id=attribute_name)
    # delete attribute in user_portrait
    query = []
    for value in attribute_value:
        query.append({'match':{attribute_name: value}})
    try:
        attribute_user_result = es.search(index=user_index_name, doc_type=user_index_type, \
                                         body={'query':{'bool':{'must':query}}})['hits']['hits']
    except:
        attribute_user_result = []
    if attribute_user_result==[]:
        status = True
        return status
    bulk_action = []
    for user_dict in attribute_user_result:
        try:
            user_item = user_dict['_source']
        except:
            next
        user_item.pop(attribute)
        user = user_item['uid']
        action = {'index':{'_id':str(user)}}
        bulk_action.extend([action, user_item])
    es.bulk(bulk_action, index=user_index_name, doc_type=index_type)
    status = True
    return status
开发者ID:ztybuaa,项目名称:user_portrait,代码行数:33,代码来源:utils.py

示例5: get_social_domain

def get_social_domain(uid_set):
    results = {}
    query_body = {
        'query':{
            'filtered':{
                'filter':{
                    'terms':{
                        'uid': list(uid_set)
                        }
                    }
                }
            },
        'aggs':{
            'all_domain':{
                'terms':{'field': 'domain'}
                }
            }
        }
    search_result = es_user_portrait.search(index=portrait_index_name, doc_type=portrait_index_type, \
            body=query_body)['aggregations']['all_domain']['buckets']
    print 'search_result:', search_result
    for item in search_result:
        results[item['key']] = item['doc_count']

    return results
开发者ID:huxiaoqian,项目名称:revised_user_portrait,代码行数:25,代码来源:new_search.py

示例6: get_attribute_name

def get_attribute_name():
    attribute_name_list = []
    try:
        attribute_result = es.search(index=attribute_index_name, doc_type=attribute_index_type, \
                                     body={'query':{'match_all':{}}})['hits']['hits']
    except Exception, e:
        raise e
开发者ID:taozhiiq,项目名称:user_portrait,代码行数:7,代码来源:utils.py

示例7: get_top_influence

def get_top_influence(key):
    query_body = {"query": {"match_all": {}}, "sort": {key: {"order": "desc"}}, "size": 1}

    search_result = es.search(index=portrait_index_name, doc_type=portrait_index_type, body=query_body)["hits"]["hits"]
    if search_result:
        result = search_result[0]["_source"][key]

    return result
开发者ID:huxiaoqian,项目名称:user_portrait,代码行数:8,代码来源:get_task_detail.py

示例8: search_attribute

def search_attribute(query_body, condition_num):
    result = []
    if condition_num==0:
        try:
            result = es.search(index=attribute_index_name, doc_type=attribute_index_type, \
                               body={'query':{'match_all':{}}})['hits']['hits']
        except Exception, e:
            raise e
开发者ID:ztybuaa,项目名称:user_portrait,代码行数:8,代码来源:utils.py

示例9: search_attribute

def search_attribute(query_body, condition_num):
    item_list = []
    default_size = 100000
    if condition_num==0:
        try:
            result = es.search(index=attribute_index_name, doc_type=attribute_index_type, \
                    body={'query':{'match_all':{}}, 'size':default_size})['hits']['hits']
        except Exception, e:
            raise e
开发者ID:taozhiiq,项目名称:user_portrait,代码行数:9,代码来源:utils.py

示例10: get_evaluate_max

def get_evaluate_max():
    max_result = {}
    evaluate_index = ["influence", "activeness", "importance"]
    for evaluate in evaluate_index:
        query_body = {"query": {"match_all": {}}, "size": 1, "sort": [{evaluate: {"order": "desc"}}]}
        try:
            result = es.search(index=portrait_index_name, doc_type=portrait_index_type, body=query_body)["hits"]["hits"]
        except Exception, e:
            raise e
        max_evaluate = result[0]["_source"][evaluate]
        max_result[evaluate] = max_evaluate
开发者ID:huxiaoqian,项目名称:user_portrait,代码行数:11,代码来源:imagine.py

示例11: search_portrait

def search_portrait(condition_num, query, sort, size):
    user_result = []
    index_name = 'user_portrait'
    index_type = 'user'
    if condition_num > 0:
        try:
            #print query
            result = es_user_portrait.search(index=index_name, doc_type=index_type, \
                    body={'query':{'bool':{'must':query}}, 'sort':sort, 'size':size})['hits']['hits']
            #print 'result:', result
        except Exception,e:
            raise e
开发者ID:ztybuaa,项目名称:user_portrait,代码行数:12,代码来源:search.py

示例12: ajax_show_task

def ajax_show_task():
    # show all working task
    # "0": unfinish working task
    # "1": finish working task
    status = request.args.get("finish", "01")
    user = request.args.get('user', 'admin')
    length = len(status)
    query_body = {
        "query":{
            "filtered":{
                "filter":{
                    "bool":{
                        "must":[
                            {"term":{"create_by": user}}
                        ]
                    }
                }
            }
        },
        "sort": {"create_at": {"order": "desc"}},
        "size": 10000
    }
    #if length == 2:
    #    category_list = [status[0], status[1]]
    #    query_body['query']['filtered']['filter']["bool"]["must"].append({"term":{"finish": category_list}})
    if length == 1:
        query_body['query']['filtered']['filter']['bool']['must'].append({"term":{"finish": status}})
    #else:
    #    print "error"

    try:
        search_results = es.search(index=index_manage_sensing_task, doc_type=task_doc_type, body=query_body)['hits']['hits']
    except:
        search_results = []
    results = []
    if search_results:
        for item in search_results:
            item = item['_source']
            history_status = json.loads(item['history_status'])
            if history_status:
                temp_list = []
                temp_list.append(history_status[-1])
                for iter_item in history_status[:-1]:
                    if int(iter_item[-1]) != 0:
                        temp_list.append(iter_item)
                sorted_list = sorted(temp_list, key=lambda x:x[0], reverse=True)
                item['history_status'] = sorted_list
            else:
                item['history_status'] = history_status
            results.append(item)
    print results
    return json.dumps(results)
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:52,代码来源:views.py

示例13: save_detect_single_task

def save_detect_single_task(input_dict):
    results = {}
    #step1: identify the seed user is in user_portrait
    seed_user = input_dict['query_condition']['seed_user']
    query = []
    query_list = []
    for user_item in seed_user:
        query_list.append({'term':{user_item: seed_user[user_item]}})
    query.append({'bool':{'should': query_list}})
    try:
        seed_user_result = es_user_portrait.search(index=portrait_index_name, doc_type=portrait_index_type, \
                            body={'query':{'bool':{'must':query}}, 'size':1})['hits']['hits']
    except Exception, e:
        raise e
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:14,代码来源:utils.py

示例14: get_top_influence

def get_top_influence(key="influence"):
    query_body = {
        "query":{
            "match_all": {}
        },
        "sort":{key:{"order":"desc"}},
        "size": 1
    }

    search_result = es.search(index=portrait_index_name, doc_type=portrait_index_type, body=query_body)['hits']['hits']
    if search_result:
        result = search_result[0]['_source']['influence']
    else:
        result = 2000

    return result
开发者ID:huxiaoqian,项目名称:user_portrait,代码行数:16,代码来源:social_sensing_utils.py

示例15: ajax_get_group_list

def ajax_get_group_list():
    user = request.args.get('user', '')
    # get all group list from group manage
    results = [] #
    query_body = {
        "query":{
            "filtered":{
                "filter":{
                    "bool":{
                        "should":[
                            {"term": {"task_type": "analysis"}},
                            {"bool":{
                                "must":[
                                    {"term": {"task_type": "detect"}},
                                    {"term": {"detect_process":100}}
                                ]
                            }}
                        ],
                        "must":{"term": {"submit_user": user}}
                    }
                }
            }
        },
        "sort": {"submit_date": {"order": "desc"}},
        "size": 10000
    }

    search_results = es.search(index=index_group_manage, doc_type=doc_type_group, body=query_body, timeout=600)['hits']['hits']
    if search_results:
        for item in search_results:
            item = item['_source']
            temp = []
            temp.append(item['task_name'])
            temp.append(item['submit_user'])
            temp.append(item['submit_date'])
            temp.append(0)
            temp.append(item.get('state', ""))
            try:
                temp.append(json.loads(item['uid_list']))
                count = len(json.loads(item['uid_list']))
                temp[3] = count
            except:
                temp.append(item['uid_list'])
                temp[3] = len(item['uid_list'])
            results.append(temp)

    return json.dumps(results)
开发者ID:huxiaoqian,项目名称:user_portrait_0324,代码行数:47,代码来源:views.py


注:本文中的user_portrait.global_utils.es_user_portrait.search函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。