Merge lp:~gnuoy/ubuntu-geonames/add-support-for-remote-db into lp:ubuntu-geonames

Proposed by Liam Young
Status: Merged
Merged at revision: 26
Proposed branch: lp:~gnuoy/ubuntu-geonames/add-support-for-remote-db
Merge into: lp:ubuntu-geonames
Diff against target: 171 lines (+76/-12)
2 files modified
import-geonames.sh (+27/-12)
sphinx.conf.tmpl (+49/-0)
To merge this branch: bzr merge lp:~gnuoy/ubuntu-geonames/add-support-for-remote-db
Reviewer Review Type Date Requested Status
Dimitri John Ledkov Approve
Review via email: mp+166050@code.launchpad.net

Description of the change

These changes are to enable deploying geonames via juju. The charm is a WIP at the moment but needs the sphinx template so the credentials of the remote db can be substituted in. Since the db is on another server I've also added options to import-geonames.sh to specify host, port etc of the remote db

To post a comment you must log in.
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'import-geonames.sh'
2--- import-geonames.sh 2012-08-23 04:23:45 +0000
3+++ import-geonames.sh 2013-05-28 13:39:30 +0000
4@@ -1,11 +1,25 @@
5 #!/bin/bash
6-
7+# If DB is local pass no arguments else
8+# ./import-geonames.sh -u user -h host -p port -d dbname
9+while getopts u:h:p:d: flag; do
10+ case $flag in
11+ u) PGUSER=$OPTARG;
12+ PGUSER_PARAM="--username $OPTARG";;
13+ h) PGHOST="--host $OPTARG";;
14+ p) PGPORT="--port $OPTARG";;
15+ d) PGDBNAME="--dbname $OPTARG";;
16+ esac
17+done
18+PGDBNAME=${PGDBNAME:="geonames"}
19+PGUSER=${PGUSER:="geouser"}
20+
21+PSQL_CMD="psql $PGUSER_PARAM $PGPASS $PGHOST $PGPORT $PGDBNAME"
22 WORKPATH="$(mktemp -d)"
23
24 chmod 755 $WORKPATH
25 cd $WORKPATH
26 trap "rm -rf $WORKPATH" EXIT HUP INT QUIT TERM
27-
28+pwd
29 # allCountries.zip contains allCountries.txt
30 # alternateNames.zip contains iso-languagecodes.txt alternateNames.txt
31 ZIPFILES="allCountries.zip alternateNames.zip"
32@@ -24,14 +38,14 @@
33 grep -v '^#' countryInfo.txt > countryInfo.txt.tmp
34 tail -n +2 timeZones.txt > timeZones.txt.tmp
35
36-psql geonames <<EOT
37+$PSQL_CMD <<EOT
38 BEGIN;
39 DROP TABLE IF EXISTS geoname;
40 CREATE TABLE geoname (
41 geonameid int,
42 name varchar(200),
43 asciiname varchar(200),
44- alternatenames varchar(10000),
45+ alternatenames varchar(12000),
46 latitude float,
47 longitude float,
48 fclass char(1),
49@@ -48,20 +62,20 @@
50 timezone varchar(40),
51 moddate date
52 );
53-copy geoname (geonameid,name,asciiname,alternatenames,latitude,longitude,fclass,fcode,country,cc2, admin1,admin2,admin3,admin4,population,elevation,gtopo30,timezone,moddate) from '$WORKPATH/allCountries.txt' null as '';
54+\copy geoname (geonameid,name,asciiname,alternatenames,latitude,longitude,fclass,fcode,country,cc2, admin1,admin2,admin3,admin4,population,elevation,gtopo30,timezone,moddate) from $WORKPATH/allCountries.txt null as ''
55
56 DROP TABLE IF EXISTS alternatename;
57 CREATE TABLE alternatename (
58 alternatenameId int,
59 geonameid int,
60 isoLanguage varchar(7),
61- alternateName varchar(200),
62+ alternateName varchar(400),
63 isPreferredName boolean,
64 isShortName boolean,
65 isColloquial boolean,
66 isHistoric boolean
67 );
68-copy alternatename (alternatenameid,geonameid,isoLanguage,alternateName,isPreferredName,isShortName,isColloquial,isHistoric) from '$WORKPATH/alternateNames.txt' null as '';
69+\copy alternatename (alternatenameid,geonameid,isoLanguage,alternateName,isPreferredName,isShortName,isColloquial,isHistoric) from $WORKPATH/alternateNames.txt null as '';
70
71 DROP TABLE IF EXISTS countryinfo;
72 CREATE TABLE countryinfo (
73@@ -85,7 +99,7 @@
74 neighbours char(50),
75 equivalentFipsCode char(10)
76 );
77-copy countryInfo (iso_alpha2,iso_alpha3,iso_numeric,fips_code,name,capital,areaInSqKm,population,continent,tld,currency,currencyName,Phone,postalCodeFormat,postalCodeRegex,languages,geonameId,neighbours,equivalentFipsCode) from '$WORKPATH/countryInfo.txt.tmp' null as '';
78+\copy countryInfo (iso_alpha2,iso_alpha3,iso_numeric,fips_code,name,capital,areaInSqKm,population,continent,tld,currency,currencyName,Phone,postalCodeFormat,postalCodeRegex,languages,geonameId,neighbours,equivalentFipsCode) from $WORKPATH/countryInfo.txt.tmp null as ''
79
80 DROP TABLE IF EXISTS iso_languagecodes;
81 CREATE TABLE iso_languagecodes(
82@@ -94,7 +108,7 @@
83 iso_639_1 VARCHAR(50),
84 language_name VARCHAR(200)
85 );
86-copy iso_languagecodes (iso_639_3, iso_639_2, iso_639_1, language_name) from '$WORKPATH/iso-languagecodes.txt.tmp' null as '';
87+\copy iso_languagecodes (iso_639_3, iso_639_2, iso_639_1, language_name) from $WORKPATH/iso-languagecodes.txt.tmp null as ''
88
89 DROP TABLE IF EXISTS admin1codes;
90 CREATE TABLE admin1codes (
91@@ -103,7 +117,7 @@
92 nameAscii TEXT,
93 geonameid int
94 );
95-copy admin1codes (code,name,nameAscii,geonameid) from '$WORKPATH/admin1CodesASCII.txt' null as '';
96+\copy admin1codes (code,name,nameAscii,geonameid) from $WORKPATH/admin1CodesASCII.txt null as ''
97
98 DROP TABLE IF EXISTS timeZones;
99 CREATE TABLE timeZones (
100@@ -113,7 +127,7 @@
101 DST_offset numeric(3,1),
102 RAW_offset numeric(3,1)
103 );
104-copy timeZones (code,timeZoneId,GMT_offset,DST_offset,RAW_offset) from '$WORKPATH/timeZones.txt.tmp' null as '';
105+\copy timeZones (code,timeZoneId,GMT_offset,DST_offset,RAW_offset) from $WORKPATH/timeZones.txt.tmp null as ''
106
107 DROP TABLE IF EXISTS continentCodes;
108 CREATE TABLE continentCodes (
109@@ -133,6 +147,7 @@
110 CREATE INDEX geoname_admin1codes_code_idx ON admin1codes(code);
111 CREATE INDEX geoname_countryinfo_isoalpha2_idx ON countryinfo(iso_alpha2);
112 CREATE INDEX geoname_alternatename_idx ON alternatename(alternatenameId);
113-GRANT ALL PRIVILEGES ON geoname, admin1codes, countryInfo, alternatename TO geouser;
114+GRANT ALL PRIVILEGES ON geoname, admin1codes, countryInfo, alternatename TO $PGUSER;
115+GRANT SELECT ON geoname, admin1codes, countryInfo, alternatename TO public;
116 COMMIT;
117 EOT
118
119=== added file 'sphinx.conf.tmpl'
120--- sphinx.conf.tmpl 1970-01-01 00:00:00 +0000
121+++ sphinx.conf.tmpl 2013-05-28 13:39:30 +0000
122@@ -0,0 +1,49 @@
123+source geonamessrc
124+{{
125+type = pgsql
126+sql_host = {host}
127+sql_user = {user}
128+sql_pass = {password}
129+sql_db = {database}
130+sql_query = SELECT geoname.geonameid*10+1 AS id, geoname.name AS name, geoname.population AS population, geoname.geonameid AS geonameid FROM geoname WHERE geoname.fclass='P'
131+sql_attr_uint = population
132+}}
133+
134+source altnamessrc
135+{{
136+type = pgsql
137+sql_host = {host}
138+sql_user = {user}
139+sql_pass = {password}
140+sql_db = {database}
141+sql_query = SELECT alternatename.alternatenameId*10+2 AS id, alternatename.alternateName AS name, geoname.population AS population, geoname.geonameid AS geonameid FROM alternatename JOIN geoname on (geoname.geonameid = alternatename.geonameid AND geoname.name != alternatename.alternateName) WHERE (geoname.fclass='P' AND (LENGTH(alternatename.isoLanguage) < 4 OR alternatename.isoLanguage is null))
142+sql_attr_uint = population
143+}}
144+
145+index geonames
146+{{
147+ source = geonamessrc
148+ source = altnamessrc
149+ path = /var/lib/sphinxsearch/data/geonames
150+ docinfo = extern
151+ morphology = none
152+ stopwords =
153+ min_word_len = 2
154+ min_prefix_len = 0
155+ min_infix_len = 0
156+ charset_type = utf-8
157+ charset_table = U+FF10..U+FF19->0..9, 0..9, U+FF41..U+FF5A->a..z, U+FF21..U+FF3A->a..z,A..Z->a..z, a..z, U+0149, U+017F, U+0138, U+00DF, U+00FF, U+00C0..U+00D6->U+00E0..U+00F6,U+00E0..U+00F6, U+00D8..U+00DE->U+00F8..U+00FE, U+00F8..U+00FE, U+0100->U+0101, U+0101, U+0102->U+0103, U+0103, U+0104->U+0105, U+0105, U+0106->U+0107, U+0107, U+0108->U+0109, U+0109, U+010A->U+010B, U+010B, U+010C->U+010D, U+010D, U+010E->U+010F, U+010F, U+0110->U+0111, U+0111, U+0112->U+0113, U+0113, U+0114->U+0115, U+0115, U+0116->U+0117, U+0117, U+0118->U+0119, U+0119, U+011A->U+011B, U+011B, U+011C->U+011D, U+011D, U+011E->U+011F, U+011F, U+0130->U+0131, U+0131, U+0132->U+0133, U+0133, U+0134->U+0135, U+0135, U+0136->U+0137, U+0137, U+0139->U+013A, U+013A, U+013B->U+013C, U+013C, U+013D->U+013E, U+013E, U+013F->U+0140, U+0140, U+0141->U+0142, U+0142, U+0143->U+0144, U+0144, U+0145->U+0146, U+0146, U+0147->U+0148, U+0148, U+014A->U+014B, U+014B, U+014C->U+014D, U+014D, U+014E->U+014F, U+014F, U+0150->U+0151, U+0151, U+0152->U+0153, U+0153, U+0154->U+0155, U+0155, U+0156->U+0157, U+0157, U+0158->U+0159, U+0159, U+015A->U+015B, U+015B, U+015C->U+015D, U+015D, U+015E->U+015F, U+015F, U+0160->U+0161, U+0161, U+0162->U+0163, U+0163, U+0164->U+0165, U+0165, U+0166->U+0167, U+0167, U+0168->U+0169, U+0169, U+016A->U+016B, U+016B, U+016C->U+016D, U+016D, U+016E->U+016F, U+016F, U+0170->U+0171, U+0171, U+0172->U+0173, U+0173, U+0174->U+0175, U+0175, U+0176->U+0177, U+0177, U+0178->U+00FF, U+00FF, U+0179->U+017A, U+017A, U+017B->U+017C, U+017C, U+017D->U+017E, U+017E, U+4E00..U+9FFF, U+3000..U+30FF
158+}}
159+searchd
160+{{
161+port = 3312
162+log = /var/log/sphinxsearch/searchd.log
163+query_log = /var/log/sphinxsearch/query.log
164+read_timeout = 5
165+max_children = 30
166+pid_file = {sphinx_pid_file_location}
167+max_matches = 1000
168+seamless_rotate = 1
169+preopen_indexes = 0
170+unlink_old = 1
171+}}

Subscribers

People subscribed via source and target branches

to all changes: