X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/bd2c64876f7ddc99da14ea78a652f797e17134f4..8f3845660f18bdbf2dd42dd2c6db6c7fa5160f3e:/test/python/api/search/test_api_search_query.py?ds=sidebyside diff --git a/test/python/api/search/test_api_search_query.py b/test/python/api/search/test_api_search_query.py index f8c9c2dc..bfdceb41 100644 --- a/test/python/api/search/test_api_search_query.py +++ b/test/python/api/search/test_api_search_query.py @@ -18,7 +18,8 @@ class MyToken(query.Token): def mktoken(tid: int): - return MyToken(3.0, tid, 1, 'foo', True) + return MyToken(penalty=3.0, token=tid, count=1, addr_count=1, + lookup_word='foo', is_indexed=True) @pytest.mark.parametrize('ptype,ttype', [('NONE', 'WORD'), @@ -28,12 +29,12 @@ def mktoken(tid: int): ('COUNTRY', 'COUNTRY'), ('POSTCODE', 'POSTCODE')]) def test_phrase_compatible(ptype, ttype): - assert query.PhraseType[ptype].compatible_with(query.TokenType[ttype]) + assert query.PhraseType[ptype].compatible_with(query.TokenType[ttype], False) @pytest.mark.parametrize('ptype', ['COUNTRY', 'POSTCODE']) def test_phrase_incompatible(ptype): - assert not query.PhraseType[ptype].compatible_with(query.TokenType.PARTIAL) + assert not query.PhraseType[ptype].compatible_with(query.TokenType.PARTIAL, True) def test_query_node_empty(): @@ -99,3 +100,36 @@ def test_query_struct_incompatible_token(): assert q.get_tokens(query.TokenRange(0, 1), query.TokenType.PARTIAL) == [] assert len(q.get_tokens(query.TokenRange(1, 2), query.TokenType.COUNTRY)) == 1 + + +def test_query_struct_amenity_single_word(): + q = query.QueryStruct([query.Phrase(query.PhraseType.AMENITY, 'bar')]) + q.add_node(query.BreakType.END, query.PhraseType.NONE) + + q.add_token(query.TokenRange(0, 1), query.TokenType.PARTIAL, mktoken(1)) + q.add_token(query.TokenRange(0, 1), query.TokenType.NEAR_ITEM, mktoken(2)) + q.add_token(query.TokenRange(0, 1), query.TokenType.QUALIFIER, mktoken(3)) + + assert len(q.get_tokens(query.TokenRange(0, 1), query.TokenType.PARTIAL)) == 1 + assert len(q.get_tokens(query.TokenRange(0, 1), query.TokenType.NEAR_ITEM)) == 1 + assert len(q.get_tokens(query.TokenRange(0, 1), query.TokenType.QUALIFIER)) == 0 + + +def test_query_struct_amenity_two_words(): + q = query.QueryStruct([query.Phrase(query.PhraseType.AMENITY, 'foo bar')]) + q.add_node(query.BreakType.WORD, query.PhraseType.AMENITY) + q.add_node(query.BreakType.END, query.PhraseType.NONE) + + for trange in [(0, 1), (1, 2)]: + q.add_token(query.TokenRange(*trange), query.TokenType.PARTIAL, mktoken(1)) + q.add_token(query.TokenRange(*trange), query.TokenType.NEAR_ITEM, mktoken(2)) + q.add_token(query.TokenRange(*trange), query.TokenType.QUALIFIER, mktoken(3)) + + assert len(q.get_tokens(query.TokenRange(0, 1), query.TokenType.PARTIAL)) == 1 + assert len(q.get_tokens(query.TokenRange(0, 1), query.TokenType.NEAR_ITEM)) == 0 + assert len(q.get_tokens(query.TokenRange(0, 1), query.TokenType.QUALIFIER)) == 1 + + assert len(q.get_tokens(query.TokenRange(1, 2), query.TokenType.PARTIAL)) == 1 + assert len(q.get_tokens(query.TokenRange(1, 2), query.TokenType.NEAR_ITEM)) == 0 + assert len(q.get_tokens(query.TokenRange(1, 2), query.TokenType.QUALIFIER)) == 1 +