예제 #1
0
def refresh_index(subject, uri2rank):
    delete_subject(subject)

    part_response = query.query_parts('',
                                      'FILTER (?subject = <' + subject + '>)')

    if len(part_response) == 1:
        add_pagerank(part_response, uri2rank)
        add_keywords(part_response)
        index_part(part_response[0])
예제 #2
0
def search(sparql_query, uri2rank, clusters):
    es_query, _from, criteria, offset, limit = extract_query(sparql_query)

    filterless_criteria = re.sub('FILTER .*', '', criteria).strip()
    allowed_graphs = extract_allowed_graphs(_from)
    _from = parse_allowed_graphs(allowed_graphs)
    
    if 'SIMILAR' in criteria:
        # SIMILAR
        similar_criteria = create_similar_criteria(criteria, clusters)
        criteria_response = query.query_parts(_from, similar_criteria) 
        bindings = create_criteria_bindings(criteria_response, uri2rank)

    elif 'USES' in criteria or 'TWINS' in criteria or (es_query == '' and filterless_criteria != ''):
        # USES or TWINS or pure advanced search
        criteria_response = query.query_parts(_from, criteria)
        bindings = create_criteria_bindings(criteria_response, uri2rank)

    elif es_query == '' and filterless_criteria == '':
        # empty search
        es_response = empty_search_es(offset, limit, allowed_graphs)
        bindings = create_bindings(es_response, clusters, allowed_graphs)
        bindings.sort(key = lambda binding: binding['order_by'], reverse = True)
        return create_response(es_response['hits']['total'], bindings, is_count_query(sparql_query))

    else:
        es_response = search_es(es_query)

        if filterless_criteria == '':
            # pure string search
            bindings = create_bindings(es_response, clusters, allowed_graphs)

        else:
            # advanced search and string search
            criteria_response = query.query_parts(_from, filterless_criteria)
            allowed_subjects = get_allowed_subjects(criteria_response)
            bindings = create_bindings(es_response, clusters, allowed_graphs, allowed_subjects)

    bindings.sort(key = lambda binding: binding['order_by'], reverse = True)

    return create_response(len(bindings), bindings[offset:offset + limit], is_count_query(sparql_query))
예제 #3
0
def update_index(uri2rank):
    index_name = utils.get_config()['elasticsearch_index_name']

    utils.log('Query for parts')
    parts_response = query.query_parts()
    utils.log('Query for parts complete')

    add_pagerank(parts_response, uri2rank)
    add_keywords(parts_response)
    create_parts_index(index_name)
    bulk_index_parts(parts_response, index_name)

    utils.log('Number of parts: ' + str(len(parts_response)))