diff --git a/config/config.go b/config/config.go index b5a19cf2..931a8e74 100644 --- a/config/config.go +++ b/config/config.go @@ -102,4 +102,4 @@ func (config *Config) Pretty(output io.Writer) error { data = append(data, []byte("\n")...) _, err = output.Write(data) return err -} \ No newline at end of file +} diff --git a/main.go b/main.go index 756b0a9f..c4e719d4 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "github.com/ewhal/nyaa/db" "github.com/ewhal/nyaa/router" "github.com/ewhal/nyaa/util/log" + "github.com/ewhal/nyaa/util/search" // super hacky fix "github.com/ewhal/nyaa/util/signals" "net/http" @@ -59,6 +60,7 @@ func main() { if len(config.TorrentFileStorage) > 0 { os.MkdirAll(config.TorrentFileStorage, 0755) } + search.Init(conf.DBType) // super hacky fix RunServer(conf) } } diff --git a/util/search/search.go b/util/search/search.go index f79d3f4d..3872adff 100644 --- a/util/search/search.go +++ b/util/search/search.go @@ -19,6 +19,17 @@ type SearchParam struct { Sort string } + +// super hacky fix: +var search_op string +func Init(backend string) { + if backend == "postgres" { + search_op = "ILIKE" + } else { + search_op = "LIKE" + } +} + func SearchByQuery(r *http.Request, pagenum int) (SearchParam, []model.Torrents, int) { maxPerPage, errConv := strconv.Atoi(r.URL.Query().Get("max")) if errConv != nil { @@ -72,7 +83,7 @@ func SearchByQuery(r *http.Request, pagenum int) (SearchParam, []model.Torrents, } searchQuerySplit := strings.Split(search_param.Query, " ") for i, _ := range searchQuerySplit { - conditions = append(conditions, "torrent_name LIKE ?") + conditions = append(conditions, "torrent_name " + search_op + " ?") parameters.Params = append(parameters.Params, "%"+searchQuerySplit[i]+"%") }