From 52b98df2f362f0a231cd54bf1c43f4b5aa4b6ff1 Mon Sep 17 00:00:00 2001 From: Chris Jaekl Date: Sat, 11 Nov 2017 17:43:10 +0900 Subject: [PATCH] Make searches more inclusive. Remove case sensitivity, and permit spaces (which will be ignored) in the author name field. --- main/db.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/main/db.go b/main/db.go index 21c6818..53c0a2c 100644 --- a/main/db.go +++ b/main/db.go @@ -4,6 +4,7 @@ import ( "database/sql" "fmt" _ "github.com/lib/pq" + "strings" "strconv" "sync" ) @@ -183,8 +184,6 @@ func queryBookPathById(id int) (string) { } func queryIds(criteria []SearchTerm) []int { - fmt.Println("queryIds():", criteria) - query := "SELECT b.id FROM Books b" + " INNER JOIN Authors a ON a.id=b.author" + " LEFT OUTER JOIN Series s ON s.id=b.series" @@ -197,18 +196,22 @@ func queryIds(criteria []SearchTerm) []int { } else { query += " AND " } + + text := criterion.Text + switch criterion.Attribute { case Author: - query += " a.grouping LIKE $" + strconv.Itoa(i + 1) + query += " UPPER(a.grouping) LIKE UPPER($" + strconv.Itoa(i + 1) + ")" + text = strings.Replace(text, " ", "", -1) // Remove spaces case Series: - query += " s.descr LIKE $" + strconv.Itoa(i + 1) + query += " UPPER(s.descr) LIKE UPPER($" + strconv.Itoa(i + 1) + ")" case Title: - query += " b.title LIKE $" + strconv.Itoa(i + 1) + query += " UPPER(b.title) LIKE UPPER($" + strconv.Itoa(i + 1) + ")" default: report("Error: unrecognized search field in queryIds(): " + criterion.Attribute.String(), nil) return nil } - args[i] = criterion.Text + args[i] = text } query += " ORDER BY b.path" -- 2.39.2