diff --git a/src/config/main.go b/src/config/main.go index 812fa64..655a0da 100644 --- a/src/config/main.go +++ b/src/config/main.go @@ -40,39 +40,57 @@ func (config *Config) GetConfig() error { config.Cron = qrzsection.Key("cron").MustString("@every 1h") config.DbSchema = fmt.Sprintf(` - CREATE TABLE IF NOT EXISTS %s - ( - id int(8) NOT NULL AUTO_INCREMENT, - qrz varchar(25) NOT NULL, - name varchar(25) DEFAULT NULL, - address varchar(50) DEFAULT NULL, - city varchar(50) DEFAULT NULL, - zipcode varchar(5) DEFAULT NULL, - dept varchar(50) DEFAULT NULL, - country varchar(25) DEFAULT NULL, - dmrid varchar(25) DEFAULT NULL, - PRIMARY KEY (id), - UNIQUE KEY qrz (qrz,name,city,dept) USING BTREE, - KEY test (country), - FULLTEXT KEY city (city), - FULLTEXT KEY dept (dept) - ) - ENGINE=InnoDB DEFAULT CHARSET=utf8;`, + CREATE TABLE IF NOT EXISTS %[1]s ( + id serial NOT NULL PRIMARY KEY, + qrz varchar(25) NOT NULL, + name varchar(25) DEFAULT NULL, + address varchar(50) DEFAULT NULL, + city varchar(50) DEFAULT NULL, + zipcode varchar(5) DEFAULT NULL, + dept varchar(50) DEFAULT NULL, + country varchar(25) DEFAULT NULL, + dmrid varchar(25) DEFAULT NULL, + fts tsvector NULL, + CONSTRAINT qrz_unique UNIQUE(qrz, name, city, dept, country) + ); + + CREATE INDEX IF NOT EXISTS fts_idx ON %[1]s (fts); + + CREATE OR REPLACE FUNCTION updateFTS() RETURNS trigger AS $fts_trigger$ + BEGIN + IF pg_trigger_depth() <> 1 THEN + RETURN NEW; + END IF; + UPDATE %[1]s SET fts = to_tsvector(concat_ws(' ', qrz, name, city, dept, country)) WHERE id = NEW.id; + RETURN NEW; + END; + $fts_trigger$ LANGUAGE plpgsql; + + DROP TRIGGER IF EXISTS fts_trigger ON %[1]s; + + CREATE TRIGGER fts_trigger + AFTER INSERT ON %[1]s + FOR EACH ROW EXECUTE PROCEDURE updateFTS(); + `, config.DbTable) - config.DbStatements.Insert = fmt.Sprintf( - `INSERT IGNORE INTO %s (qrz, dmrid, name, city, dept, country) - VALUES (?,?,?,?,?,?);`, - config.DbTable) - config.DbStatements.ExportCSV = fmt.Sprintf( - `SELECT qrz, name, city, dept, country - FROM %s;`, + config.DbStatements.Insert = fmt.Sprintf(` + INSERT INTO %[1]s (qrz, dmrid, name, city, dept, country) + VALUES ($1, $2, $3, $4, $5, $6); + `, config.DbTable) - config.DbStatements.Countries = fmt.Sprintf( - `SELECT country - FROM %s - GROUP BY country;`, + config.DbStatements.ExportCSV = fmt.Sprintf(` + SELECT qrz, name, city, dept, country + FROM %[1]s; + `, + config.DbTable) + + config.DbStatements.Countries = fmt.Sprintf(` + SELECT country + FROM %[1]s + GROUP BY country; + `, config.DbTable) config.URLBase = `http://groupe-frs.hamstation.eu/index_qrz_liste_%s.php` diff --git a/src/qrz/main.go b/src/qrz/main.go index 3aa9810..d598ac0 100644 --- a/src/qrz/main.go +++ b/src/qrz/main.go @@ -168,4 +168,5 @@ type FrsEntry struct { ZipCode sql.NullString `db:"zipcode"` Dept sql.NullString `db:"dept"` Country sql.NullString `db:"country"` + Fts sql.NullString `db:"fts"` } diff --git a/src/qrzws/main.go b/src/qrzws/main.go index 5328625..1068de7 100644 --- a/src/qrzws/main.go +++ b/src/qrzws/main.go @@ -109,7 +109,7 @@ func BuildQuery(config config.Config, qrzdt QrzDatatableInput) (rows *sqlx.Rows, if err != nil { return nil, err } - searchstatement, err = SetSearchStatement(config, qrzdt) + searchstatement, err = SetSearchLikeStatement(config, qrzdt) if err != nil { return nil, err } @@ -120,16 +120,36 @@ func BuildQuery(config config.Config, qrzdt QrzDatatableInput) (rows *sqlx.Rows, } // BuildQueryCountFiltered builds query for counting filtered +<<<<<<< Updated upstream func BuildQueryCountFiltered(config config.Config, qrzdt QrzDatatableInput) (cnt int, err error) { searchstatement, err := SetSearchStatement(config, qrzdt) err = config.Db.Get(&cnt, fmt.Sprintf("SELECT COUNT(*) FROM %s WHERE %s;", config.DbTable, searchstatement)) +======= +func BuildQueryCountFiltered(config config.Config, qrzdt DatatableInput) (cnt int, err error) { + searchstatement, err := SetSearchLikeStatement(config, qrzdt) + + query := ` + SELECT COUNT(*) + FROM %s + WHERE %s;` + + err = config.Db.Get(&cnt, fmt.Sprintf(query, config.DbTable, searchstatement)) +>>>>>>> Stashed changes return } // BuildQueryCountTotal builds query for counting totals +<<<<<<< Updated upstream func BuildQueryCountTotal(config config.Config, qrzdt QrzDatatableInput) (cnt int, err error) { err = config.Db.Get(&cnt, fmt.Sprintf("SELECT COUNT(*) FROM %s;", config.DbTable)) +======= +func BuildQueryCountTotal(config config.Config, qrzdt DatatableInput) (cnt int, err error) { + query := ` + SELECT COUNT(*) FROM %s; + ` + err = config.Db.Get(&cnt, fmt.Sprintf(query, config.DbTable)) +>>>>>>> Stashed changes return } @@ -190,8 +210,13 @@ func SetLimitStatement(config config.Config, qrzdt QrzDatatableInput) (limitstmt return } +<<<<<<< Updated upstream // SetSearchStatement build the where clause in sql statement func SetSearchStatement(config config.Config, qrzdt QrzDatatableInput) (searchstmt string, err error) { +======= +// SetSearchLikeStatement build the where clause in sql statement +func SetSearchLikeStatement(config config.Config, qrzdt DatatableInput) (searchstmt string, err error) { +>>>>>>> Stashed changes var searchstmtslice []string if len(qrzdt.Columns) > 0 { for id, i := range qrzdt.Columns { @@ -208,6 +233,16 @@ func SetSearchStatement(config config.Config, qrzdt QrzDatatableInput) (searchst return } +// SetSearchFTSStatement build the where clause in sql statement +func SetSearchFTSStatement(config config.Config, qrzdt DatatableInput) (searchstmt string, err error) { + if len(qrzdt.Columns) > 0 { + searchstmt = fmt.Sprintf("fts @@ plainto_tsquery('%s')", qrzdt.Search.Value) + } else { + searchstmt = "1=1" + } + return +} + // RunCSVExport runs the main loop func RunCSVExport(c echo.Context, config config.Config) (data []byte, mime string, err error) { mime = "text/csv" diff --git a/static/css/main.css b/static/css/main.css index 72a9d2f..8aed961 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -2,3 +2,18 @@ body { font-family: "Helvetica Neue", "HelveticaNeue", "Helvetica", "Arial", "sans-serif"; } +<<<<<<< Updated upstream +======= + +#main_table_length +{ + float: left; +} + +#main_table_filter +{ + float: right; +} + +#main_table_paginate +>>>>>>> Stashed changes diff --git a/templates/index.html b/templates/index.html index 5b508df..4ff01a6 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,14 +3,22 @@
+<<<<<<< Updated upstream +======= + + +>>>>>>> Stashed changes +<<<<<<< Updated upstream +======= +>>>>>>> Stashed changes @@ -21,7 +29,11 @@Mirror of http://groupe-frs.hamstation.eu list of users
QRZ |