Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More tweaks for Python frontend search #3263

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions nominatim/api/search/db_search_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ def build(self, assignment: TokenAssignment) -> Iterator[dbs.AbstractSearch]:
penalty = min(near_items.penalties)
near_items.penalties = [p - penalty for p in near_items.penalties]
for search in builder:
yield dbs.NearSearch(penalty + assignment.penalty, near_items, search)
search_penalty = search.penalty
search.penalty = 0.0
yield dbs.NearSearch(penalty + assignment.penalty + search_penalty,
near_items, search)
else:
for search in builder:
search.penalty += assignment.penalty
Expand Down Expand Up @@ -160,11 +163,15 @@ def build_housenumber_search(self, sdata: dbf.SearchData, hnrs: List[Token],
housenumber is the main name token.
"""
sdata.lookups = [dbf.FieldLookup('name_vector', [t.token for t in hnrs], 'lookup_any')]
expected_count = sum(t.count for t in hnrs)

partials = [t for trange in address
for t in self.query.get_partials_list(trange)]

if len(partials) != 1 or partials[0].count < 10000:
if expected_count < 8000:
sdata.lookups.append(dbf.FieldLookup('nameaddress_vector',
[t.token for t in partials], 'restrict'))
elif len(partials) != 1 or partials[0].count < 10000:
sdata.lookups.append(dbf.FieldLookup('nameaddress_vector',
[t.token for t in partials], 'lookup_all'))
else:
Expand All @@ -175,7 +182,7 @@ def build_housenumber_search(self, sdata: dbf.SearchData, hnrs: List[Token],
'lookup_any'))

sdata.housenumbers = dbf.WeightedStrings([], [])
yield dbs.PlaceSearch(0.05, sdata, sum(t.count for t in hnrs))
yield dbs.PlaceSearch(0.05, sdata, expected_count)


def build_name_search(self, sdata: dbf.SearchData,
Expand Down
4 changes: 2 additions & 2 deletions nominatim/api/search/geocoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ async def execute_searches(self, query: QueryStruct,

end_time = dt.datetime.now() + self.timeout

min_ranking = 1000.0
min_ranking = searches[0].penalty + 2.0
prev_penalty = 0.0
for i, search in enumerate(searches):
if search.penalty > prev_penalty and (search.penalty > min_ranking or i > 20):
Expand All @@ -94,7 +94,7 @@ async def execute_searches(self, query: QueryStruct,
prevresult.accuracy = min(prevresult.accuracy, result.accuracy)
else:
results[rhash] = result
min_ranking = min(min_ranking, result.ranking + 0.5, search.penalty + 0.3)
min_ranking = min(min_ranking, result.accuracy * 1.2)
log().result_dump('Results', ((r.accuracy, r) for r in lookup_results))
prev_penalty = search.penalty
if dt.datetime.now() >= end_time:
Expand Down