示例#1
0
def test_compile_with_match_deleted():
    query = {
        'type': 'exact',
        'path': 'dummy.path',
        'search_path': 'dummy.search.path',
    }
    record = {
        'dummy': {
            'path': 'foo',
        },
    }

    result = compile(query, record, match_deleted=True)
    expected = {
        'query': {
            'bool': {
                'should': [{
                    'match': {
                        'dummy.search.path': 'foo',
                    },
                }],
            },
        },
    }

    assert expected == result
示例#2
0
def test_compile_returns_none_if_empty_inner():
    query = {
        'type': 'exact',
        'path': 'dummy.path',
        'search_path': 'dummy.search.path',
    }
    record = {}

    assert compile(query, record) is None
示例#3
0
def test_compile_with_collections():
    query = {
        'type': 'exact',
        'path': 'dummy.path',
        'search_path': 'dummy.search.path',
    }
    record = {
        'dummy': {
            'path': 'foo',
        },
    }

    result = compile(query, record, collections=['Literature', 'HAL Hidden'])
    expected = {
        'query': {
            'bool': {
                'must': {
                    'bool': {
                        'should': [{
                            'match': {
                                'dummy.search.path': 'foo',
                            },
                        }],
                    },
                },
                'filter': {
                    'bool': {
                        'should': [
                            {
                                'match': {
                                    '_collections': 'Literature',
                                },
                            },
                            {
                                'match': {
                                    '_collections': 'HAL Hidden',
                                },
                            }
                        ],
                        'must_not': {
                            'match': {
                                'deleted': True,
                            },
                        },
                    },
                },
            },
        },
    }

    assert expected == result
示例#4
0
def test_compile_without_optional_args():
    query = {
        'type': 'exact',
        'path': 'dummy.path',
        'search_path': 'dummy.search.path',
    }
    record = {
        'dummy': {
            'path': 'foo',
        },
    }

    result = compile(query, record)
    expected = {
        'query': {
            'bool': {
                'must': {
                    'bool': {
                        'should': [{
                            'match': {
                                'dummy.search.path': 'foo',
                            },
                        }],
                    },
                },
                'filter': {
                    'bool': {
                        'must_not': {
                            'match': {
                                'deleted': True,
                            },
                        },
                    },
                },
            },
        },
    }

    assert expected == result