diff --git a/common/torrent.go b/common/torrent.go index 48b240b8..fdbe6e85 100644 --- a/common/torrent.go +++ b/common/torrent.go @@ -231,21 +231,24 @@ func (p *TorrentParam) Find(client *elastic.Client) (int64, []model.Torrent, err log.Infof("Query '%s' took %d milliseconds.", p.NameLike, result.TookInMillis) log.Infof("Amount of results %d.", result.TotalHits()) - torrents := make([]model.Torrent, len(result.Hits.Hits)) + var torrents []model.Torrent + var torrentCount int64 + torrentCount = 0 + //torrents := make([]model.Torrent, len(result.Hits.Hits)) if len(result.Hits.Hits) <= 0 { return 0, nil, nil } - for i, hit := range result.Hits.Hits { - // Deserialize hit.Source into a Tweet (could also be just a map[string]interface{}). + for _, hit := range result.Hits.Hits { var tJson model.TorrentJSON err := json.Unmarshal(*hit.Source, &tJson) - if err != nil { - log.Errorf("Cannot unmarshal elasticsearch torrent: %s", err) + if err == nil { + torrents = append(torrents, tJson.ToTorrent()) + torrentCount += 1 + } else { + log.Infof("Cannot unmarshal elasticsearch torrent: %s", err) } - torrent := tJson.ToTorrent() - torrents[i] = torrent } - return result.TotalHits(), torrents, nil + return torrentCount, torrents, nil } diff --git a/model/torrent.go b/model/torrent.go index 7e52af6c..75e26830 100644 --- a/model/torrent.go +++ b/model/torrent.go @@ -255,7 +255,7 @@ func (t *TorrentJSON) ToTorrent() Torrent { } // Need to add +00:00 at the end because ES doesn't store it by default dateFixed := t.Date - if t.Date[len(t.Date)-6] != '+' { + if len(dateFixed) > 6 && dateFixed[len(dateFixed)-6] != '+' { dateFixed += "Z" } date, err := time.Parse(time.RFC3339, dateFixed)