import pytest_asyncio
from nominatim_api import NominatimAPIAsync
-from nominatim_api.search.query import Phrase, PhraseType
+from nominatim_api.search.query import Phrase
import nominatim_api.search.query as qmod
import nominatim_api.search.icu_tokenizer as tok
from nominatim_api.logging import set_log_output, get_and_disable
def make_phrase(query):
- return [Phrase(PhraseType.NONE, s) for s in query.split(',')]
+ return [Phrase(qmod.PHRASE_ANY, s) for s in query.split(',')]
@pytest_asyncio.fixture
async def conn(table_factory):
query = await ana.analyze_query(make_phrase('foo BAR'))
assert len(query.source) == 1
- assert query.source[0].ptype == PhraseType.NONE
+ assert query.source[0].ptype == qmod.PHRASE_ANY
assert query.source[0].text == 'foo bar'
assert query.num_token_slots() == 2
@pytest.mark.asyncio
@pytest.mark.parametrize('term,order', [('23456', ['P', 'H', 'W', 'w']),
- ('3', ['H', 'P', 'W', 'w'])
+ ('3', ['H', 'W', 'w'])
])
async def test_penalty_postcodes_and_housenumbers(conn, term, order):
ana = await tok.create_query_analyzer(conn)
- await add_word(conn, 1, term, 'P', None)
await add_word(conn, 2, term, 'H', term)
await add_word(conn, 3, term, 'w', term)
await add_word(conn, 4, term, 'W', term)
assert query.nodes[1].starting[0].ttype == qmod.TOKEN_HOUSENUMBER
assert len(query.nodes[1].starting[0].tokens) == 1
assert query.nodes[1].starting[0].tokens[0].token == 1
- assert not query.nodes[2].starting
- assert not query.nodes[3].starting
+ assert query.nodes[2].has_tokens(3, qmod.TOKEN_POSTCODE)
+ assert not query.nodes[2].has_tokens(3, qmod.TOKEN_HOUSENUMBER)
+ assert not query.nodes[2].has_tokens(4, qmod.TOKEN_HOUSENUMBER)
+ assert not query.nodes[3].has_tokens(4, qmod.TOKEN_HOUSENUMBER)
@pytest.mark.asyncio