forked from hans/Nominatim
remove unused columns from word and search_name_* tables
Removes 'trigram' and 'location' from word. Removes 'address', 'importance' and 'country_code' from search_name_*. Use full geometry in centroid column of search_name_*. Requires migration of existing tables. For more info see pull request https://github.com/twain47/Nominatim/pull/45
This commit is contained in:
@@ -95,7 +95,7 @@ BEGIN
|
|||||||
SELECT min(word_id), max(search_name_count) FROM word WHERE word_token = lookup_token and class is null and type is null into return_word_id, count;
|
SELECT min(word_id), max(search_name_count) FROM word WHERE word_token = lookup_token and class is null and type is null into return_word_id, count;
|
||||||
IF return_word_id IS NULL THEN
|
IF return_word_id IS NULL THEN
|
||||||
return_word_id := nextval('seq_word');
|
return_word_id := nextval('seq_word');
|
||||||
INSERT INTO word VALUES (return_word_id, lookup_token, regexp_replace(lookup_token,E'([^0-9])\\1+',E'\\1','g'), null, null, null, null, 0, null);
|
INSERT INTO word VALUES (return_word_id, lookup_token, null, null, null, null, 0);
|
||||||
ELSE
|
ELSE
|
||||||
IF count > get_maxwordfreq() THEN
|
IF count > get_maxwordfreq() THEN
|
||||||
return_word_id := NULL;
|
return_word_id := NULL;
|
||||||
@@ -117,7 +117,7 @@ BEGIN
|
|||||||
SELECT min(word_id) FROM word WHERE word_token = lookup_token and class='place' and type='house' into return_word_id;
|
SELECT min(word_id) FROM word WHERE word_token = lookup_token and class='place' and type='house' into return_word_id;
|
||||||
IF return_word_id IS NULL THEN
|
IF return_word_id IS NULL THEN
|
||||||
return_word_id := nextval('seq_word');
|
return_word_id := nextval('seq_word');
|
||||||
INSERT INTO word VALUES (return_word_id, lookup_token, null, null, 'place', 'house', null, 0, null);
|
INSERT INTO word VALUES (return_word_id, lookup_token, null, 'place', 'house', null, 0);
|
||||||
END IF;
|
END IF;
|
||||||
RETURN return_word_id;
|
RETURN return_word_id;
|
||||||
END;
|
END;
|
||||||
@@ -135,7 +135,7 @@ BEGIN
|
|||||||
SELECT min(word_id) FROM word WHERE word_token = lookup_token and country_code=lookup_country_code into return_word_id;
|
SELECT min(word_id) FROM word WHERE word_token = lookup_token and country_code=lookup_country_code into return_word_id;
|
||||||
IF return_word_id IS NULL THEN
|
IF return_word_id IS NULL THEN
|
||||||
return_word_id := nextval('seq_word');
|
return_word_id := nextval('seq_word');
|
||||||
INSERT INTO word VALUES (return_word_id, lookup_token, null, null, null, null, lookup_country_code, 0, null);
|
INSERT INTO word VALUES (return_word_id, lookup_token, null, null, null, lookup_country_code, 0);
|
||||||
END IF;
|
END IF;
|
||||||
RETURN return_word_id;
|
RETURN return_word_id;
|
||||||
END;
|
END;
|
||||||
@@ -153,7 +153,7 @@ BEGIN
|
|||||||
SELECT min(word_id) FROM word WHERE word_token = lookup_token and class=lookup_class and type = lookup_type into return_word_id;
|
SELECT min(word_id) FROM word WHERE word_token = lookup_token and class=lookup_class and type = lookup_type into return_word_id;
|
||||||
IF return_word_id IS NULL THEN
|
IF return_word_id IS NULL THEN
|
||||||
return_word_id := nextval('seq_word');
|
return_word_id := nextval('seq_word');
|
||||||
INSERT INTO word VALUES (return_word_id, lookup_token, null, null, lookup_class, lookup_type, null, 0, null);
|
INSERT INTO word VALUES (return_word_id, lookup_token, null, lookup_class, lookup_type, null, 0);
|
||||||
END IF;
|
END IF;
|
||||||
RETURN return_word_id;
|
RETURN return_word_id;
|
||||||
END;
|
END;
|
||||||
@@ -171,7 +171,7 @@ BEGIN
|
|||||||
SELECT min(word_id) FROM word WHERE word_token = lookup_token into return_word_id;
|
SELECT min(word_id) FROM word WHERE word_token = lookup_token into return_word_id;
|
||||||
IF return_word_id IS NULL THEN
|
IF return_word_id IS NULL THEN
|
||||||
return_word_id := nextval('seq_word');
|
return_word_id := nextval('seq_word');
|
||||||
INSERT INTO word VALUES (return_word_id, lookup_token, null, null, null, null, null, 0, null);
|
INSERT INTO word VALUES (return_word_id, lookup_token, null, null, null, null, 0);
|
||||||
END IF;
|
END IF;
|
||||||
RETURN return_word_id;
|
RETURN return_word_id;
|
||||||
END;
|
END;
|
||||||
@@ -203,7 +203,7 @@ BEGIN
|
|||||||
SELECT min(word_id) FROM word WHERE word_token = lookup_token and class=lookup_class and type = lookup_type and operator = op into return_word_id;
|
SELECT min(word_id) FROM word WHERE word_token = lookup_token and class=lookup_class and type = lookup_type and operator = op into return_word_id;
|
||||||
IF return_word_id IS NULL THEN
|
IF return_word_id IS NULL THEN
|
||||||
return_word_id := nextval('seq_word');
|
return_word_id := nextval('seq_word');
|
||||||
INSERT INTO word VALUES (return_word_id, lookup_token, null, null, lookup_class, lookup_type, null, 0, op, null);
|
INSERT INTO word VALUES (return_word_id, lookup_token, null, lookup_class, lookup_type, null, 0, op);
|
||||||
END IF;
|
END IF;
|
||||||
RETURN return_word_id;
|
RETURN return_word_id;
|
||||||
END;
|
END;
|
||||||
@@ -222,7 +222,7 @@ BEGIN
|
|||||||
SELECT min(word_id) FROM word WHERE word_token = lookup_token and class is null and type is null into return_word_id;
|
SELECT min(word_id) FROM word WHERE word_token = lookup_token and class is null and type is null into return_word_id;
|
||||||
IF return_word_id IS NULL THEN
|
IF return_word_id IS NULL THEN
|
||||||
return_word_id := nextval('seq_word');
|
return_word_id := nextval('seq_word');
|
||||||
INSERT INTO word VALUES (return_word_id, lookup_token, regexp_replace(lookup_token,E'([^0-9])\\1+',E'\\1','g'), src_word, null, null, null, 0, null);
|
INSERT INTO word VALUES (return_word_id, lookup_token, src_word, null, null, null, 0);
|
||||||
-- nospace_lookup_token := replace(replace(lookup_token, '-',''), ' ','');
|
-- nospace_lookup_token := replace(replace(lookup_token, '-',''), ' ','');
|
||||||
-- IF ' '||nospace_lookup_token != lookup_token THEN
|
-- IF ' '||nospace_lookup_token != lookup_token THEN
|
||||||
-- INSERT INTO word VALUES (return_word_id, '-'||nospace_lookup_token, null, src_word, null, null, null, 0, null);
|
-- INSERT INTO word VALUES (return_word_id, '-'||nospace_lookup_token, null, src_word, null, null, null, 0, null);
|
||||||
@@ -1560,7 +1560,7 @@ BEGIN
|
|||||||
result := add_location(NEW.place_id, NEW.calculated_country_code, NEW.partition, name_vector, NEW.rank_search, NEW.rank_address, NEW.geometry);
|
result := add_location(NEW.place_id, NEW.calculated_country_code, NEW.partition, name_vector, NEW.rank_search, NEW.rank_address, NEW.geometry);
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
result := insertSearchName(NEW.partition, NEW.place_id, NEW.calculated_country_code, name_vector, nameaddress_vector, NEW.rank_search, NEW.rank_address, NEW.importance, place_centroid);
|
result := insertSearchName(NEW.partition, NEW.place_id, NEW.calculated_country_code, name_vector, nameaddress_vector, NEW.rank_search, NEW.rank_address, NEW.importance, place_centroid, NEW.geometry);
|
||||||
|
|
||||||
return NEW;
|
return NEW;
|
||||||
END IF;
|
END IF;
|
||||||
@@ -1891,9 +1891,8 @@ BEGIN
|
|||||||
result := insertLocationRoad(NEW.partition, NEW.place_id, NEW.calculated_country_code, NEW.geometry);
|
result := insertLocationRoad(NEW.partition, NEW.place_id, NEW.calculated_country_code, NEW.geometry);
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
result := insertSearchName(NEW.partition, NEW.place_id, NEW.calculated_country_code, name_vector, nameaddress_vector, NEW.rank_search, NEW.rank_address, NEW.importance, place_centroid);
|
result := insertSearchName(NEW.partition, NEW.place_id, NEW.calculated_country_code, name_vector, nameaddress_vector, NEW.rank_search, NEW.rank_address, NEW.importance, place_centroid, NEW.geometry);
|
||||||
|
|
||||||
-- INSERT INTO search_name values (NEW.place_id, NEW.rank_search, NEW.rank_search, 0, NEW.calculated_country_code, name_vector, nameaddress_vector, place_centroid);
|
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
-- If we've not managed to pick up a better one - default centroid
|
-- If we've not managed to pick up a better one - default centroid
|
||||||
@@ -2344,7 +2343,7 @@ END;
|
|||||||
$$
|
$$
|
||||||
LANGUAGE plpgsql;
|
LANGUAGE plpgsql;
|
||||||
|
|
||||||
DROP TYPE addressline CASCADE;
|
DROP TYPE IF EXISTS addressline CASCADE;
|
||||||
create type addressline as (
|
create type addressline as (
|
||||||
place_id BIGINT,
|
place_id BIGINT,
|
||||||
osm_type CHAR(1),
|
osm_type CHAR(1),
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ CREATE INDEX idx_placex_interpolation ON placex USING BTREE (geometry_sector) wh
|
|||||||
CREATE INDEX idx_location_area_country_place_id ON location_area_country USING BTREE (place_id);
|
CREATE INDEX idx_location_area_country_place_id ON location_area_country USING BTREE (place_id);
|
||||||
|
|
||||||
CREATE INDEX idx_search_name_country_centroid ON search_name_country USING GIST (centroid);
|
CREATE INDEX idx_search_name_country_centroid ON search_name_country USING GIST (centroid);
|
||||||
CREATE INDEX idx_search_name_country_nameaddress_vector ON search_name_country USING GIN (nameaddress_vector) WITH (fastupdate = off);
|
|
||||||
|
|
||||||
-- start
|
-- start
|
||||||
CREATE INDEX idx_location_property_-partition-_centroid ON location_property_-partition- USING GIST (centroid);
|
CREATE INDEX idx_location_property_-partition-_centroid ON location_property_-partition- USING GIST (centroid);
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ create or replace function insertSearchName(
|
|||||||
in_partition INTEGER, in_place_id BIGINT, in_country_code VARCHAR(2),
|
in_partition INTEGER, in_place_id BIGINT, in_country_code VARCHAR(2),
|
||||||
in_name_vector INTEGER[], in_nameaddress_vector INTEGER[],
|
in_name_vector INTEGER[], in_nameaddress_vector INTEGER[],
|
||||||
in_rank_search INTEGER, in_rank_address INTEGER, in_importance FLOAT,
|
in_rank_search INTEGER, in_rank_address INTEGER, in_importance FLOAT,
|
||||||
in_centroid GEOMETRY) RETURNS BOOLEAN AS $$
|
in_centroid GEOMETRY, in_geometry GEOMETRY) RETURNS BOOLEAN AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
@@ -176,16 +176,16 @@ BEGIN
|
|||||||
|
|
||||||
IF in_rank_search <= 4 THEN
|
IF in_rank_search <= 4 THEN
|
||||||
DELETE FROM search_name_country WHERE place_id = in_place_id;
|
DELETE FROM search_name_country WHERE place_id = in_place_id;
|
||||||
INSERT INTO search_name_country values (in_place_id, in_rank_search, in_rank_address, in_importance, in_country_code,
|
INSERT INTO search_name_country values (in_place_id, in_rank_search, in_rank_address,
|
||||||
in_name_vector, in_nameaddress_vector, in_centroid);
|
in_name_vector, in_geometry);
|
||||||
RETURN TRUE;
|
RETURN TRUE;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
-- start
|
-- start
|
||||||
IF in_partition = -partition- THEN
|
IF in_partition = -partition- THEN
|
||||||
DELETE FROM search_name_-partition- values WHERE place_id = in_place_id;
|
DELETE FROM search_name_-partition- values WHERE place_id = in_place_id;
|
||||||
INSERT INTO search_name_-partition- values (in_place_id, in_rank_search, in_rank_address, 0, in_country_code,
|
INSERT INTO search_name_-partition- values (in_place_id, in_rank_search, in_rank_address,
|
||||||
in_name_vector, in_nameaddress_vector, in_centroid);
|
in_name_vector, in_geometry);
|
||||||
RETURN TRUE;
|
RETURN TRUE;
|
||||||
END IF;
|
END IF;
|
||||||
-- end
|
-- end
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
drop type nearplace cascade;
|
drop type if exists nearplace cascade;
|
||||||
create type nearplace as (
|
create type nearplace as (
|
||||||
place_id BIGINT
|
place_id BIGINT
|
||||||
);
|
);
|
||||||
|
|
||||||
drop type nearfeature cascade;
|
drop type if exists nearfeature cascade;
|
||||||
create type nearfeature as (
|
create type nearfeature as (
|
||||||
place_id BIGINT,
|
place_id BIGINT,
|
||||||
keywords int[],
|
keywords int[],
|
||||||
@@ -13,7 +13,7 @@ create type nearfeature as (
|
|||||||
isguess boolean
|
isguess boolean
|
||||||
);
|
);
|
||||||
|
|
||||||
drop type nearfeaturecentr cascade;
|
drop type if exists nearfeaturecentr cascade;
|
||||||
create type nearfeaturecentr as (
|
create type nearfeaturecentr as (
|
||||||
place_id BIGINT,
|
place_id BIGINT,
|
||||||
keywords int[],
|
keywords int[],
|
||||||
@@ -24,6 +24,16 @@ create type nearfeaturecentr as (
|
|||||||
centroid GEOMETRY
|
centroid GEOMETRY
|
||||||
);
|
);
|
||||||
|
|
||||||
|
drop table IF EXISTS search_name_blank CASCADE;
|
||||||
|
CREATE TABLE search_name_blank (
|
||||||
|
place_id BIGINT,
|
||||||
|
search_rank integer,
|
||||||
|
address_rank integer,
|
||||||
|
name_vector integer[]
|
||||||
|
);
|
||||||
|
SELECT AddGeometryColumn('search_name_blank', 'centroid', 4326, 'GEOMETRY', 2);
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE location_area_country () INHERITS (location_area_large);
|
CREATE TABLE location_area_country () INHERITS (location_area_large);
|
||||||
CREATE INDEX idx_location_area_country_geometry ON location_area_country USING GIST (geometry);
|
CREATE INDEX idx_location_area_country_geometry ON location_area_country USING GIST (geometry);
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ drop table IF EXISTS word;
|
|||||||
CREATE TABLE word (
|
CREATE TABLE word (
|
||||||
word_id INTEGER,
|
word_id INTEGER,
|
||||||
word_token text,
|
word_token text,
|
||||||
word_trigram text,
|
|
||||||
word text,
|
word text,
|
||||||
class text,
|
class text,
|
||||||
type text,
|
type text,
|
||||||
@@ -78,9 +77,7 @@ CREATE TABLE word (
|
|||||||
search_name_count INTEGER,
|
search_name_count INTEGER,
|
||||||
operator TEXT
|
operator TEXT
|
||||||
);
|
);
|
||||||
SELECT AddGeometryColumn('word', 'location', 4326, 'GEOMETRY', 2);
|
|
||||||
CREATE INDEX idx_word_word_token on word USING BTREE (word_token);
|
CREATE INDEX idx_word_word_token on word USING BTREE (word_token);
|
||||||
--CREATE INDEX idx_word_trigram ON word USING gin(word_trigram gin_trgm_ops) WITH (fastupdate = off);
|
|
||||||
GRANT SELECT ON word TO "www-data" ;
|
GRANT SELECT ON word TO "www-data" ;
|
||||||
DROP SEQUENCE seq_word;
|
DROP SEQUENCE seq_word;
|
||||||
CREATE SEQUENCE seq_word start 1;
|
CREATE SEQUENCE seq_word start 1;
|
||||||
@@ -124,8 +121,8 @@ CREATE INDEX idx_location_property_tiger_parent_place_id ON location_property_ti
|
|||||||
CREATE INDEX idx_location_property_tiger_housenumber_parent_place_id ON location_property_tiger USING BTREE (parent_place_id, housenumber);
|
CREATE INDEX idx_location_property_tiger_housenumber_parent_place_id ON location_property_tiger USING BTREE (parent_place_id, housenumber);
|
||||||
GRANT SELECT ON location_property_tiger TO "www-data";
|
GRANT SELECT ON location_property_tiger TO "www-data";
|
||||||
|
|
||||||
drop table IF EXISTS search_name_blank CASCADE;
|
drop table IF EXISTS search_name;
|
||||||
CREATE TABLE search_name_blank (
|
CREATE TABLE search_name (
|
||||||
place_id BIGINT,
|
place_id BIGINT,
|
||||||
search_rank integer,
|
search_rank integer,
|
||||||
address_rank integer,
|
address_rank integer,
|
||||||
@@ -134,10 +131,7 @@ CREATE TABLE search_name_blank (
|
|||||||
name_vector integer[],
|
name_vector integer[],
|
||||||
nameaddress_vector integer[]
|
nameaddress_vector integer[]
|
||||||
);
|
);
|
||||||
SELECT AddGeometryColumn('search_name_blank', 'centroid', 4326, 'GEOMETRY', 2);
|
SELECT AddGeometryColumn('search_name', 'centroid', 4326, 'GEOMETRY', 2);
|
||||||
|
|
||||||
drop table IF EXISTS search_name;
|
|
||||||
CREATE TABLE search_name () INHERITS (search_name_blank);
|
|
||||||
CREATE INDEX idx_search_name_place_id ON search_name USING BTREE (place_id);
|
CREATE INDEX idx_search_name_place_id ON search_name USING BTREE (place_id);
|
||||||
|
|
||||||
drop table IF EXISTS place_addressline;
|
drop table IF EXISTS place_addressline;
|
||||||
|
|||||||
@@ -319,7 +319,7 @@
|
|||||||
{
|
{
|
||||||
$sQuery = str_replace($aSpecialTerm[0], ' ', $sQuery);
|
$sQuery = str_replace($aSpecialTerm[0], ' ', $sQuery);
|
||||||
$sToken = $oDB->getOne("select make_standard_name('".$aSpecialTerm[1]."') as string");
|
$sToken = $oDB->getOne("select make_standard_name('".$aSpecialTerm[1]."') as string");
|
||||||
$sSQL = 'select * from (select word_id,word_token, word, class, type, location, country_code, operator';
|
$sSQL = 'select * from (select word_id,word_token, word, class, type, country_code, operator';
|
||||||
$sSQL .= ' from word where word_token in (\' '.$sToken.'\')) as x where (class is not null and class not in (\'place\')) or country_code is not null';
|
$sSQL .= ' from word where word_token in (\' '.$sToken.'\')) as x where (class is not null and class not in (\'place\')) or country_code is not null';
|
||||||
if (CONST_Debug) var_Dump($sSQL);
|
if (CONST_Debug) var_Dump($sSQL);
|
||||||
$aSearchWords = $oDB->getAll($sSQL);
|
$aSearchWords = $oDB->getAll($sSQL);
|
||||||
@@ -396,10 +396,10 @@
|
|||||||
{
|
{
|
||||||
|
|
||||||
// Check which tokens we have, get the ID numbers
|
// Check which tokens we have, get the ID numbers
|
||||||
$sSQL = 'select word_id,word_token, word, class, type, location, country_code, operator, search_name_count';
|
$sSQL = 'select word_id,word_token, word, class, type, country_code, operator, search_name_count';
|
||||||
$sSQL .= ' from word where word_token in ('.join(',',array_map("getDBQuoted",$aTokens)).')';
|
$sSQL .= ' from word where word_token in ('.join(',',array_map("getDBQuoted",$aTokens)).')';
|
||||||
// $sSQL .= ' and search_name_count < '.CONST_Max_Word_Frequency;
|
// $sSQL .= ' and search_name_count < '.CONST_Max_Word_Frequency;
|
||||||
// $sSQL .= ' group by word_token, word, class, type, location, country_code';
|
// $sSQL .= ' group by word_token, word, class, type, country_code';
|
||||||
|
|
||||||
if (CONST_Debug) var_Dump($sSQL);
|
if (CONST_Debug) var_Dump($sSQL);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user