aboutsummaryrefslogtreecommitdiff
path: root/modules/search
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2015-12-30 15:10:35 (UTC)
committerjan <jan@ruken.pw>2015-12-30 15:10:35 (UTC)
commitbcab80f3e81b3aea7b1a6e84b39838bd19402975 (patch)
tree5ba8fb024fde49f203863b57724158ed4171ff99 /modules/search
parent836099557e2327813668d50d5abb73ac43ad212d (diff)
nur noch eine datenbankabfrage. results sehen jetzt ziemlich leer aus, muss bestimmt mal neu gestaltet werden.
Diffstat (limited to 'modules/search')
-rw-r--r--modules/search/search.go25
1 files changed, 13 insertions, 12 deletions
diff --git a/modules/search/search.go b/modules/search/search.go
index da6d126..a614c08 100644
--- a/modules/search/search.go
+++ b/modules/search/search.go
@@ -16,6 +16,12 @@ type Module struct {
16 grils *grils.GrilsModule 16 grils *grils.GrilsModule
17} 17}
18 18
19type GrilResult struct {
20 ID int
21 ImagePath string
22 Name string
23}
24
19func New() *Module { 25func New() *Module {
20 return &Module{} 26 return &Module{}
21} 27}
@@ -50,7 +56,7 @@ func (m *Module) instantSearchGril(w http.ResponseWriter, r *http.Request, p htt
50 return 56 return
51 } 57 }
52 58
53 rows, err := m.g.DB.Query(`SELECT id FROM grilist.search_grils($1)`, name) 59 rows, err := m.g.DB.Query(`SELECT id, name FROM grilist.search_grils($1)`, name)
54 if err != nil { 60 if err != nil {
55 log.Println("error in instant gril search:", err) 61 log.Println("error in instant gril search:", err)
56 return 62 return
@@ -58,24 +64,19 @@ func (m *Module) instantSearchGril(w http.ResponseWriter, r *http.Request, p htt
58 64
59 defer rows.Close() 65 defer rows.Close()
60 66
61 var ids []int 67 var results []GrilResult
62 for rows.Next() { 68 for rows.Next() {
63 var id int 69 result := GrilResult{}
64 if err := rows.Scan(&id); err != nil { 70 if err := rows.Scan(&result.ID, &result.Name); err != nil {
65 log.Println("error scanning in instant gril search", err) 71 log.Println("error scanning in instant gril search", err)
66 continue 72 continue
67 } 73 }
68 74
69 ids = append(ids, id) 75 result.ImagePath = grils.ImagePath(result.ID, true)
70 } 76 results = append(results, result)
71
72 grils, err := m.grils.FromIDs(ids)
73 if err != nil {
74 log.Println("error acquiring instant grils:", err)
75 return
76 } 77 }
77 78
78 data := make(map[string]interface{}) 79 data := make(map[string]interface{})
79 data["results"] = grils 80 data["results"] = results
80 m.g.Renderer.RenderPage("instant_search_results", w, data) 81 m.g.Renderer.RenderPage("instant_search_results", w, data)
81} 82}