예제 #1
0
def description(project_id, *args):
    pub_query = IndexedPublication.search()\
        .filter(Q({'term': {'projectId._exact': project_id}}))\
        .source(includes=['project.value.description'])
    desc = next(hit.project.value.description
                for hit in pub_query.execute().hits)
    return {'description': desc}
예제 #2
0
def listing(offset=0, limit=100, limit_fields=True, *args):
    pub_query = IndexedPublication.search()
    pub_query = pub_query.filter(Q('term', status='published'))
    pub_query = pub_query.extra(from_=offset, size=limit)
    if limit_fields:
        pub_query = pub_query.source(includes=[
            'project.value.title', 'project.value.pi',
            'project.value.keywords', 'project.value.projectType',
            'project.value.dataType', 'created', 'projectId', 'users', 'system'
        ])
    pub_query = pub_query.sort({'created': {'order': 'desc'}})

    res = pub_query.execute()

    hits = list(
        map(
            lambda h: {
                **h.to_dict(), 'pi': _get_user_by_username(
                    h, h.project.value.pi)
            }, res.hits))

    return {'listing': hits}
예제 #3
0
def search(offset=0, limit=100, query_string='', limit_fields=True, *args):
    query_dict = json.loads(urllib.parse.unquote(query_string))

    type_filters = query_dict['typeFilters']
    has_type_filters = True in list(map(bool, type_filters.values()))

    def filter_query(type):
        return Q('term', **{'project.value.projectType._exact': type})

    selected_filters = list(
        filter(lambda key: bool(type_filters[key]), type_filters.keys()))

    type_query = Q('bool', should=list(map(filter_query, selected_filters)))
    search = IndexedPublication.search()
    if has_type_filters:
        search = search.filter(type_query)

    query_filters = []

    # Query string fields
    author = query_dict['queries']['author']
    title = query_dict['queries']['title']
    keywords = query_dict['queries']['keyword']
    description = query_dict['queries']['description']
    if author:
        query_filters.append(search_utils.author_query(author))
    if title:
        query_filters.append(search_utils.title_query(title))
    if keywords:
        query_filters.append(search_utils.keyword_query(keywords))
    if description:
        query_filters.append(search_utils.description_query(description))

    # Experimental advanced filters
    facility_name = query_dict['advancedFilters']['experimental'][
        'experimentalFacility']
    experiment_type = query_dict['advancedFilters']['experimental'][
        'experimentType']
    if facility_name:
        query_filters.append(
            search_utils.experimental_facility_query(facility_name))
    if experiment_type:
        query_filters.append(search_utils.experiment_type_query)

    # Simulation advanced filters
    simulation_type = query_dict['advancedFilters']['simulation'][
        'simulationType']
    if simulation_type:
        query_filters.append(
            search_utils.simulation_type_query(simulation_type))

    # Field recon advanced filters
    nh_type = query_dict['advancedFilters']['field_recon']['naturalHazardType']
    nh_event = query_dict['advancedFilters']['field_recon'][
        'naturalHazardEvent']
    if nh_type:
        query_filters.append(search_utils.nh_type_query(nh_type))
    if nh_event:
        query_filters.append(search_utils.nh_event_query(nh_event))

    # Other advanced filters
    data_type = query_dict['advancedFilters']['other']['dataType']
    if data_type:
        query_filters.append(search_utils.other_type_query(data_type))

    # Hybrid sim advanced filters
    sim_type = data_type = query_dict['advancedFilters']['hybrid_simulation'][
        'hybridSimulationType']
    if sim_type:
        query_filters.append(search_utils.hybrid_sim_type_query(sim_type))

    search = search.filter('bool', must=query_filters)
    search = search.filter(Q('term', status='published'))
    search = search.extra(from_=offset, size=limit)
    if limit_fields:
        search = search.source(includes=[
            'project.value.title', 'project.value.pi',
            'project.value.keywords', 'project.value.projectType',
            'project.value.dataType', 'created', 'projectId', 'users', 'system'
        ])

    search = search.sort({'created': {'order': 'desc'}})
    res = search.execute()
    hits = list(
        map(
            lambda h: {
                **h.to_dict(), 'pi': _get_user_by_username(
                    h, h.project.value.pi)
            }, res.hits))

    return {'listing': hits}