コード例 #1
0
def test_driver_with_simple_query():
    author_name = 'Ellis, John'
    name_variations = generate_name_variations(author_name)

    query_str = 'author: ' + author_name
    expected_es_query = {
        "bool": {
            "filter": {
                "bool": {
                    "should": [{
                        "term": {
                            "authors.name_variations": name_variation
                        }
                    } for name_variation in name_variations]
                }
            },
            "must": {
                "match": {
                    "authors.full_name": "Ellis, John"
                }
            }
        }
    }

    es_query = parse_query(query_str)

    assert es_query == expected_es_query
コード例 #2
0
def test_driver_with_es_visitor_empty_query_generates_a_query_against_all():
    query_str = 'd < 200'
    expected_es_query = {
        'multi_match': {
            'query': 'd < 200',
            'fields': ['_all'],
            'zero_terms_query': 'all'
        }
    }

    es_query = parse_query(query_str)

    assert es_query == expected_es_query
コード例 #3
0
def test_driver_with_simple_query():
    query_str = 'subject astrophysics'
    expected_es_query = {
        "match": {
            "facet_inspire_categories": {
                "query": "astrophysics",
                "operator": "and"
            }
        }
    }

    es_query = parse_query(query_str)

    assert es_query == expected_es_query
コード例 #4
0
def test_driver_with_syntax_error(mocked_parser):
    query_str = 'query with syntax error'
    expected_es_query = {
        'multi_match': {
            'query': 'query with syntax error',
            'fields': ['_all'],
            'zero_terms_query': 'all'
        }
    }

    mocked_parser.return_value.parse.side_effect = SyntaxError()

    es_query = parse_query(query_str)

    assert es_query == expected_es_query
コード例 #5
0
def test_driver_with_rst_visitor_error(mocked_rst_visitor):
    query_str = 'foo'
    expected_es_query = {
        'multi_match': {
            'query': 'foo',
            'fields': ['_all'],
            'zero_terms_query': 'all'
        }
    }
    mocked_rst_visitor.return_value.visit.side_effect = Exception('Something went wrong with visit_value')
    mocked_rst_visitor.__name__ = 'MockedRestructuringVisitor'

    es_query = parse_query(query_str)

    assert es_query == expected_es_query
コード例 #6
0
def test_driver_with_nothing_recognized(mocked_parser):
    query_str = 'unrecognized query'
    expected_es_query = {
        'multi_match': {
            'query': 'unrecognized query',
            'fields': ['_all'],
            'zero_terms_query': 'all'
        }
    }

    mocked_parser.return_value.parse.return_value = ('unrecognized query', None)

    es_query = parse_query(query_str)

    assert es_query == expected_es_query