Skip to content

Commit

Permalink
avoid LookupAny with address and too many name tokens
Browse files Browse the repository at this point in the history
The index for nameaddress_vector has grown so large that PostgreSQL
will resort to a sequential scan if there are too many items
in the LookupAny list.
  • Loading branch information
lonvia committed Jan 29, 2024
1 parent 76eadc5 commit 33c0f24
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions nominatim/api/search/db_search_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,12 @@ def build_housenumber_search(self, sdata: dbf.SearchData, hnrs: List[Token],
sdata.lookups.append(dbf.FieldLookup('nameaddress_vector',
list(partials), lookups.LookupAll))
else:
addr_fulls = [t.token for t
in self.query.get_tokens(address[0], TokenType.WORD)]
if len(addr_fulls) > 5:
return
sdata.lookups.append(
dbf.FieldLookup('nameaddress_vector',
[t.token for t
in self.query.get_tokens(address[0], TokenType.WORD)],
lookups.LookupAny))
dbf.FieldLookup('nameaddress_vector', addr_fulls, lookups.LookupAny))

sdata.housenumbers = dbf.WeightedStrings([], [])
yield dbs.PlaceSearch(0.05, sdata, expected_count)
Expand Down

0 comments on commit 33c0f24

Please sign in to comment.