exp_count = min(exp_count, min(t.count for t in addr_partials)) \
if addr_partials else exp_count
- if exp_count < 1000 and len(addr_tokens) > 3 and partials_indexed:
- # Lookup by address partials and restrict results through name terms.
- # Give this a small penalty because lookups in the address index are
- # more expensive
- yield penalty + exp_count/5000, exp_count,\
- dbf.lookup_by_addr(name_tokens, addr_tokens)
- return
# Partial term to frequent. Try looking up by rare full names first.
name_fulls = self.query.get_tokens(name, TokenType.WORD)
except ValueError as exc:
raise UsageError('Bounding box parameter needs to be numbers.') from exc
- if x1 < -180.0 or x1 > 180.0 or y1 < -90.0 or y1 > 90.0 \
- or x2 < -180.0 or x2 > 180.0 or y2 < -90.0 or y2 > 90.0:
- raise UsageError('Bounding box coordinates invalid.')
+ x1 = min(180, max(-180, x1))
+ x2 = min(180, max(-180, x2))
+ y1 = min(90, max(-90, y1))
+ y2 = min(90, max(-90, y2))
if x1 == x2 or y1 == y2:
raise UsageError('Bounding box with invalid parameters.')
body of the response to 'output'.
"""
+ @abc.abstractmethod
+ def base_uri(self) -> str:
+ """ Return the URI of the original request.
+ """
+
@abc.abstractmethod
def config(self) -> Configuration:
(str(r.place_id) for r in results if r.place_id))
queryparts['format'] = fmt
- moreurl = urlencode(queryparts)
+ moreurl = params.base_uri() + '/search?' + urlencode(queryparts)
else:
moreurl = ''
self.response.content_type = self.content_type
+ def base_uri(self) -> str:
+ return cast (str, self.request.forwarded_prefix)
+
def config(self) -> Configuration:
return self._config
return Response(output, status_code=status, media_type=self.content_type)
+ def base_uri(self) -> str:
+ scheme = self.request.url.scheme
+ host = self.request.url.hostname
+ port = self.request.url.port
+ root = self.request.scope['root_path']
+ if (scheme == 'http' and port == 80) or (scheme == 'https' and port == 443):
+ port = None
+ if port is not None:
+ return f"{scheme}://{host}:{port}{root}"
+
+ return f"{scheme}://{host}{root}"
+
+
def config(self) -> Configuration:
return cast(Configuration, self.request.app.state.API.config)
return FakeResponse(status, output, self.content_type)
+ def base_uri(self) -> str:
+ return 'http://test'
+
def config(self):
return self._config
assert set(search.countries.values) == {'en'}
-def test_country_search_with_confllicting_country_restriction():
+def test_country_search_with_conflicting_country_restriction():
q = make_query([(1, TokenType.COUNTRY, [(2, 'de'), (3, 'en')])])
builder = SearchBuilder(q, SearchDetails.from_kwargs({'countries': 'fr'}))
{('name_vector', 'lookup_all'), ('nameaddress_vector', 'restrict')}
-def test_frequent_partials_in_name_but_not_in_address():
- searches = make_counted_searches(10000, 1, 1, 1, num_address_parts=4)
-
- assert len(searches) == 1
- search = searches[0]
-
- assert isinstance(search, dbs.PlaceSearch)
- assert len(search.lookups) == 2
- assert len(search.rankings) == 2
-
- assert set((l.column, l.lookup_type) for l in search.lookups) == \
- {('nameaddress_vector', 'lookup_all'), ('name_vector', 'restrict')}
-
-
def test_frequent_partials_in_name_and_address():
searches = make_counted_searches(9999, 1, 9999, 1)