mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-03-12 05:44:06 +00:00
handle duplicate word entries correctly when looking for nearest street
This commit is contained in:
@@ -271,6 +271,20 @@ END;
|
|||||||
$$
|
$$
|
||||||
LANGUAGE plpgsql IMMUTABLE;
|
LANGUAGE plpgsql IMMUTABLE;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION get_name_ids(lookup_word TEXT)
|
||||||
|
RETURNS INTEGER[]
|
||||||
|
AS $$
|
||||||
|
DECLARE
|
||||||
|
lookup_token TEXT;
|
||||||
|
return_word_ids INTEGER[];
|
||||||
|
BEGIN
|
||||||
|
lookup_token := ' '||trim(lookup_word);
|
||||||
|
SELECT array_agg(word_id) FROM word WHERE word_token = lookup_token and class is null and type is null into return_word_ids;
|
||||||
|
RETURN return_word_ids;
|
||||||
|
END;
|
||||||
|
$$
|
||||||
|
LANGUAGE plpgsql IMMUTABLE;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION array_merge(a INTEGER[], b INTEGER[])
|
CREATE OR REPLACE FUNCTION array_merge(a INTEGER[], b INTEGER[])
|
||||||
RETURNS INTEGER[]
|
RETURNS INTEGER[]
|
||||||
AS $$
|
AS $$
|
||||||
@@ -1260,6 +1274,7 @@ DECLARE
|
|||||||
search_maxrank INTEGER;
|
search_maxrank INTEGER;
|
||||||
address_maxrank INTEGER;
|
address_maxrank INTEGER;
|
||||||
address_street_word_id INTEGER;
|
address_street_word_id INTEGER;
|
||||||
|
address_street_word_ids INTEGER[];
|
||||||
parent_place_id_rank BIGINT;
|
parent_place_id_rank BIGINT;
|
||||||
|
|
||||||
isin TEXT[];
|
isin TEXT[];
|
||||||
@@ -1505,18 +1520,18 @@ BEGIN
|
|||||||
--RAISE WARNING 'x3 %',NEW.parent_place_id;
|
--RAISE WARNING 'x3 %',NEW.parent_place_id;
|
||||||
|
|
||||||
IF NEW.parent_place_id IS NULL AND NEW.street IS NOT NULL THEN
|
IF NEW.parent_place_id IS NULL AND NEW.street IS NOT NULL THEN
|
||||||
address_street_word_id := get_name_id(make_standard_name(NEW.street));
|
address_street_word_ids := get_name_ids(make_standard_name(NEW.street));
|
||||||
IF address_street_word_id IS NOT NULL THEN
|
IF address_street_word_ids IS NOT NULL THEN
|
||||||
FOR location IN SELECT * from getNearestNamedRoadFeature(NEW.partition, place_centroid, address_street_word_id) LOOP
|
FOR location IN SELECT * from getNearestNamedRoadFeature(NEW.partition, place_centroid, address_street_word_ids) LOOP
|
||||||
NEW.parent_place_id := location.place_id;
|
NEW.parent_place_id := location.place_id;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
END IF;
|
END IF;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
IF NEW.parent_place_id IS NULL AND NEW.addr_place IS NOT NULL THEN
|
IF NEW.parent_place_id IS NULL AND NEW.addr_place IS NOT NULL THEN
|
||||||
address_street_word_id := get_name_id(make_standard_name(NEW.addr_place));
|
address_street_word_ids := get_name_id(make_standard_name(NEW.addr_place));
|
||||||
IF address_street_word_id IS NOT NULL THEN
|
IF address_street_word_ids IS NOT NULL THEN
|
||||||
FOR location IN SELECT * from getNearestNamedPlaceFeature(NEW.partition, place_centroid, address_street_word_id) LOOP
|
FOR location IN SELECT * from getNearestNamedPlaceFeature(NEW.partition, place_centroid, address_street_word_ids) LOOP
|
||||||
NEW.parent_place_id := location.place_id;
|
NEW.parent_place_id := location.place_id;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
END IF;
|
END IF;
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ END
|
|||||||
$$
|
$$
|
||||||
LANGUAGE plpgsql;
|
LANGUAGE plpgsql;
|
||||||
|
|
||||||
create or replace function getNearestNamedRoadFeature(in_partition INTEGER, point GEOMETRY, isin_token INTEGER)
|
create or replace function getNearestNamedRoadFeature(in_partition INTEGER, point GEOMETRY, isin_token INTEGER[])
|
||||||
RETURNS setof nearfeature AS $$
|
RETURNS setof nearfeature AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
r nearfeature%rowtype;
|
r nearfeature%rowtype;
|
||||||
@@ -123,7 +123,7 @@ BEGIN
|
|||||||
SELECT place_id, name_vector, address_rank, search_rank,
|
SELECT place_id, name_vector, address_rank, search_rank,
|
||||||
ST_Distance(centroid, point) as distance, null as isguess
|
ST_Distance(centroid, point) as distance, null as isguess
|
||||||
FROM search_name_-partition-
|
FROM search_name_-partition-
|
||||||
WHERE name_vector @> ARRAY[isin_token]
|
WHERE name_vector @> isin_token
|
||||||
AND ST_DWithin(centroid, point, 0.01)
|
AND ST_DWithin(centroid, point, 0.01)
|
||||||
AND search_rank between 26 and 27
|
AND search_rank between 26 and 27
|
||||||
ORDER BY distance ASC limit 1
|
ORDER BY distance ASC limit 1
|
||||||
@@ -139,7 +139,7 @@ END
|
|||||||
$$
|
$$
|
||||||
LANGUAGE plpgsql;
|
LANGUAGE plpgsql;
|
||||||
|
|
||||||
create or replace function getNearestNamedPlaceFeature(in_partition INTEGER, point GEOMETRY, isin_token INTEGER)
|
create or replace function getNearestNamedPlaceFeature(in_partition INTEGER, point GEOMETRY, isin_token INTEGER[])
|
||||||
RETURNS setof nearfeature AS $$
|
RETURNS setof nearfeature AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
r nearfeature%rowtype;
|
r nearfeature%rowtype;
|
||||||
@@ -151,7 +151,7 @@ BEGIN
|
|||||||
SELECT place_id, name_vector, address_rank, search_rank,
|
SELECT place_id, name_vector, address_rank, search_rank,
|
||||||
ST_Distance(centroid, point) as distance, null as isguess
|
ST_Distance(centroid, point) as distance, null as isguess
|
||||||
FROM search_name_-partition-
|
FROM search_name_-partition-
|
||||||
WHERE name_vector @> ARRAY[isin_token]
|
WHERE name_vector @> isin_token
|
||||||
AND ST_DWithin(centroid, point, 0.03)
|
AND ST_DWithin(centroid, point, 0.03)
|
||||||
AND search_rank between 16 and 22
|
AND search_rank between 16 and 22
|
||||||
ORDER BY distance ASC limit 1
|
ORDER BY distance ASC limit 1
|
||||||
|
|||||||
Reference in New Issue
Block a user